cfuncs module#

cfuncs contains all standard cost functions integrated into mlr-gd and melar.

Each cost function has a name (ex. mse) that returns a cost. Each cost function has a derivative function, indicated by _deriv

melar.cfuncs.mae(y_predictions: ndarray, y_target: ndarray) float64[source]#

MAE Function.

Calculates the mean absolute error of predictions as compared to the target values.

Parameters:
  • y_predictions (np.ndarray) – Predicted values.

  • y_target (np.ndarray) – Target values.

Returns:

Mean of the absolute remainder array (y_predictions - y_target)

Return type:

np.float64

melar.cfuncs.mae_deriv(x_training: ndarray, y_training: ndarray, y_predict: ndarray) tuple[source]#

Derivative of mae

Parameters:
  • x_training (np.ndarray) – Input values.

  • y_training (np.ndarray) – Target values.

  • y_predict (np.ndarray) – Predicted values.

Returns:

Derivative of cost function mae (bias_derivative, weights_derivative)

Return type:

tuple (np.float64, np.ndarray)

melar.cfuncs.mse(y_predictions: ndarray, y_target: ndarray) float64[source]#

MSE Function.

Calculates the mean square error of predictions as compared to the target values.

Parameters:
  • y_predictions (np.ndarray) – Predicted values.

  • y_target (np.ndarray) – Target values.

Returns:

Mean of the squared remainder array (y_predictions - y_target)

Return type:

np.float64

melar.cfuncs.mse_deriv(x_training: ndarray, y_training: ndarray, y_predict: ndarray) tuple[source]#

Derivative of mse

Parameters:
  • x_training (np.ndarray) – Input values.

  • y_training (np.ndarray) – Target values.

  • y_predict (np.ndarray) – Predicted values.

Returns:

Derivative of cost function mse (bias_derivative, weights_derivative)

Return type:

tuple (np.float64, np.ndarray)