Utilities
Samplers
Samplers are designed to be used with supertypes. See the Supertypes page for examples on how they are used.
Interface
- class phantom.utils.samplers.Sampler[source]
Samplers are used in Agent/Environment Supertypes to define how they are sampled.
Samplers are designed to be used when training policies and a stochastic distribution of values is required for the Supertype sampling.
Samplers return an unbounded number of total values with one value being returned at a time with the
sample()
method.
- class phantom.utils.samplers.ComparableSampler[source]
Extension of the
Sampler
for ComparableTypes in order to treat theComparableSampler
like its actual internal value.Example: >>> s = UniformFloatSampler() >>> s.value = s.sample() >>> s <= 1.0 # True >>> s == 1.5 # False
Implementations
- class phantom.utils.samplers.UniformFloatSampler(low=0.0, high=1.0, clip_low=None, clip_high=None)[source]
Samples a single float value from a uniform distribution.
Uses
np.random.uniform()
internally.
- class phantom.utils.samplers.UniformIntSampler(low=0, high=1, clip_low=None, clip_high=None)[source]
Samples a single int value from a uniform distribution.
Uses
np.random.randint()
internally.
- class phantom.utils.samplers.UniformArraySampler(low=0.0, high=1.0, shape=(1,), clip_low=None, clip_high=None)[source]
Samples an array of float values from a uniform distribution.
Uses
np.random.uniform()
internally.
- class phantom.utils.samplers.NormalSampler(mu, sigma, clip_low=None, clip_high=None)[source]
Samples a single float value from a normal distribution.
Uses
np.random.normal()
internally.
- class phantom.utils.samplers.NormalArraySampler(mu, sigma, shape=(1,), clip_low=None, clip_high=None)[source]
Samples an array of float values from a normal distribution.
Uses
np.random.normal()
internally.
Ranges
Ranges are designed to be used with supertypes. See the Supertypes page for examples on how they are used.
Interface
- class phantom.utils.ranges.Range(name=None)[source]
Ranges are used in Agent/Environment Supertypes to define how they are sampled.
Ranges are designed to be used when generating rollouts post-training and a non-stochastic distribution of values is required for the Supertype sampling.
Ranges return a fixed number of total values and as such all values must be returned in one go with the
values()
method.
Implementations
- class phantom.utils.ranges.UniformRange(start, end, step=1.0, name=None, dtype=None)[source]
Returns an array of values spaced by a step between a start and end value.
Uses
np.arange()
internally.
- class phantom.utils.ranges.LinspaceRange(start, end, n, name=None, dtype=None)[source]
Returns an array of n values evenly distributed between a start and end value.
Uses
np.linspace()
internally.
- class phantom.utils.ranges.UnitArrayUniformRange(start, end, step=1.0, name=None, dtype=None)[source]
Returns a list of n shape (1,) numpy arrays with values spaced by a step between a start and end value. Useful for encoding observation spaces with single element boxes.
Uses
np.arange()
internally.