jrbourbeau / pyunfold

Iterative unfolding for Python
https://jrbourbeau.github.io/pyunfold/
MIT License
26 stars 13 forks source link

Bug in Bayes factor test statistic #92

Closed fzeiser closed 6 years ago

fzeiser commented 6 years ago

When using the Bayes factor test statistic, selected via (see also #91) [otherwise just using the code from the tutorial]

unfolded_results_BF = iterative_unfold(data=data_observed,
                                    data_err=data_observed_err,
                                    response=response,
                                    response_err=response_err,
                                    efficiencies=efficiencies,
                                    efficiencies_err=efficiencies_err,
                                    ts='bf',
                                    ts_stopping=0.01,
                                    callbacks=[Logger()])

I receive following error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-48-29a3ae55821e> in <module>()
     35                                     ts='bf',
     36                                     ts_stopping=0.01,
---> 37                                     callbacks=[Logger()])

/usr/local/lib/python3.5/dist-packages/pyunfold/unfold.py in iterative_unfold(data, data_err, response, response_err, efficiencies, efficiencies_err, prior, ts, ts_stopping, max_iter, cov_type, return_iterations, callbacks)
    160                               ts_func=ts_func,
    161                               max_iter=max_iter,
--> 162                               callbacks=callbacks)
    163 
    164     if return_iterations:

/usr/local/lib/python3.5/dist-packages/pyunfold/unfold.py in _unfold(prior, mixer, ts_func, max_iter, callbacks)
    215             status['unfolded'] = unfolded_n_c
    216 
--> 217         ts_iter = ts_func.calc(unfolded_n_c, current_n_c)
    218         status['ts_iter'] = ts_iter
    219         status['ts_stopping'] = ts_func.tol

/usr/local/lib/python3.5/dist-packages/pyunfold/teststat.py in calc(self, dist1, dist2)
    159             lnB += lgamma(dist1[i]+1) + lgamma(dist2[i]+1) - lgamma(dist1[i]+dist2[i]+2)
    160 
--> 161         self.SetStat(lnB)
    162         self.stat = lnB
    163 

AttributeError: 'BF' object has no attribute 'SetStat'

I assume this is either a bug, or I would need to pass some additional information. If so, I would appreciate if the docstring to the function could be a little more informative: https://github.com/jrbourbeau/pyunfold/blob/b329820754905fcd14f2be33b13bfbc20fe1cf44/pyunfold/teststat.py#L121-L133

jrbourbeau commented 6 years ago

Thanks for reporting this @fzeiser, this is indeed a bug! The SetStat method was an older method that has been removed from the codebase, but I clearly missed a reference to it in the BF.calc method. I've opened up a fix in #93.