Probability#
- class deeptrack.features.Probability(feature: Feature, probability: float | Callable[[...], float], **kwargs: Any)#
Bases:
StructuralFeatureResolve a feature with a certain probability.
This feature conditionally applies a given feature to an input based on a sampled uniform random number. If the sampled number is less than the specified probability, the feature is resolved; otherwise, the input is returned unchanged.
To resample the decision, call .update() before evaluating the feature.
Parameters#
- feature: Feature
The feature to resolve conditionally.
- probability: PropertyLike[float]
The probability (from 0 to 1) of resolving the feature.
- **kwargs: Any
Additional keyword arguments passed to the parent StructuralFeature class.
Methods#
- get(inputs, probability, random_number, **kwargs) -> Any
Resolves the feature if the sampled random number is less than the specified probability.
Examples#
>>> import deeptrack as dt
In this example, the Add feature is applied to the input image with a 70% chance.
Define a feature and wrap it with Probability:
>>> add_feature = dt.Add(value=2) >>> probabilistic_feature = dt.Probability(add_feature, probability=0.7)
Define inputs:
>>> import numpy as np >>> >>> inputs = np.zeros((2, 3))
Apply the feature:
>>> probabilistic_feature.update() # Update the random number >>> outputs = probabilistic_feature(inputs)
With 70% probability, the output is:
>>> outputs array([[2., 2., 2.], [2., 2., 2.]])
With 30% probability, it remains:
>>> outputs array([[0., 0., 0.], [0., 0., 0.]])
Methods Summary
get(inputs, probability, random_number, **kwargs)Resolve the feature if random number is less than probability.
Methods Documentation
- get(inputs: Any, probability: float, random_number: float, **kwargs: Any) Any#
Resolve the feature if random number is less than probability.
Parameters#
- inputs: Any or list[Any]
The inputs to process.
- probability: float
The probability (between 0 and 1) of resolving the feature.
- random_number: float
A random number sampled to determine whether to resolve the feature. It is initialized when this feature is initialized. It can be updated using the .update() method.
- **kwargs: Any
Additional arguments passed to the feature’s resolve() method.
Returns#
- Any
The processed outputs. If the feature is resolved, this is the output of the feature; otherwise, it is the unchanged inputs.