quara.loss_function.loss_function module
- class LossFunction(num_var=None)[source]
Bases:
objectConstructor
Subclasses have a responsibility to set
on_value,on_gradient,on_hessian.- Parameters
num_var (int, optional) – number of variables, by default None
- abstract gradient(var)[source]
returns the gradient of the loss function.
- Parameters
var (np.ndarray) – np.ndarray of variables.
- Returns
the gradient of the loss function. dtype=np.float64
- Return type
np.ndarray
- Raises
NotImplementedError – this function does not be implemented in the subclass.
- abstract hessian(var)[source]
returns the Hessian of the loss function.
- Parameters
var (np.ndarray) – np.ndarray of variables.
- Returns
the Hessian of the loss function. dtype=np.float64
- Return type
np.ndarray
- Raises
NotImplementedError – this function does not be implemented in the subclass.
- is_option_sufficient()[source]
returns whether the option is sufficient.
In the default implementation, this function returns True. Override with subclasses as needed.
- Returns
whether the option is sufficient.
- Return type
bool
- property num_var: int
returns number of variables.
- Returns
number of variables.
- Return type
int
- property on_gradient: bool
returns whether or not to support gradient.
- Returns
whether or not to support gradient.
- Return type
bool
- property on_hessian: bool
returns whether or not to support Hessian.
- Returns
whether or not to support Hessian.
- Return type
bool
- property on_value: bool
returns whether or not to support value.
- Returns
whether or not to support value.
- Return type
bool
- property option: quara.loss_function.loss_function.LossFunctionOption
returns loss function option.
- Returns
loss function option.
- Return type
- set_from_option(option)[source]
sets option from LossFunctionOption and calls
is_option_sufficientfunction.- Parameters
option (LossFunctionOption) – option to set.
- Return type
None
- set_from_standard_qtomography_option_data(qtomography, option, data, is_gradient_required, is_hessian_required)[source]
sets settings of loss function.
This implementation is empty by default. If necessary, implement it in subclasses.
- Parameters
qtomography (StandardQTomography) – StandardQTomography for settings of loss function.
option (LossFunctionOption) – ProbabilityBasedLossFunctionOption for settings of loss function.
data (List[Tuple[int, np.ndarray]]) – empirical distributions for settings of loss function.
is_gradient_required (bool) – whether or not to require gradient.
is_hessian_required (bool) – whether or not to require Hessian.
- Return type
None
- class LossFunctionOption(mode_weight=None, weights=None, weight_name=None)[source]
Bases:
objectConstructor
- Parameters
mode_weight (str, optional) – mode weight, by default None
weights (List, optional) – list of weight, by default None
weight_name (str, optional) – weight name for reporting, by default None
- property mode_weight: str
returns mode weight.
- Returns
mode weight.
- Return type
str
- property weight_name: str
returns weight name for reporting.
- Returns
weight name for reporting.
- Return type
str
- property weights: List
returns weights.
- Returns
list of weight.
- Return type
List