Skip to content

Commit

Permalink
Merge pull request #19 from cvjena/master
Browse files Browse the repository at this point in the history
Fixed gradient check for non-default localized error functions
  • Loading branch information
Clemens-Alexander Brust committed Feb 27, 2015
2 parents 4bd3cd1 + 46e1509 commit 0074040
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/net/ErrorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void ErrorLayer::FeedForward() {
#ifdef ERROR_LAYER_IGNORE_WEIGHTS
const datum weight = 1.0;
#else
const datum weight =
const datum weight =
*third_->data.data_ptr_const ( x,y,0,sample );
#endif
*first_->delta.data_ptr(x,y,map,sample) = diff * weight;
Expand Down Expand Up @@ -137,9 +137,27 @@ datum ErrorLayer::CalculateLossFunction() {
long double error = 0;

// Add up the squared error
for ( std::size_t i = 0; i < first_->data.elements(); i++ ) {
const datum diff = first_->delta.data_ptr_const() [i];
error += (long double)( diff * diff );
for (unsigned int sample = 0; sample < first_->data.samples(); sample++) {
for (unsigned int map = 0; map < first_->data.maps(); map++) {
for (unsigned int y = 0; y < first_->data.height(); y++) {
for (unsigned int x = 0; x < first_->data.width(); x++) {
const datum first =
*first_->data.data_ptr_const(x, y, map, sample);
const datum second =
*second_->data.data_ptr_const(x, y, map, sample);

const datum diff = first - second;

#ifdef ERROR_LAYER_IGNORE_WEIGHTS
const datum weight = 1.0;
#else
const datum weight =
*third_->data.data_ptr_const ( x,y,0,sample );
#endif
error += ((long double)diff) * ((long double)diff) * ((long double)weight);
}
}
}
}

return error / 2.0;
Expand Down

0 comments on commit 0074040

Please sign in to comment.