dmlfw (Daniyal Machine Learning Framework)
|
Mini-batch stochastic gradient descent training example using DMLFW. More...
dmlfw_mat_double * | buffer_matrix_1 = NULL |
dmlfw_mat_double * | buffer_matrix_1_shuffled = NULL |
dmlfw_mat_double * | buffer_matrix_2 = NULL |
dmlfw_mat_double * | buffer_matrix_2_shuffled = NULL |
uint32_t | BUFFER_SIZE = 50 |
void | data_loader (void *x, void *y, uint64_t from_row, uint32_t how_many_rows) |
Supplies mini-batch data to gradient descent algorithm. | |
#define | FREQUENCY_OF_PRINTING_COST 100 |
void | get_from_file_buffer (dmlfw_mat_double **target_matrix, uint64_t from_row, uint32_t how_many_rows) |
Retrieves a data block for training from buffers. | |
dmlfw_gradient_descent_options * | get_gradient_descent_options () |
Creates and configures options for mini-batch stochastic gradient descent. | |
FILE * | gnuplot |
void | init_buffers () |
Initializes minibatch data buffers before training. | |
#define | LEARNING_RATE 0.00001 |
int | main () |
Main entry point running the mini-batch stochastic gradient descent training example. | |
uint32_t | MINI_BATCH_SIZE = 46 |
#define | MODEL_FILE_NAME "example-3-model.csv" |
dmlfw_column_vec_double * | model_squared_sum_vector = NULL |
dmlfw_row_vec_double * | model_transposed = NULL |
uint64_t | number_of_columns_in_training_examples = 0 |
#define | NUMBER_OF_ITERATIONS 100000 |
uint64_t | number_of_training_examples = 0 |
int | on_iteration_complete (uint64_t iteration_number, void *y, void *predicted_y, void *model, double regularization_parameter) |
Callback after each gradient descent iteration to log cost and plot progress. | |
dmlfw_column_vec_double * | prediction_error = NULL |
dmlfw_row_vec_double * | prediction_error_transposed = NULL |
void | print_error_and_exit () |
Prints ml-framework error string and terminates program. | |
dmlfw_column_vec_double * | product_vector = NULL |
#define | REGULARIZATION_PARAMETER 0.5 |
#define | SHOW_GRAPH 1 |
#define | TRAINING_DATASET "IceCreamSales_training_examples.csv" |
dmlfw_mat_double * | x_matrix = NULL |
dmlfw_mat_double * | xy_matrix = NULL |
dmlfw_column_vec_double * | y_vector = NULL |
Mini-batch stochastic gradient descent training example using DMLFW.
This program trains a linear regression model on the IceCreamSales dataset using mini-batch stochastic gradient descent with regularization. It manages data buffering, shuffling, and mini-batch provision for efficient training.
The training progress is logged and optionally visualized with gnuplot showing cost descent and fitted line graphs. The final model parameters are saved to a CSV file.
Global buffers are used for dataset handling, and a custom progress callback logs iteration-wise cost with early termination support.
Usage: ./mini_batch_gd
#define FREQUENCY_OF_PRINTING_COST 100 |
Frequency of printing/logging cost
#define LEARNING_RATE 0.00001 |
Learning rate for gradient descent
#define MODEL_FILE_NAME "example-3-model.csv" |
Output model CSV file path
#define NUMBER_OF_ITERATIONS 100000 |
Maximum number of gradient descent iterations
#define REGULARIZATION_PARAMETER 0.5 |
Regularization parameter lambda
#define SHOW_GRAPH 1 |
Enable or disable plotting with gnuplot (1 = enabled)
#define TRAINING_DATASET "IceCreamSales_training_examples.csv" |
Training dataset CSV file path
void data_loader | ( | void * | x, |
void * | y, | ||
uint64_t | from_row, | ||
uint32_t | how_many_rows | ||
) |
Supplies mini-batch data to gradient descent algorithm.
x | Pointer to feature matrix pointer. |
y | Pointer to target vector pointer. |
from_row | Starting row of data to load. |
how_many_rows | Number of rows to load. |
void get_from_file_buffer | ( | dmlfw_mat_double ** | target_matrix, |
uint64_t | from_row, | ||
uint32_t | how_many_rows | ||
) |
Retrieves a data block for training from buffers.
target_matrix | Matrix pointer to fill. |
from_row | Starting row index in dataset. |
how_many_rows | Number of rows to retrieve. |
dmlfw_gradient_descent_options * get_gradient_descent_options | ( | ) |
Creates and configures options for mini-batch stochastic gradient descent.
void init_buffers | ( | ) |
Initializes minibatch data buffers before training.
int main | ( | ) |
Main entry point running the mini-batch stochastic gradient descent training example.
int on_iteration_complete | ( | uint64_t | iteration_number, |
void * | y, | ||
void * | predicted_y, | ||
void * | model, | ||
double | regularization_parameter | ||
) |
Callback after each gradient descent iteration to log cost and plot progress.
iteration_number | Current iteration index. |
y | Actual target values. |
predicted_y | Model predicted values. |
model | Current model parameters. |
regularization_parameter | Lambda regularization value. |
void print_error_and_exit | ( | ) |
Prints ml-framework error string and terminates program.
dmlfw_mat_double* buffer_matrix_1 = NULL |
Primary buffer matrix holding dataset block for training
dmlfw_mat_double* buffer_matrix_1_shuffled = NULL |
Shuffled copy of primary buffer matrix
dmlfw_mat_double* buffer_matrix_2 = NULL |
Secondary buffer matrix holding remaining dataset block
dmlfw_mat_double* buffer_matrix_2_shuffled = NULL |
Shuffled copy of secondary buffer matrix
uint32_t BUFFER_SIZE = 50 |
Buffer size, adjustable at runtime for batch loading
FILE* gnuplot |
Gnuplot pipe pointer used for plotting graphs
uint32_t MINI_BATCH_SIZE = 46 |
Mini batch size, adjustable at runtime
dmlfw_column_vec_double* model_squared_sum_vector = NULL |
Vector holding squared sum of model parameters for regularization calculation
dmlfw_row_vec_double* model_transposed = NULL |
Transposed vector of current model parameters during callback
uint64_t number_of_columns_in_training_examples = 0 |
Number of columns (features + target) in training dataset
uint64_t number_of_training_examples = 0 |
Total number of training examples (rows) in dataset
dmlfw_column_vec_double* prediction_error = NULL |
Vector holding prediction errors during training progress callback
dmlfw_row_vec_double* prediction_error_transposed = NULL |
Transposed version of prediction_error vector
dmlfw_column_vec_double* product_vector = NULL |
Temporary vector used for intermediate matrix products
dmlfw_mat_double* x_matrix = NULL |
Feature matrix pointer used in data loading for mini-batches
dmlfw_mat_double* xy_matrix = NULL |
Combined feature-target matrix used temporarily for data loading
dmlfw_column_vec_double* y_vector = NULL |
Target vector pointer used in data loading for mini-batches