pydvl.utils.types
¶
This module contains types, protocols, decorators and generic function transformations. Some of it probably belongs elsewhere.
BaggingModel
¶
Bases: Protocol
Any model with the attributes n_estimators
and max_samples
is considered a
bagging model.
fit
¶
BaseModel
¶
SupervisedModel
¶
Bases: Protocol
This is the standard sklearn Protocol with the methods fit()
, predict()
and
score()
.
fit
¶
predict
¶
ensure_seed_sequence
¶
ensure_seed_sequence(
seed: Optional[Union[Seed, SeedSequence]] = None,
) -> SeedSequence
If the passed seed is a SeedSequence object then it is returned as is. If it is a Generator the internal protected seed sequence from the generator gets extracted. Otherwise, a new SeedSequence object is created from the passed (optional) seed.
PARAMETER | DESCRIPTION |
---|---|
seed
|
Either an int, a Generator object a SeedSequence object or None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SeedSequence
|
A SeedSequence object. |
New in version 0.7.0
Source code in src/pydvl/utils/types.py
validate_number
¶
validate_number(
name: str,
value: Any,
dtype: Type[T],
lower: T | None = None,
upper: T | None = None,
) -> T
Ensure that the value is of the given type and within the given bounds.
For int and float types, this function is lenient with numpy numeric types and will convert them to the appropriate Python type as long as no precision is lost.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the variable to validate.
TYPE:
|
value
|
The value to validate.
TYPE:
|
dtype
|
The type to convert the value to.
TYPE:
|
lower
|
The lower bound for the value (inclusive).
TYPE:
|
upper
|
The upper bound for the value (inclusive).
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the value is not of the given type. |
ValueError
|
If the value is not within the given bounds, if there is precision
loss, e.g. when forcing a float to an int, or if |