-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Cleaned up versioning and copyright tags. 2. Added homepage for API documentation. 3. Added documentation for Optimizer classes.
- Loading branch information
1 parent
526e048
commit 83254ab
Showing
16 changed files
with
205 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
* @file Core.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Core header to provide common types and functions. | ||
* @version 0.1 | ||
* @date 2024-03-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
* @file Exceptions.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Exceptions header to provide some commonly used custom exceptions. | ||
* @version 0.1 | ||
* @date 2024-10-16 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
|
||
|
@@ -15,8 +13,13 @@ | |
#include <exception> | ||
#include <string> | ||
|
||
#define SVGDCPP_LOG_PREFIX std::string("SVGDCpp: ") | ||
#define SVGDCPP_LOG_PREFIX std::string("SVGDCpp: ") ///< Convenience macro to prefix output logs. | ||
|
||
/** | ||
* @class DimensionMismatchException | ||
* @brief Exception for dimension mismatch type errors. | ||
* @ingroup Core_Module | ||
*/ | ||
class DimensionMismatchException : public std::exception | ||
{ | ||
public: | ||
|
@@ -32,6 +35,11 @@ class DimensionMismatchException : public std::exception | |
std::string message_; | ||
}; | ||
|
||
/** | ||
* @class UnsetException | ||
* @brief Exception for unset value type errors. | ||
* @ingroup Core_Module | ||
*/ | ||
class UnsetException : public std::exception | ||
{ | ||
public: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
* @file GaussianRBFKernel.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Gaussian RBF kernel class header. | ||
* @version 0.1 | ||
* @date 2024-03-23 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
/** | ||
* @file Kernel.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Kernel class header | ||
* @version 0.1 | ||
* @date 2024-03-23 | ||
* @brief Kernel class header. | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
#ifndef SVGDCPP_KERNEL_HPP | ||
|
@@ -350,7 +348,7 @@ class Kernel | |
} | ||
|
||
/** | ||
* @brief Execute methods required for each step. | ||
* @brief Execute methods required at each step. | ||
* @details Override this method to include methods that you need to have run every step of the iteration | ||
* @a e.g., computing the scale parameter of the kernel function. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
* @file Model.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Model class header | ||
* @version 0.1 | ||
* @date 2024-03-22 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
|
||
|
@@ -408,7 +406,7 @@ class Model | |
} | ||
|
||
/** | ||
* @brief Execute methods required for each step. | ||
* @brief Execute methods required at each step. | ||
* @details Override this method to include methods that you need to have run every step of the iteration. | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
* @file MultivariateNormal.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Multivariate normal model class header. | ||
* @version 0.1 | ||
* @date 2024-03-22 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
/** | ||
* @file AdaGrad.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief AdaGrad optimizer class header. | ||
* | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
#ifndef SVGDCPP_ADAGRAD_HPP | ||
#define SVGDCPP_ADAGRAD_HPP | ||
|
||
#include "../Core.hpp" | ||
#include "Optimizer.hpp" | ||
|
||
/** | ||
* @class AdaGrad | ||
* @brief This class provides the AdaGrad optimizer. | ||
* @ingroup Optimizer_Module | ||
*/ | ||
class AdaGrad : public Optimizer | ||
{ | ||
public: | ||
/** | ||
* @brief Default constructor. | ||
* | ||
* @param dimension Dimension of the problem. | ||
* @param num_particles Number of particles used in the problem. | ||
* @param lr Learning rate. | ||
* @param epsilon Numerical stabilizer. | ||
*/ | ||
AdaGrad(const size_t &dimension, | ||
const size_t &num_particles, | ||
const double &lr, | ||
|
@@ -15,13 +36,27 @@ class AdaGrad : public Optimizer | |
dimension_(dimension), | ||
num_particles_(num_particles) {} | ||
|
||
/** | ||
* @brief Default destructor. | ||
* | ||
*/ | ||
virtual ~AdaGrad() {} | ||
|
||
/** | ||
* @brief Initialize the optimizer. | ||
* | ||
*/ | ||
virtual void Initialize() override | ||
{ | ||
sum_of_sq_grad_ = Eigen::MatrixXd::Zero(dimension_, num_particles_).array(); | ||
} | ||
|
||
/** | ||
* @brief Execute the optimization of the gradient at each step. | ||
* | ||
* @param grad_matrix Gradient matrix for each particle coordinate. | ||
* @return Optimized gradient matrix. | ||
*/ | ||
virtual Eigen::MatrixXd Step(const Eigen::MatrixXd &grad_matrix) | ||
{ | ||
sum_of_sq_grad_ += grad_matrix.array().square(); | ||
|
@@ -30,13 +65,13 @@ class AdaGrad : public Optimizer | |
} | ||
|
||
protected: | ||
size_t dimension_; | ||
size_t dimension_; ///< Dimension of the problem. | ||
|
||
size_t num_particles_; | ||
size_t num_particles_; ///< Number of particles used in the problem. | ||
|
||
double decay_rate_; | ||
double decay_rate_; ///< Decay rate (unused). | ||
|
||
Eigen::ArrayXXd sum_of_sq_grad_; | ||
Eigen::ArrayXXd sum_of_sq_grad_; ///< Sum of squares gradient matrix. | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
/** | ||
* @file Adam.hpp | ||
* @author Khai Yi Chin ([email protected]) | ||
* @brief Adam optimizer class header. | ||
* | ||
* @copyright Copyright (c) 2024 Khai Yi Chin | ||
* | ||
*/ | ||
#ifndef SVGDCPP_ADAM_HPP | ||
#define SVGDCPP_ADAM_HPP | ||
|
||
#include "../Core.hpp" | ||
#include "Optimizer.hpp" | ||
|
||
/** | ||
* @class Adam | ||
* @brief This class provides the Adam optimizer. | ||
* @ingroup Optimizer_Module | ||
*/ | ||
class Adam : public Optimizer | ||
{ | ||
public: | ||
/** | ||
* @brief Default constructor. | ||
* | ||
* @param dimension Dimension of the problem. | ||
* @param num_particles Number of particles used in the problem. | ||
* @param lr Learning rate. | ||
* @param beta1 Exponential decay rate for the 1st moment estimates. | ||
* @param beta2 Exponential decay rate for the 2nd moment estimates. | ||
* @param epsilon Numerical stabilizer. | ||
*/ | ||
Adam(const size_t &dimension, | ||
const size_t &num_particles, | ||
const double &lr, | ||
|
@@ -25,8 +48,16 @@ class Adam : public Optimizer | |
} | ||
} | ||
|
||
/** | ||
* @brief Default destructor. | ||
* | ||
*/ | ||
virtual ~Adam() {} | ||
|
||
/** | ||
* @brief Initialize the optimizer. | ||
* | ||
*/ | ||
virtual void Initialize() override | ||
{ | ||
sum_of_sq_grad_ = Eigen::MatrixXd::Zero(dimension_, num_particles_).array(); | ||
|
@@ -35,6 +66,12 @@ class Adam : public Optimizer | |
counter_ = 0; | ||
} | ||
|
||
/** | ||
* @brief Execute the optimization of the gradient at each step. | ||
* | ||
* @param grad_matrix Gradient matrix for each particle coordiniate. | ||
* @return Optimized gradient matrix. | ||
*/ | ||
virtual Eigen::MatrixXd Step(const Eigen::MatrixXd &grad_matrix) | ||
{ | ||
sum_of_grad_ = decay_rate_1_ * sum_of_grad_ + (1 - decay_rate_1_) * grad_matrix.array(); // Momentum part | ||
|
@@ -46,24 +83,31 @@ class Adam : public Optimizer | |
} | ||
|
||
protected: | ||
/** | ||
* @brief Correct moment estimate for bias. | ||
* | ||
* @param arr Biased gradient estimate array. | ||
* @param decay Decay rate. | ||
* @return Bias-corrected moment estimate. | ||
*/ | ||
Eigen::ArrayXXd CorrectForBias(const Eigen::ArrayXXd arr, const double &decay) | ||
{ | ||
return arr / (1.0 - std::pow(decay, counter_)); | ||
} | ||
|
||
size_t counter_ = 0; | ||
size_t counter_ = 0; ///< Time step counter. | ||
|
||
size_t dimension_; | ||
size_t dimension_; ///< Dimension of the problem. | ||
|
||
size_t num_particles_; | ||
size_t num_particles_; ///< Number of particles used in the problem. | ||
|
||
double decay_rate_1_; | ||
double decay_rate_1_; ///< Exponential decay rate for the 1st moment estimate. | ||
|
||
double decay_rate_2_; | ||
double decay_rate_2_; ///< Exponential decay rate for the 2nd moment estimate. | ||
|
||
Eigen::ArrayXXd sum_of_sq_grad_; | ||
Eigen::ArrayXXd sum_of_sq_grad_; ///< 2nd biased moment estimate. | ||
|
||
Eigen::ArrayXXd sum_of_grad_; | ||
Eigen::ArrayXXd sum_of_grad_; ///< 1st biased moment estimate | ||
}; | ||
|
||
#endif |
Oops, something went wrong.