blob: f5bb3bf23a14a74c1b771f0e53a86c3b1ea21dd3 [file] [log] [blame]
// 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 {
double LossFunction::BatchLoss(
const Weights &weights, const InstanceSet &instances,
const LabelSet &labels) const {
double loss = 0.0;
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.0, 1.0, gradient);
}
}
} // namespace lossmin