d3m.base.primitives¶
-
class
d3m.base.primitives.DatasetSplitPrimitiveBase(*, hyperparams, random_seed=0, docker_containers=None, volumes=None, temporary_directory=None)[source]¶ Bases:
d3m.primitive_interfaces.generator.GeneratorPrimitiveBase[[d3m.container.list.List,typing.Params],typing.Hyperparams]A base class for primitives which fit on a
Datasetobject to produce splits of thatDatasetwhen producing. There are two produce methods: produce and produce_score_data. They take as an input a list of non-negative integers which identify whichDatasetsplits to return.This class is parameterized using only by two type variables,
ParamsandHyperparams.-
abstract
produce(*, inputs, timeout=None, iterations=None)[source]¶ For each input integer creates a
Datasetsplit and produces the trainingDatasetobject. ThisDatasetobject should then be used to fit (train) the pipeline.- Parameters
- Returns
The outputs of shape [num_inputs, …] wrapped inside
CallResult.- Return type
-
abstract
produce_score_data(*, inputs, timeout=None, iterations=None)[source]¶ For each input integer creates a
Datasetsplit and produces the scoringDatasetobject. ThisDatasetobject should then be used to test the pipeline and score the results.Output
Datasetobjects do not have targets redacted and are not directly suitable for testing.- Return type
-
abstract
set_training_data(*, dataset)[source]¶ Sets training data of this primitive, the
Datasetto split.- Parameters
dataset (
Dataset) – The dataset to split.- Return type
None
-
docker_containers: Dict[str, d3m.primitive_interfaces.base.DockerContainer][source]¶ A dict mapping Docker image keys from primitive’s metadata to (named) tuples containing container’s address under which the container is accessible by the primitive, and a dict mapping exposed ports to ports on that address.
-
logger: ClassVar[logging.Logger][source]¶ Primitive’s logger. Available as a class attribute. This gets automatically set to primitive’s logger in metaclass.
-
metadata: ClassVar[d3m.metadata.base.PrimitiveMetadata][source]¶ Primitive’s metadata. Available as a class attribute. Primitive author should provide all fields which cannot be determined automatically inside the code. In this way metadata is close to the code and it is easier for consumers to make sure metadata they are using is really matching the code they are using. PrimitiveMetadata class updates itself with metadata about code and other things it can extract automatically.
-
abstract
-
class
d3m.base.primitives.FileReaderPrimitiveBase(*, hyperparams)[source]¶ Bases:
d3m.primitive_interfaces.transformer.TransformerPrimitiveBase[[d3m.container.pandas.DataFrame,d3m.container.pandas.DataFrame],d3m.base.primitives.FileReaderHyperparams]A primitive base class for reading files referenced in columns.
Primitives using this base class must implement:
_supported_media_types: A sequence of supported media types such asaudio/mpeg,image/jpeg, etc._file_structural_type: Structural type of the file contents after being read such ascontainer.ndarray,container.DataFrame, etc._file_semantic_types: A sequence of semantic types to be applied to the produced column.metadata: Primitive Metadata._read_fileuri: The function which describes how to load each file. This function must load one file at the time.
-
produce(*, inputs, timeout=None, iterations=None)[source]¶ Produce primitive’s best choice of the output for each of the inputs.
The output value should be wrapped inside
CallResultobject before returning.In many cases producing an output is a quick operation in comparison with
fit, but not all cases are like that. For example, a primitive can start a potentially long optimization process to compute outputs.timeoutanditerationscan serve as a way for a caller to guide the length of this process.Ideally, a primitive should adapt its call to try to produce the best outputs possible inside the time allocated. If this is not possible and the primitive reaches the timeout before producing outputs, it should raise a
TimeoutErrorexception to signal that the call was unsuccessful in the given time. The state of the primitive after the exception should be as the method call has never happened and primitive should continue to operate normally. The purpose oftimeoutis to give opportunity to a primitive to cleanly manage its state instead of interrupting execution from outside. Maintaining stable internal state should have precedence over respecting thetimeout(caller can terminate the misbehaving primitive from outside anyway). If a longertimeoutwould produce different outputs, thenCallResult’shas_finishedshould be set toFalse.Some primitives have internal iterations (for example, optimization iterations). For those, caller can provide how many of primitive’s internal iterations should a primitive do before returning outputs. Primitives should make iterations as small as reasonable. If
iterationsisNone, then there is no limit on how many iterations the primitive should do and primitive should choose the best amount of iterations on its own (potentially controlled through hyper-parameters). Ifiterationsis a number, a primitive has to do those number of iterations, if possible.timeoutshould still be respected and potentially less iterations can be done because of that. Primitives with internal iterations should makeCallResultcontain correct values.For primitives which do not have internal iterations, any value of
iterationsmeans that they should run fully, respecting onlytimeout.If primitive should have been fitted before calling this method, but it has not been, primitive should raise a
PrimitiveNotFittedErrorexception.- Parameters
- Returns
The outputs of shape [num_inputs, …] wrapped inside
CallResult.- Return type
-
class
d3m.base.primitives.TabularSplitPrimitiveBase(*, hyperparams, random_seed=0)[source]¶ Bases:
d3m.base.primitives.DatasetSplitPrimitiveBase[d3m.base.primitives.TabularSplitPrimitiveParams,typing.Hyperparams]A primitive base class for splitting tabular datasets.
Primitives using this base class must implement:
_get_splits: The function which describes how to split the tabular dataset.
-
fit(*, timeout=None, iterations=None)[source]¶ This function computes everything in advance, including generating the relation graph.
- Parameters
- Returns
A
CallResultwithNonevalue.- Return type
CallResult[None]
-
fit_multi_produce(*, produce_methods, inputs, dataset, timeout=None, iterations=None)[source]¶ A method calling
fitand after that multiple produce methods at once.- Parameters
produce_methods (
Sequence[str]) – A list of names of produce methods to call.inputs (
List) – The inputs given to all produce methods.outputs – The outputs given to
set_training_data.timeout (
Optional[float]) – A maximum time this primitive should take to both fit the primitive and produce outputs for all produce methods listed inproduce_methodsargument, in seconds.iterations (
Optional[int]) – How many of internal iterations should the primitive do for both fitting and producing outputs of all produce methods.
- Returns
A dict of values for each produce method wrapped inside
MultiCallResult.- Return type
-
get_params()[source]¶ Returns parameters of this primitive.
Parameters are all parameters of the primitive which can potentially change during a life-time of a primitive. Parameters which cannot are passed through constructor.
Parameters should include all data which is necessary to create a new instance of this primitive behaving exactly the same as this instance, when the new instance is created by passing the same parameters to the class constructor and calling
set_params.No other arguments to the method are allowed (except for private arguments).
- Returns
An instance of parameters.
- Return type
TabularSplitPrimitiveParams
-
produce(*, inputs, timeout=None, iterations=None)[source]¶ For each input integer creates a
Datasetsplit and produces the trainingDatasetobject. ThisDatasetobject should then be used to fit (train) the pipeline.- Parameters
- Returns
The outputs of shape [num_inputs, …] wrapped inside
CallResult.- Return type
-
produce_score_data(*, inputs, timeout=None, iterations=None)[source]¶ For each input integer creates a
Datasetsplit and produces the scoringDatasetobject. ThisDatasetobject should then be used to test the pipeline and score the results.Output
Datasetobjects do not have targets redacted and are not directly suitable for testing.- Return type
-
set_params(*, params)[source]¶ Sets parameters of this primitive.
Parameters are all parameters of the primitive which can potentially change during a life-time of a primitive. Parameters which cannot are passed through constructor.
No other arguments to the method are allowed (except for private arguments).
- Parameters
params (
TabularSplitPrimitiveParams) – An instance of parameters.- Return type
None
-
set_training_data(*, dataset)[source]¶ Sets training data of this primitive, the
Datasetto split.- Parameters
dataset (
Dataset) – The dataset to split.- Return type
None
-
docker_containers: Dict[str, d3m.primitive_interfaces.base.DockerContainer][source]¶ A dict mapping Docker image keys from primitive’s metadata to (named) tuples containing container’s address under which the container is accessible by the primitive, and a dict mapping exposed ports to ports on that address.
-
logger: ClassVar[logging.Logger][source]¶ Primitive’s logger. Available as a class attribute. This gets automatically set to primitive’s logger in metaclass.
-
metadata: ClassVar[d3m.metadata.base.PrimitiveMetadata][source]¶ Primitive’s metadata. Available as a class attribute. Primitive author should provide all fields which cannot be determined automatically inside the code. In this way metadata is close to the code and it is easier for consumers to make sure metadata they are using is really matching the code they are using. PrimitiveMetadata class updates itself with metadata about code and other things it can extract automatically.