Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
|
Ordinary Least Squares trainer using Gradient Descent optimization. More...
#include <OlsGDTrainer.h>
Public Member Functions | |
OlsGDTrainer (const OlsGDTrainer &)=delete | |
OlsGDTrainer (OlsGDTrainer &&)=delete | |
OlsGDTrainer & | operator= (const OlsGDTrainer &)=delete |
OlsGDTrainer & | operator= (OlsGDTrainer &&)=delete |
~OlsGDTrainer ()=default | |
OlsGDTrainer (txeo::DataTable< T > &&data) | |
Construct a new OlsGD Trainer object from a data table. | |
OlsGDTrainer (const txeo::DataTable< T > &data) | |
txeo::Tensor< T > | predict (const txeo::Tensor< T > &input) const override |
Makes predictions using learned weights. | |
T | learning_rate () const |
Gets current learning rate. | |
void | set_learning_rate (T learning_rate) |
Sets learning rate for gradient descent. | |
void | enable_variable_lr () |
Enables adaptive learning rate adjustment (Barzilai-Borwein Method). When enabled, learning rate automatically reduces when loss plateaus. For the majority of the cases, convergence drastically increases. | |
void | disable_variable_lr () |
Disables adaptive learning rate adjustment (Barzilai-Borwein Method) | |
const txeo::Matrix< T > & | weight_bias () const |
Gets weight/bias matrix related to the minimum loss during fit. | |
T | tolerance () const |
Gets convergence tolerance. | |
void | set_tolerance (const T &tolerance) |
Sets convergence tolerance. | |
bool | is_converged () const |
Checks convergence status. | |
T | min_loss () const |
Gets the minimum loss during training. | |
![]() | |
Trainer (const Trainer &)=delete | |
Trainer (Trainer &&)=delete | |
Trainer & | operator= (const Trainer &)=delete |
Trainer & | operator= (Trainer &&)=delete |
virtual | ~Trainer ()=default |
Trainer (txeo::DataTable< T > &&data, txeo::Logger &logger=txeo::LoggerConsole::instance()) | |
Construct a new Trainer object from a data table. | |
Trainer (const txeo::DataTable< T > &data) | |
virtual void | fit (size_t epochs, txeo::LossFunc metric) |
Trains the model for specified number of epochs. | |
virtual void | fit (size_t epochs, txeo::LossFunc metric, size_t patience) |
Trains with early stopping based on validation performance. | |
virtual void | fit (size_t epochs, txeo::LossFunc metric, size_t patience, txeo::NormalizationType type) |
Trains with early stopping based on validation performance and feature normalization. | |
T | compute_test_loss (txeo::LossFunc metric) const |
Evaluates test data based on a specified metric. | |
bool | is_trained () const |
Checks if model has been trained. | |
const txeo::DataTable< T > & | data_table () const |
Returns the data table of this trainer. | |
void | enable_feature_norm (txeo::NormalizationType type) |
Enable feature normalization. | |
void | disable_feature_norm () |
Disable feature normalization. | |
Additional Inherited Members | |
![]() | |
Trainer ()=default | |
![]() | |
bool | _is_trained {false} |
bool | _is_early_stop {false} |
size_t | _patience {0} |
std::unique_ptr< txeo::DataTable< T > > | _data_table |
txeo::Logger * | _logger {nullptr} |
txeo::DataTableNorm< T > | _data_table_norm |
bool | _is_norm_enabled {false} |
Ordinary Least Squares trainer using Gradient Descent optimization.
T | Floating-point type for calculations (float, double, etc.) |
Implements linear regression training through gradient descent with:
Inherits from txeo::Trainer<T> and implements required virtual methods.
Implements algorithms based on paper: Algarte, R.D., "Tensor-Based Foundations of Ordinary Least Squares and Neural Network Regression Models" (https://arxiv.org/abs/2411.12873)
Example Usage:
Definition at line 60 of file OlsGDTrainer.h.
|
delete |
|
delete |
|
default |
|
inline |
Construct a new OlsGD Trainer object from a data table.
data | Training/Evaluation/Test data |
Definition at line 73 of file OlsGDTrainer.h.
|
inline |
Definition at line 75 of file OlsGDTrainer.h.
|
inline |
Disables adaptive learning rate adjustment (Barzilai-Borwein Method)
Definition at line 113 of file OlsGDTrainer.h.
|
inline |
Enables adaptive learning rate adjustment (Barzilai-Borwein Method). When enabled, learning rate automatically reduces when loss plateaus. For the majority of the cases, convergence drastically increases.
Definition at line 108 of file OlsGDTrainer.h.
|
inline |
Checks convergence status.
Definition at line 143 of file OlsGDTrainer.h.
T txeo::OlsGDTrainer< T >::learning_rate | ( | ) | const |
Gets current learning rate.
T txeo::OlsGDTrainer< T >::min_loss | ( | ) | const |
Gets the minimum loss during training.
|
delete |
|
delete |
|
overridevirtual |
Makes predictions using learned weights.
input | Feature matrix (shape: [samples, features]) |
OlsGDTrainerError |
Implements txeo::Trainer< T >.
Sets learning rate for gradient descent.
learning_rate | Must be > 0 |
OlsGDTrainerError | for invalid values |
Sets convergence tolerance.
tolerance | Minimum loss difference to consider converged (>0) |
|
inline |
Gets convergence tolerance.
Definition at line 129 of file OlsGDTrainer.h.
const txeo::Matrix< T > & txeo::OlsGDTrainer< T >::weight_bias | ( | ) | const |
Gets weight/bias matrix related to the minimum loss during fit.
OlsGDTrainerError |