Constraints¶
Setting Defaults¶
Since constraints are often the same for all layers in an SPN, libspn-keras
provides the following
functions to get and set default constraints. These can still be overridden by providing the initializers
explicitly at initialization of a layer.
Linear accumulator constraints¶
By default, the logspace accumulator constraint is set to GreaterEqualEpsilonNormalized
.
-
libspn_keras.
set_default_linear_accumulators_constraint
(op)¶ Set default sum op to conveniently use it throughout an SPN architecture.
- Parameters
op (
Constraint
) – A constraint applied to linear accumulators after updates- Return type
None
-
libspn_keras.
get_default_linear_accumulators_constraint
()¶ Get default linear accumulator constraint.
- Return type
Optional
[Constraint
]- Returns
A
Constraint
instance that was set withset_default_linear_accumulators_constraint
Logspace accumulator constraints¶
By default, the logspace accumulator constraint is set to LogNormalized
.
-
libspn_keras.
set_default_logspace_accumulators_constraint
(op)¶ Set default sum op to conveniently use it throughout an SPN architecture.
- Parameters
op (
Constraint
) – A constraint applied to logspace accumulators after updates- Return type
None
-
libspn_keras.
get_default_logspace_accumulators_constraint
()¶ Get default logspace accumulator constraint.
- Return type
Optional
[Constraint
]- Returns
A
Constraint
instance that was set withset_default_logspace_accumulators_constraint
Linear Weight Constraints¶
These should be used for linear accumulators.
-
class
libspn_keras.constraints.
GreaterEqualEpsilonNormalized
(epsilon=1e-10, axis=- 2)¶ Constraints the weight to be greater than or equal to epsilon and then normalizes.
- Parameters
epsilon (
float
) – Constant, usually small non-zero
-
class
libspn_keras.constraints.
GreaterEqualEpsilon
(epsilon=1e-10)¶ Constraints the weight to be greater than or equal to epsilon.
- Parameters
epsilon (
float
) – Constant, usually small non-zero
Log Weight Constraints¶
These should be used for log accumulators.
-
class
libspn_keras.constraints.
LogNormalized
(axis=- 2)¶ Normalizes log-space weights.
- Parameters
axis (int) – Axis along whichto normalize
Scale Constraints¶
The following constraint is useful for ensuring stable scale parameters in location-scale leaf layers.
-
class
libspn_keras.constraints.
Clip
(min, max=None)¶ Constraints the weights to be between
min
andmax
.- Parameters
min (
float
) – Minimum clip valuemax (
Optional
[float
]) – Maximum clip value