CostFunction#
- class caf.distribute.cost_functions.CostFunction(name, params, function, default_params=None)#
Bases:
objectAbstract Class defining how cost function classes should look.
If a new cost function is needed, then a new class needs to be made which inherits this abstract class.
Attributes Summary
Return the key-word names of the cost function params.
Methods Summary
calculate(base_cost, **kwargs)Calculate the actual cost using self.function.
Get random parameter values for this cost function.
validate_params(param_dict)Check the given values are valid and within min/max ranges.
Attributes Documentation
- Parameters:
name (str)
params (Mapping[str, tuple[float, float]])
function (Callable)
default_params (Optional[Mapping[str, float | int]])
- parameter_names#
Return the key-word names of the cost function params.
Methods Documentation
- calculate(base_cost, **kwargs)#
Calculate the actual cost using self.function.
Before calling the cost function the given cost function params will be checked that they are within the min and max values passed in when creating the object. The cost function will then be called and the value returned.
- Parameters:
base_cost (ndarray) – Array of the base costs.
kwargs
self.function. (Parameters of the cost function to pass to)
- Returns:
Output from self.function, same shape as base_cost.
- Return type:
costs
- Raises:
ValueError: – If the given cost function params are outside the min/max range for this class.
- random_valid_params()#
Get random parameter values for this cost function.
- Return type:
dict[str, Any]
- validate_params(param_dict)#
Check the given values are valid and within min/max ranges.
Validates that the param dictionary given contains only and all expected parameter names as keys, and that the values for each key fall within the acceptable parameter ranges.
- Parameters:
param_dict (dict[str, Any]) – A dictionary of values to validate. Should be in {param_name: param_value} format.
- Raises:
ValueError: – If any of the given params do not have valid name, or their values fall outside the min/max range defined in this class.
- Return type:
None