dmlfw (Daniyal Machine Learning Framework)

Gradient descent-based linear regression training and prediction. More...

#include <dmlfw_vector.h>
#include <dmlfw_matrix.h>
#include <dmlfw_algorithms.h>
Include dependency graph for dmlfw_linear_regression.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

dmlfw_column_vec_doubledmlfw_linear_regression_fit_using_batch_gradient_descent (dmlfw_gradient_descent_options *gd_options, dmlfw_mat_double *x, dmlfw_column_vec_double *y, double regularization_parameter, dmlfw_column_vec_double *model)
 Fits linear regression model using batch gradient descent.
 
dmlfw_column_vec_doubledmlfw_linear_regression_fit_using_mini_batch_gradient_descent (dmlfw_gradient_descent_options *gd_options, double regularization_parameter, dmlfw_column_vec_double *model)
 Fits linear regression model using mini-batch gradient descent.
 
dmlfw_column_vec_doubledmlfw_linear_regression_fit_using_stochastic_gradient_descent (dmlfw_gradient_descent_options *gd_options, double regularization_parameter, dmlfw_column_vec_double *model)
 Fits linear regression model using stochastic gradient descent.
 
dmlfw_column_vec_doubledmlfw_linear_regression_predict (dmlfw_mat_double *x, dmlfw_column_vec_double *model)
 Predicts output using trained linear regression model.
 

Detailed Description

Gradient descent-based linear regression training and prediction.

Version
1.0
Date
2025-09-25

This module provides APIs to fit linear regression models using batch, stochastic, and mini-batch gradient descent methods, including support for regularization and user-defined progress callbacks. It also offers prediction functionality from trained models.

Error Handling:

Functions use centralized error reporting. Call dmlfw_error() after function execution to check for errors. For error details, use dmlfw_get_error_string() and dmlfw_get_debug_string().

Ownership:

Returned vectors representing trained models or predictions must be freed using the vector destroy API to avoid memory leaks.

Function Documentation

◆ dmlfw_linear_regression_fit_using_batch_gradient_descent()

dmlfw_column_vec_double * dmlfw_linear_regression_fit_using_batch_gradient_descent ( dmlfw_gradient_descent_options gd_options,
dmlfw_mat_double x,
dmlfw_column_vec_double y,
double  regularization_parameter,
dmlfw_column_vec_double model 
)

Fits linear regression model using batch gradient descent.

Parameters
gd_options[in] Gradient descent options (non-NULL).
x[in] Feature matrix (non-NULL).
y[in] Target vector (non-NULL).
regularization_parameter[in] L2 regularization coefficient.
model[in,out] Optional initial model vector or NULL.
Returns
Pointer to trained model vector or NULL on error.
See also
dmlfw_linear_regression_predict

Usage example:

char err[512], dbg[512];
opts, x, y, 0.1, NULL);
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error training model: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use model...
void dmlfw_get_error_string(char *error_string, uint32_t size)
Copies the last error message into the provided character buffer.
uint8_t dmlfw_error(void)
Checks if the last framework call resulted in an error.
void dmlfw_get_debug_string(char *debug_string, uint32_t size)
Copies detailed debug information about the last error into the provided character buffer.
dmlfw_column_vec_double * dmlfw_linear_regression_fit_using_batch_gradient_descent(dmlfw_gradient_descent_options *gd_options, dmlfw_mat_double *x, dmlfw_column_vec_double *y, double regularization_parameter, dmlfw_column_vec_double *model)
Fits linear regression model using batch gradient descent.
void dmlfw_column_vec_double_destroy(dmlfw_column_vec_double *vector)
Destroys a column vector and frees its memory.
struct __dmlfw_column_vec_double dmlfw_column_vec_double
Opaque structure representing a column vector of doubles.
Definition dmlfw_vec_double.h:83
Examples
example_dmlfw_linear_regression.c.

◆ dmlfw_linear_regression_fit_using_mini_batch_gradient_descent()

dmlfw_column_vec_double * dmlfw_linear_regression_fit_using_mini_batch_gradient_descent ( dmlfw_gradient_descent_options gd_options,
double  regularization_parameter,
dmlfw_column_vec_double model 
)

Fits linear regression model using mini-batch gradient descent.

Parameters
gd_options[in] Gradient descent options (non-NULL).
regularization_parameter[in] L2 regularization coefficient.
model[in,out] Optional initial model vector or NULL.
Returns
Pointer to trained model vector or NULL on error.

◆ dmlfw_linear_regression_fit_using_stochastic_gradient_descent()

dmlfw_column_vec_double * dmlfw_linear_regression_fit_using_stochastic_gradient_descent ( dmlfw_gradient_descent_options gd_options,
double  regularization_parameter,
dmlfw_column_vec_double model 
)

Fits linear regression model using stochastic gradient descent.

Parameters
gd_options[in] Gradient descent options (non-NULL).
regularization_parameter[in] L2 regularization coefficient.
model[in,out] Optional initial model vector or NULL.
Returns
Pointer to trained model vector or NULL on error.

◆ dmlfw_linear_regression_predict()

dmlfw_column_vec_double * dmlfw_linear_regression_predict ( dmlfw_mat_double x,
dmlfw_column_vec_double model 
)

Predicts output using trained linear regression model.

Parameters
x[in] Feature matrix (non-NULL).
model[in] Trained model vector (non-NULL).
Returns
Pointer to prediction vector or NULL on error.

Usage example:

char err[512], dbg[512];
if (dmlfw_error()) {
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error predicting output: %s\nDebug info: %s\n", err, dbg);
return NULL;
}
// Use predictions...
dmlfw_column_vec_double * dmlfw_linear_regression_predict(dmlfw_mat_double *x, dmlfw_column_vec_double *model)
Predicts output using trained linear regression model.
Examples
example_dmlfw_linear_regression.c.