| // Copyright 2014 Google Inc. All Rights Reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // Author: nevena@google.com (Nevena Lazic) |
| |
| #include "lossmin/losses/loss-function.h" |
| #include <float.h> |
| #include <math.h> |
| |
| namespace lossmin { |
| |
| float LossFunction::BatchLoss( |
| const Weights &weights, const InstanceSet &instances, |
| const LabelSet &labels) const { |
| float loss = 0.0f; |
| for (int i = 0; i < instances.rows(); ++i) { |
| loss += ExampleLoss(weights, instances, labels, i); |
| } |
| return loss; |
| } |
| |
| void LossFunction::BatchGradient( |
| const Weights &weights, const InstanceSet &instances, |
| const LabelSet &labels, Weights *gradient) const { |
| for (int i = 0; i < instances.rows(); ++i) { |
| AddExampleGradient(weights, instances, labels, i, 1.0f, 1.0f, gradient); |
| } |
| } |
| |
| } // namespace lossmin |