Skip to content

Latest commit

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ensemble

A model ensemble utility optimized for low barrier integration

TL;DR this lets you use one thing to call many things.

Model Ensemble

Examples

Define your model functions and create your ensemble:

>>>fromensembleimportEnsemble>>>defsquare(x):
... returnx**2
...
>>>defcube(y):
... returny**3
...
>>>my_ensemble=Ensemble(
... name='e1',
... children=[function1, function2],
... )

Multiplex between functions:

>>>my_ensemble(child='square', x=2)
4>>>my_ensemble(child='cube', y=2)
8

Call all the models in the ensemble:

>>>my_ensemble.all(x=2, y=2)
{'square': 4, 'cube': 8}

You may instead decorate your model functions with @model in order to attach them to an ensemble:

>>>fromensembleimportchild>>>@child('e2')
... deffunc1(x):
... returnx**2
...
>>>@child('e2')
... deffunc2(x):
... returnx**3
...
>>>e2=Ensemble('e2')
>>>e2.all(x=3)
{'func1': 9, 'func2': 27}

You may even attach a model to multiple ensembles! (this is one main reason ensemble is useful)

>>>@child('e2', 'e3')
... deffunc3(x, y):
... returnx**3+y
...
>>>e2.all(x=2, y=3)
{'func1': 4, 'func2': 8, 'func3': 11}
>>>>>>e3=Ensemble('e3')
>>>e3.all(x=2, y=3)
{'func3': 11}

If you forget what models are in your ensemble, just check:

>>>e2Ensemble(
name='e2',
children={
'func1': <functionfunc1at0x1024fa9d8>'func2': <functionfunc2at0x1024faa60>'func3': <functionfunc3at0x1024fa950>
},
weights=None,
)
>>>e3Ensemble(
name='e3',
children={
'func3': <functionfunc3at0x1024fa950>
},
weights=None,
)

In the above example, ensemble e2 contains func1, func2, and func3, while ensemble e3 contains just func3.

About

model ensemble utility optimized for low barrier integration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages