dmlfw (Daniyal Machine Learning Framework)
|
Demonstrates batch gradient descent for linear regression using ml-framework. More...
#define | FREQUENCY_OF_PRINTING_COST 50000 |
dmlfw_gradient_descent_options * | get_gradient_descent_options () |
Creates and configures gradient descent options object. | |
FILE * | gnuplot |
#define | LEARNING_RATE 0.0001 |
void | load_dataset (dmlfw_mat_double **x, dmlfw_column_vec_double **y) |
Loads the dataset into X (features matrix) and Y (target vector). Adds bias column filled with 1.0. | |
int | main () |
Main function to execute batch gradient descent linear regression example. | |
#define | MODEL_FILE_NAME "example-1-model.csv" |
#define | NUMBER_OF_ITERATIONS 3000000 |
int | on_iteration_complete (uint64_t iteration_number, void *y, void *predicted_y, void *model, double regularization_parameter) |
Progress callback called on each gradient descent iteration. Logs cost, updates plot files, shows graph via gnuplot at intervals. | |
void | print_error_and_exit () |
Prints error string from ml-framework and exits program. | |
#define | REGULARIZATION_PARAMETER 0.5 |
#define | SHOW_GRAPH 1 |
#define | TRAINING_DATASET "IceCreamSales_training_examples.csv" |
Demonstrates batch gradient descent for linear regression using ml-framework.
This example loads the IceCreamSales training dataset, trains a linear regression model using batch gradient descent with regularization, tracks cost progress, optionally plots cost and fitted line using gnuplot, and saves the final model to CSV.
Defines custom progress callback for iteration logging and visualization.
Usage: ./batch_gd
#define FREQUENCY_OF_PRINTING_COST 50000 |
Frequency of printing/logging cost during training
#define LEARNING_RATE 0.0001 |
Learning rate for gradient descent
#define MODEL_FILE_NAME "example-1-model.csv" |
Output model CSV file path
#define NUMBER_OF_ITERATIONS 3000000 |
Maximum number of iterations for gradient descent
#define REGULARIZATION_PARAMETER 0.5 |
Regularization parameter (lambda)
#define SHOW_GRAPH 1 |
Flag to enable (1) or disable (0) graph plotting
#define TRAINING_DATASET "IceCreamSales_training_examples.csv" |
Training dataset CSV file path
dmlfw_gradient_descent_options * get_gradient_descent_options | ( | ) |
Creates and configures gradient descent options object.
Sets learning rate, number of iterations, gradient descent type, and associates the progress callback.
void load_dataset | ( | dmlfw_mat_double ** | x, |
dmlfw_column_vec_double ** | y | ||
) |
Loads the dataset into X (features matrix) and Y (target vector). Adds bias column filled with 1.0.
[out] | x | Pointer to the features matrix pointer. |
[out] | y | Pointer to the target column vector pointer. |
int main | ( | ) |
Main function to execute batch gradient descent linear regression example.
Loads dataset, creates gradient descent options, fits model, saves model parameters to CSV, and manages resources.
int on_iteration_complete | ( | uint64_t | iteration_number, |
void * | y, | ||
void * | predicted_y, | ||
void * | model, | ||
double | regularization_parameter | ||
) |
Progress callback called on each gradient descent iteration. Logs cost, updates plot files, shows graph via gnuplot at intervals.
iteration_number | Current iteration number. |
y | Actual target vector. |
predicted_y | Predicted target vector. |
model | Current model parameters. |
regularization_parameter | Regularization coefficient lambda. |
void print_error_and_exit | ( | ) |
Prints error string from ml-framework and exits program.
FILE* gnuplot |
Gnuplot file pointer used for plotting progress