25 #ifndef LOGLIKELIHOODLOSS_HPP_
26 #define LOGLIKELIHOODLOSS_HPP_
37 namespace neural_nets {
45 template <
typename dtype=
float>
51 dtype
calculateLoss (mic::types::MatrixPtr<dtype> target_y_, mic::types::MatrixPtr<dtype> predicted_y_) {
53 assert(predicted_y_->size() == target_y_->size());
59 for (
size_t i=0; i <(size_t)predicted_y_->cols(); i++) {
61 target_y_.col(i).maxCoeff(ind);
64 loss -= std::log((*predicted_y_)[ind]);
74 mic::types::MatrixPtr<dtype>
calculateGradient (mic::types::MatrixPtr<dtype> target_y_, mic::types::MatrixPtr<dtype> predicted_y_) {
76 assert(predicted_y_->size() == target_y_->size());
79 mic::types::MatrixPtr<dtype> dy = MAKE_MATRIX_PTR(dtype, predicted_y_->rows(), predicted_y_->cols());
80 for (
size_t i=0; i <(size_t)predicted_y_->size(); i++) {
mic::types::MatrixPtr< dtype > calculateGradient(mic::types::MatrixPtr< dtype > target_y_, mic::types::MatrixPtr< dtype > predicted_y_)
Gradient calculation for log-likelihood cost. NOT FINISHED!!
dtype calculateLoss(mic::types::MatrixPtr< dtype > target_y_, mic::types::MatrixPtr< dtype > predicted_y_)
Calculates log-likelihood cost.
Abstract class representing a loss function. Defines interfaces.
Class representing a log-likelihood cost (to be used with softmax logistic regression).