dmlfw (Daniyal Machine Learning Framework)
|
Demonstrates mini-batch stochastic gradient descent for linear regression using ml-framework. 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 |
#define | BUFFER_SIZE 50 |
void | data_loader (void *x, void *y, uint64_t from_row, uint32_t how_many_rows) |
Supplies training data batches to SGD optimizer via buffer loading. | |
#define | FREQUENCY_OF_PRINTING_COST 100 |
dmlfw_gradient_descent_options * | get_gradient_descent_options () |
Configures options for SGD training. | |
void | get_one_from_file_buffer (dmlfw_mat_double **target_matrix, uint64_t from_row) |
Retrieves a single row from buffered training data. | |
FILE * | gnuplot |
void | init_buffers () |
Initializes data buffers used for training data management. | |
#define | LEARNING_RATE 0.00001 |
int | main () |
Main entry point to run buffered stochastic gradient descent linear regression. | |
#define | MODEL_FILE_NAME "example-2-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) |
SGD iteration callback to calculate and log cost function. | |
dmlfw_column_vec_double * | prediction_error = NULL |
dmlfw_row_vec_double * | prediction_error_transposed = NULL |
void | print_error_and_exit () |
Prints ml-framework error and terminates execution. | |
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 |
Demonstrates mini-batch stochastic gradient descent for linear regression using ml-framework.
This example trains a linear regression model on the IceCreamSales training dataset using mini-batch stochastic gradient descent with specified batch size, learning rate, and regularization. Includes custom data loader, progress callback logging with cost visualization using gnuplot, and buffer management for data loading.
Usage: ./stochastic_gd
#define BUFFER_SIZE 50 |
Buffer size used for batch data loading
#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-2-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 training data batches to SGD optimizer via buffer loading.
x | Pointer to feature matrix pointer to populate. |
y | Pointer to target vector pointer to populate. |
from_row | Starting row index for batch. |
how_many_rows | Number of rows requested. |
dmlfw_gradient_descent_options * get_gradient_descent_options | ( | ) |
Configures options for SGD training.
void get_one_from_file_buffer | ( | dmlfw_mat_double ** | target_matrix, |
uint64_t | from_row | ||
) |
Retrieves a single row from buffered training data.
target_matrix | Output pointer to matrix containing the row. |
from_row | Row index to retrieve. |
void init_buffers | ( | ) |
Initializes data buffers used for training data management.
int main | ( | ) |
Main entry point to run buffered stochastic gradient descent linear regression.
int on_iteration_complete | ( | uint64_t | iteration_number, |
void * | y, | ||
void * | predicted_y, | ||
void * | model, | ||
double | regularization_parameter | ||
) |
SGD iteration callback to calculate and log cost function.
iteration_number | Current iteration count. |
y | Actual target vector. |
predicted_y | Predicted output by model. |
model | Current model weights. |
regularization_parameter | Regularization factor. |
void print_error_and_exit | ( | ) |
Prints ml-framework error and terminates execution.
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
FILE* gnuplot |
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