mendevi.models.base

Unify all the models with a common sctucture.

Classes

MetaModel(name, bases, namespace, /, **kwargs)

Relax somes+ constraints on few methods.

Model(*args, **kwargs)

Common structure to all models.

Functions

from_torch(data)

Back convertion from vectorized torch to python list, bijection of to_torch().

to_torch(data[, dtype])

Convert the fields into a tensor compatible encoding.

Details

class mendevi.models.base.MetaModel(name, bases, namespace, /, **kwargs)[source]

Relax somes+ constraints on few methods.

see https://github.com/python/cpython/blob/main/Lib/_py_abc.py and https://github.com/python/cpython/blob/main/Lib/abc.py

class mendevi.models.base.Model(*args: tuple, **kwargs: dict)[source]

Common structure to all models.

Attributes

citestr

The latex bibtext model citation.

parameterstuple[tuple[str], dict[tuple, object]] | None

The fitted parameters of the trainable model (readonly).

aggregationlist[str]

The labels that divide clusterers (readonly).

input_labelslist[str]

The name of all input parameters (readonly).

input_labels_aggreglist[str]

The subset of input_label that does not contain the aggregation values (readonly).

output_labelslist[str]

The name of all output parameters (readonly).

accuracydict[str, dict]

For each cluster name, associate for each output label, the predicted and validation data. This dictionary is builded / overwitten when the .validate method is called (readonly).

Initialise the model.

Parameters

titlestr, optional

The model title.

**kwargsdict

Includes the following fields.

sourcesstr

All sources for the model, the conference paper, the authors, etc.

input_labelslist[str]

The name of all input parameters. The possibles values are mendevi.plot.axis.Name.

output_labelslist[str]

The name of all output parameters. The possibles values are mendevi.plot.axis.Name.

aggregationlist[str]

Specifies the list of parameters that the model will not interpolate. By default, this list consists of the subset of discrete parameters from input_labels. For example, if you provide an empty list, a single instance of the model will be trained on all parameters.

mendevi.models.base.from_torch(data: dict[str, Tensor]) dict[str, list][source]

Back convertion from vectorized torch to python list, bijection of to_torch().

mendevi.models.base.to_torch(data: dict[str, list], dtype: dtype = torch.float32) dict[str, Tensor][source]

Convert the fields into a tensor compatible encoding.

Allows you to cast lists of numbers into floating point vectors. Labels are encoded as one-hot.

Returns

dict[str, torch.Tensor]

For each starting field, associate the torch matrix of size (n, k), where n is the number of elements and k is the dimension. k is 1 for lists of numbers and is the cardinality of the number of labels otherwise.

Examples

>>> from pprint import pprint
>>> from mendevi.models.base import to_torch
>>> data = {
...     "effort": ["fast", "medium", "slow"],
...     "encoder": ["libx264", "libsvtav1"],
...     "profile": ["sd", "hd", "fhd"],
...     "scalar": [0.0, 1.0, 2.0],
... }
>>> pprint(to_torch(data))
{'effort': tensor([[1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.]]),
 'encoder': tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.]]),
 'profile': tensor([[0., 0., 1., 0.],
        [0., 1., 0., 0.],
        [1., 0., 0., 0.]]),
 'scalar': tensor([[0.],
        [1.],
        [2.]])}
>>>