losses
Functions for computing losses
- QQuantLib.qml4var.losses.compute_integral(y_array, x_array, dask_client=None)
Function for computing numerical integral of inputs arrays.
- Parameters:
y_array (np.array or dask futures:) – array or futures (only is dask_client is provided) with the y-values for integration. For array expected shape is: shape(n)
x_array (np array) – array with the x domain for integration: Shape(n, n_features)
dask_client (DASK client) – DASK client to submit computation of the integral. y_array MUST BE a list of futures
- Returns:
integral – float or future (if dask_client is provided) with the desired integral computation.
- Return type:
float or future
Note
- Considerations:
if x_array has shape(n, 1): then numpy trapz is used for computing integral.
if x_array has shape(n, 2): and dask_client is None numpy trapz is used for computing the double integral.
if x_array has shape(n, 2): and dask_client is provided then MonteCarlo integration is used.
if x_array has shape(n, > 2): MonteCarlo integration is used
- QQuantLib.qml4var.losses.compute_loss(weights, produce_results, loss_function)
Workflow for computing loss:
- Parameters:
weights (list) – list with the weights for the PQC
produce_results (python function) – Function for producing mandatory inputs for computing loss
loss_function (python function) – Function for computing loss function
- Returns:
loss_ – Loss value
- Return type:
float
- QQuantLib.qml4var.losses.loss_function_qdml(labels, predict_cdf, predict_pdf, integral, loss_weights=[1.0, 5.0])
Computes the function for Quantum Differential Machine Learning
- Parameters:
labels (numpy array) – numpy array with the labels. Shape: (-1, 1)
predict_cdf (numpy array) – numpy array with the predictions for the CDF. Shape: (-1, 1)
predict_pdf (numpy array) – numpy array with the predictions for the PDF. Shape: (-1, 1)
integral (float) – float with the integral of the square of the PDF in the desired domain
loss_weights (list) – Weights for each part of the Loss function
- Returns:
loss_ – evaluation of the loss function for QDML
- Return type:
float
- QQuantLib.qml4var.losses.mse(labels, prediction)
Compute Mean Square Error
- Parameters:
labels (numpy array) – numpy array with the labels
prediction (numpy array) – numpy array with the predictions
- Returns:
mse_v – MSE value
- Return type:
float
- QQuantLib.qml4var.losses.numeric_gradient(weights, data_x, data_y, loss)
Compute the numeric gradient for some input loss function properly configured.
- Parameters:
weights (numpy array) – Array with weights for PQC
data_x (numpy array) – Array with dataset of the features
data_y (numpy array) – Array with targets (labes) dataset
loss (function) – function for computing the loss properly configured
- Returns:
gradient_i – Array with the gradients of the Loss Function
- Return type:
numpy array
- QQuantLib.qml4var.losses.trapezoidal_rule(x_domain, y_range)
Computes the integral using the trapezoidal_rule
- Parameters:
x_domain (numpy array) – domain for computing the integral
y_range (numpy array) – range for computing the integral
- Returns:
integral – integral computed using the trapezoidal rule
- Return type:
float