squlearn.qnn.loss
.VarianceLoss
- class squlearn.qnn.loss.VarianceLoss(alpha: float | Callable[[int], float] = 0.005)
Variance loss for regression.
- Parameters:
alpha (float, Callable[[int], float]) – Weight value \(\alpha\)
- gradient(value_dict: dict, **kwargs) ndarray | tuple[ndarray, ndarray]
Returns the gradient of the variance.
This function calculates the gradient of the variance values in value_dict.
- Parameters:
value_dict (dict) – Contains calculated values of the model
iteration (int) – iteration number, if variance_factor is a function
multiple_output (bool) – True if the QNN has multiple outputs
- Returns:
Gradient values
- set_opt_param_op(opt_param_op: bool = True)
Sets the opt_param_op flag.
- Parameters:
opt_param_op (bool) – True, if operator has trainable parameters
- value(value_dict: dict, **kwargs) float
Returns the variance.
This function returns the weighted variance as
\[L_\operatorname{Var} = \alpha \sum_i \operatorname{Var}_i\]- Parameters:
value_dict (dict) – Contains calculated values of the model
iteration (int) – iteration number, if alpha is a callable function
- Returns:
Loss value
- variance(value_dict: dict, **kwargs) float
Returns 0 since we neglect the variance of the variance.