brian-team / brian2modelfitting

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

[MRG] Temporal weighting #31

Closed mstimberg closed 4 years ago

mstimberg commented 4 years ago

This adds a simple temporal weighting factor to MSEMetric. Instead of t_start you can provide t_weights, a vector of values of the same size as the trace that gets multiplied with the error (i.e. scales the squared error in the case of MSEMetric ). For simplicity, it cannot be combined with t_start.

Closes #22

mstimberg commented 4 years ago

Somewhat forgot about this PR. @romainbrette, what do you think?

romainbrette commented 4 years ago

It runs, but does it apply also to refine?

mstimberg commented 4 years ago

It runs, but does it apply also to refine?

Oops, good catch! No it didn't, but now it does :)

romainbrette commented 4 years ago

What does the error correspond to now? mean(t_weight*error)?

mstimberg commented 4 years ago

What does the error correspond to now? mean(t_weight*error)?

Yes. I now realize that we should maybe make this clearer in the documentation. Weighting the first part of the trace as 0 or using t_start is similar, but it will not give the same result for the error – in the former case the error is considered 0 (but included in the mean) and in the latter it is simply ignored.

We could renormalize things by considering the total weight (so only the relative weights would matter)?

romainbrette commented 4 years ago

for example with something like t_weights = t_weights/(sum(t_weights)*dt) ?

romainbrette commented 4 years ago

En tout cas ça marche!

romainbrette commented 4 years ago

Ah non ça ne doit pas être exactement ça

romainbrette commented 4 years ago

(la normalisation je veux dire)

mstimberg commented 4 years ago

I guess

t_weights = len(t_weights)*t_weights/sum(t_weights)

would work?

romainbrette commented 4 years ago

yes that seems rights (ie t_weights/mean(weights)).

mstimberg commented 4 years ago

I implemented the normalization of the weights. This makes sure that using t_start generates the same error as using t_weights with zero for time points < t_start and any kind of constant value for the other time points. Currently, the weights weigh the squared error, or in other words the residual is weighted by the square root of the provided weight. Not sure whether this is the best approach, especially given that the normalization scales the residual and not the squared error.

mstimberg commented 4 years ago

Discussed with @romainbrette and decided that applying the weighting to the squared error is ok. After all, users will chose this value somewhat arbitrarily anyway. Going ahead with the merge.