lucasmaystre / choix

Inference algorithms for models based on Luce's choice axiom
MIT License
163 stars 28 forks source link

add minimum exponent to _safe_exp #26

Closed fohrloop closed 2 days ago

fohrloop commented 1 week ago

Fixes: https://github.com/lucasmaystre/choix/issues/25

Alternative would be to disallow z reaching zero. Like this:

    def hessian(self, params):
        hess = 2 * self._penalty * np.identity(len(params))
        for win, los in self._data:
            z = _safe_exp(params[win] - params[los]) or math.exp(-500) # this changed
            val =  1 / (1/z + 2 + z)
            hess[(win,los),(los,win)] += -val
            hess[(win,los),(win,los)] += +val
        return hess

Let me know what you think.

lucasmaystre commented 2 days ago

I like your suggested fix to _safe_exp, will merge. Thanks!