dmlfw (Daniyal Machine Learning Framework)
|
Gradient descent configuration data structures and APIs. More...
Go to the source code of this file.
Gradient descent configuration data structures and APIs.
This module provides definitions and management functions for gradient descent configuration objects used with ML algorithms such as linear regression. It enables detailed customization of learning rate, iterations, gradient descent type, progress callbacks, data provisioning, and mini-batch processing.
All functions validate input parameters and report errors via the centralized error API. After function calls, check dmlfw_error()
to detect if an error occurred. Retrieve descriptive error messages with dmlfw_get_error_string()
and diagnostic info with dmlfw_get_debug_string()
.
typedef void(* dmlfw_gradient_descent_lin_reg_data_provider_t) (void *x, void *y, uint64_t from_row_index, uint32_t how_many_rows) |
Data provider callback for gradient descent linear regression.
Supplies batches of data for training.
x | Feature matrix subset. |
y | Target vector subset. |
from_row_index | Index of first row in batch. |
how_many_rows | Number of rows in batch. |
typedef int(* dmlfw_gradient_descent_lin_reg_progress_callback_t) (uint64_t iteration_number, void *y, void *predicted_y, void *model, double regularization_parameter) |
Progress callback for gradient descent linear regression.
Called during each iteration to report training status.
iteration_number | Current iteration count. |
y | Actual target values. |
predicted_y | Predicted target values. |
model | Current model parameters. |
regularization_parameter | Regularization term used. |
typedef struct _dmlfw_gradient_descent_options dmlfw_gradient_descent_options |
Opaque structure representing gradient descent configuration options.
The internal details are hidden. Use the provided API functions to create, manipulate, and destroy instances.
dmlfw_gradient_descent_options * dmlfw_gradient_descent_options_create_new | ( | void | ) |
Creates a new gradient descent options object with default values.
Usage example in API context:
Usage example in main():
void dmlfw_gradient_descent_options_destroy | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Destroys a gradient descent options object and frees associated memory.
gd_options | [in] Pointer to options to destroy, or NULL (no-op). |
Usage example:
dmlfw_gradient_descent_lin_reg_data_provider_t dmlfw_gradient_descent_options_get_data_provider | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Gets the data provider callback pointer.
gd_options | [in] Gradient descent options (must not be NULL). |
Usage example:
int dmlfw_gradient_descent_options_get_gradient_descent_type | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Gets the gradient descent type.
gd_options | [in] Gradient descent options (must not be NULL). |
Usage example:
double dmlfw_gradient_descent_options_get_learning_rate | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Gets the learning rate.
gd_options | [in] Gradient descent options (must not be NULL). |
Usage example:
uint32_t dmlfw_gradient_descent_options_get_mini_batch_size | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Gets the mini-batch size.
gd_options | [in] Gradient descent options (must not be NULL). |
Usage example:
uint64_t dmlfw_gradient_descent_options_get_number_of_iterations | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Gets the number of iterations.
gd_options | [in] Gradient descent options (must not be NULL). |
Usage example:
dmlfw_gradient_descent_lin_reg_progress_callback_t dmlfw_gradient_descent_options_get_progress_callback | ( | dmlfw_gradient_descent_options * | gd_options | ) |
Gets the progress callback pointer.
gd_options | [in] Gradient descent options (must not be NULL). |
Usage example:
void dmlfw_gradient_descent_options_set_data_provider | ( | dmlfw_gradient_descent_options * | gd_options, |
dmlfw_gradient_descent_lin_reg_data_provider_t | data_provider | ||
) |
Sets the data provider callback.
gd_options | [in,out] Gradient descent options (must not be NULL). |
data_provider | [in] Callback function pointer or NULL. |
Usage example:
void dmlfw_gradient_descent_options_set_gradient_descent_type | ( | dmlfw_gradient_descent_options * | gd_options, |
int | gradient_descent_type | ||
) |
Sets the gradient descent type.
gd_options | [in,out] Gradient descent options (must not be NULL). |
gradient_descent_type | [in] One of MLFW_BATCH_GRADIENT_DESCENT, MLFW_STOCHASTIC_GRADIENT_DESCENT, MLFW_MINI_BATCH_GRADIENT_DESCENT. |
Usage example:
void dmlfw_gradient_descent_options_set_learning_rate | ( | dmlfw_gradient_descent_options * | gd_options, |
double | learning_rate | ||
) |
Sets the learning rate.
gd_options | [in,out] Gradient descent options (must not be NULL). |
learning_rate | [in] Learning rate value. |
Usage example:
void dmlfw_gradient_descent_options_set_mini_batch_size | ( | dmlfw_gradient_descent_options * | gd_options, |
uint32_t | mini_batch_size | ||
) |
Sets the mini-batch size for mini-batch gradient descent.
gd_options | [in,out] Gradient descent options (must not be NULL). |
mini_batch_size | [in] Number of samples in a mini-batch. |
Usage example:
void dmlfw_gradient_descent_options_set_number_of_iterations | ( | dmlfw_gradient_descent_options * | gd_options, |
uint64_t | number_of_iterations | ||
) |
Sets the number of iterations.
gd_options | [in,out] Gradient descent options (must not be NULL). |
number_of_iterations | [in] Number of iterations. |
Usage example:
void dmlfw_gradient_descent_options_set_progress_callback | ( | dmlfw_gradient_descent_options * | gd_options, |
dmlfw_gradient_descent_lin_reg_progress_callback_t | progress_callback | ||
) |
Sets the progress callback.
gd_options | [in,out] Gradient descent options (must not be NULL). |
progress_callback | [in] Callback function pointer or NULL. |
Usage example: