Skip to content

Commit

Permalink
fix: missing include file
Browse files Browse the repository at this point in the history
  • Loading branch information
Az-r-ow committed May 18, 2024
1 parent 09dd99d commit 32f3a62
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/NeuralNet/callbacks/ModelCheckpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ModelCheckpoint : public Callback {
private:
std::string folderPath, filename;
bool saveBestOnly, verbose;
double bestLoss = 10, bestAccuracy = 0;
double bestLoss = std::numeric_limits<double>::max(), bestAccuracy = 0;
int numEpochs, bestEpoch;
std::unordered_map<std::string, Logs> logs;

Expand Down
6 changes: 4 additions & 2 deletions src/NeuralNet/losses/BCE.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Loss.hpp"
#include "utils/Functions.hpp"

namespace NeuralNet {
/**
Expand All @@ -9,7 +10,7 @@ namespace NeuralNet {
class BCE : public Loss {
public:
static double cmpLoss(const Eigen::MatrixXd &o, const Eigen::MatrixXd &y) {
double threshold = 1.0e-5;
constexpr double threshold = 1.0e-5;
Eigen::MatrixXd oTrim = trim(o, threshold);
Eigen::MatrixXd yTrim = trim(y, threshold);

Expand All @@ -26,8 +27,9 @@ class BCE : public Loss {

static Eigen::MatrixXd cmpLossGrad(const Eigen::MatrixXd &yHat,
const Eigen::MatrixXd &y) {
constexpr double epsilon = 1.0e-9;
return (yHat.array() - y.array()) /
((yHat.array() * (1.0 - yHat.array())) + 1e-9);
((yHat.array() * (1.0 - yHat.array())) + epsilon);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/NeuralNet/utils/Functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ inline std::string constructFilePath(const std::string &folderPath,
*
* @return The square of x
*/
inline double sqr(const double x) { return x * x; };
inline constexpr double sqr(const double x) { return x * x; };

/* VECTOR OPERATIONS */

Expand Down
8 changes: 4 additions & 4 deletions tests/test-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ TEST_CASE("vectorToMatrixXd outputs the correct format", "[helper_function]") {
TEST_CASE("randomWeightInit initializes value properly",
"[weight_initialization]") {
Eigen::MatrixXd weights = Eigen::MatrixXd::Zero(5, 5);
double min = -2.0;
double max = 2.0;
constexpr double min = -2.0;
constexpr double max = 2.0;

randomWeightInit(&weights, min, max);
CHECK_MATRIX_VALUES_IN_RANGE(weights, min, max);
Expand All @@ -39,8 +39,8 @@ TEST_CASE("randomWeightInit initializes value properly",
TEST_CASE("randomDistMatrixInit initializes values properly",
"[weight_initialization]") {
Eigen::MatrixXd weights = Eigen::MatrixXd::Zero(5, 5);
double mean = -1.0;
double stddev = 0;
constexpr double mean = -1.0;
constexpr double stddev = 0;

randomDistMatrixInit(&weights, mean, stddev);

Expand Down

0 comments on commit 32f3a62

Please sign in to comment.