9.0.0.2
15 Loss Functions
Loss functions are curried and have the following type:
(target-fn? . -> . expectant-fn?) 
where a target-fn? expects a tensor first, and then a theta?, and returns a tensor?.
An expectant-fn? expects xs and ys which
are two tensors representing a subset of the dataset, and returns
an objective-fn?.
These are defined as follows
- target-fn? : (-> tensor? (-> theta? tensor?)) 
- expectant-fn? : (-> tensor? tensor? objective-fn?) 
- objective-fn? : (-> theta? tensor?) 
The tensor returned from an objective-fn? must have rank 1, and its tlen should be the same as the number of elements in xs.
The following loss functions are available in malt.
procedure
target : (-> tensor? (-> theta? tensor?)) xs : tensor? ys : tensor θ : theta? 
Implements the SSE loss function. 
(let ((pred-ys ((target xs) theta))) (sum (sqr (- ys pred-ys)))) 
procedure
target : (-> tensor? (-> theta? tensor?)) xs : tensor? ys : tensor θ : theta? 
Implements the cross-entropy loss function. 
(let ((pred-ys ((target xs) theta)) (num-classes (ref (reverse (shape ys)) 0))) (* -1 (/ (dot-product ys (log pred-ys)) num-classes))) 
procedure
target : (-> tensor? (-> theta? tensor?)) xs : tensor? ys : tensor θ : theta? 
Implements the KL-divergence loss function. 
(let ((pred-ys ((target xs) theta))) (sum (* pred-ys (log (/ pred-ys ys)))))