brian-team / brian2modelfitting

Model fitting toolbox for the Brian 2 simulator
https://brian2modelfitting.readthedocs.io
Other
14 stars 6 forks source link

Generalize `FeatureMetric` #48

Open mstimberg opened 3 years ago

mstimberg commented 3 years ago

Currently, users can provide FeatureMetric with a list of feature names known to eFEL. In addition to that functionality, it should be possible to hand over a function instead of a name to support arbitrary feature calculations not supported by eFEL.

akapet00 commented 3 years ago

I think we can think of this as solved.

Even though we do not provide feature extraction by using eFEL or some other library behind the scenes, the user can manually use eFEL or any other external library of choice to extract features.

See for example this simple code snippet:

dt = ...
eqs = ...
inferencer = Inferencer(dt=dt, model=eqs,
                        input=...,
                        output=...,
                        features={'v': [lambda x: x.mean(),
                                        lambda x: x.std(),
                                        lambda x: x.max()]},
                        method=...,
                        threshold=...,
                        refractory=...,
                        param_init=...)

what the user could do is to define additional function that will use any external library. Let's say that, for whatever the reason is, the potentially interesting feature to learn the posterior could be the sample entropy. The user would just have to import the library of choice that is able to compute this and wrap it inside the callable as follows: (Here I use antropy because of its user friendliness)

import antropy as ant

...

sample_entropy(x):
    return ant.sample_entropy(x)

...

dt = ...
eqs = ...
inferencer = Inferencer(dt=dt, model=eqs,
                        input=...,
                        output=...,
                        features={'v': [lambda x: x.mean(),
                                        lambda x: x.std(),
                                        lambda x: x.max()],
                                        sample_entropy},
                        method=...,
                        threshold=...,
                        refractory=...,
                        param_init=...)