mendevi.models.solver.Solver

class mendevi.models.solver.Solver(model: Model, loss: Callable, grid: dict[str, list] | None = None)[source]

Minimizes a metric for a given model.

Performs a grid search on all free parameters.

Examples

>>> import cutcutcodec
>>> from mendevi.models import Solver
>>> from mendevi.models.lr import EncodeLinear
>>> model = EncodeLinear().fit("x264_vs_openh264.db", table="t_enc_encode")
>>> solver = Solver(model, lambda **kwd: kwd["log_energy_per_frame"] + (kwd["psnr"]-35)**2)
>>> video = cutcutcodec.utils.get_project_root() / "media" / "video" / "intro.webm"
>>> values, loss = solver.solve(video, encoder=["libopenh264", "libx264"])
>>>

Prepare the solver.

Parameters

modelmendevi.models.base.Model

The instantiated and fitted model, ready to be evaluated.

losscallable

The cost function, which takes the value of the labels as input and returns a scalar.

griddict[str, list], optional

Allows you to define the list of values to be tested. It is a dictionary that for each input label, associate the values to be tested.

solve(video: Path | str | None = None, **kwargs: dict[str]) tuple[dict[str, list], list[float]][source]

Test all combinations as a cartesian product.

Parameters

videopathlike, optional

Use this to extract the missing parameters.

**kwargsdict, optional

Use to define or redefine certain input parameters to be explored. Explore the cartesian product of all the values.

Returns

valuesdict[str, list]

Associate the list of provided and predicted values with each label, input and output.

losslist[float]

The value of the stroke function for each point. This list is sorted in ascending order.