spines.parameters.base¶
Base classes for model parameters.
-
class
spines.parameters.base.
HyperParameter
(*value_type, default: Optional[Any] = None, desc: Optional[str] = None)[source]¶ Bases:
spines.parameters.base.Parameter
Hyper-parameter
-
exception
spines.parameters.base.
InvalidParameterException
[source]¶ Bases:
spines.parameters.base.ParameterException
Thrown when an invalid parameter is given.
-
exception
spines.parameters.base.
MissingParameterException
[source]¶ Bases:
spines.parameters.base.ParameterException
Thrown when a required parameter is missing.
-
class
spines.parameters.base.
Parameter
(*value_type, default: Optional[Any] = None, desc: Optional[str] = None)[source]¶ Bases:
object
Parameter class
- Parameters
value_type (
type
orIterable
oftype
) – The type(s) of values allowed for this parameter.default (object, optional) – Default value for this parameter, if any.
desc (str, optional) – Description for this parameter, if any.
-
check
(value: Any) → bool[source]¶ Checks the given value for validity
Based on this particular Parameter’s settings this method checks the given value to see if it’s in-line with the specifications.
- Parameters
value – Parameter value to check validity of.
- Returns
Whether or not the value is valid for the parameter.
- Return type
bool
See also
-
default
¶ Default value to use for this parameter.
- Type
object
-
desc
¶ Description of this parameter.
- Type
str
-
name
¶ Name of this parameter.
- Type
str
-
preprocess
(value: Any) → Any[source]¶ Pre-process/massage parameter values into correct type
This is used to try and convert parameter values to the allowed types (if possible). For instance the allowed type may be a
float
but the user provides1
, we would likely not want to break in that situation, but simply convert theint
given into afloat
. However, this can also be used to perform more complex initialization or customization on given parameter values, if needed.The default method is to try and cast the given value as the types given in this Parameter’s
_value_types
attribute and returning the first successful cast, otherwise returns the given input value.This method can be easily extended or overridden for custom Parameter classes to handle more complex value types.
- Parameters
value (object) – The value to pre-process for this parameter.
- Returns
The pre-processed value.
- Return type
object
Note
This method is, by default, only called if the given value fails this Parameter’s
check
call.See also
-
required
¶ Whether or not this parameter is required to be set.
- Type
bool
-
value_type
¶ The types of values allowed for this option.
- Type
tuple