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.

parameterstorch.Tensor | None

The trainable parameters of the model (read and write).

input_labelslist[str]

The name of all input parameters (readonly).

output_labelslist[str]

The name of all output parameters (readonly).

accuracydict[str, float]

For each output label, associate the standard deviation of the associated average error. This dictionary is constructed when the .fit 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.

parametersobject, optional

The learnable parameters for regressive models.

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.]])}
>>>