Skip to content

BUG: Inaccuracy in logcdf with quadrature method #5

@JacobHass8

Description

@JacobHass8

I was working on writing more tests and the hypothesis library found this example where the logcdf method wasn't accurate with the quadrature method. Here is the script

import numpy as np
from normal import Normal

if __name__ == '__main__':
    arg = -0.55686482
    methods = ['formula', 'log/exp', 'quadrature']
    X = Normal(mu=0.904775196502295, sigma=1.3102019638947042)
    reference = np.exp(X.logcdf(arg))

    print("-------------------")
    for method in methods:
        result = np.exp(X.logcdf(arg, method=method))
        print(f"Method: {method}", "\n"
              "Absolute difference: ", np.abs(reference - result), "\n"
              "-------------------")

and the output is

-------------------
Method: formula 
Absolute difference:  0.0 
-------------------
Method: log/exp 
Absolute difference:  1.1102230246251565e-16 
-------------------
Method: quadrature 
Absolute difference:  1.3001154173353235e-05 
-------------------

The relative tolerance is currently set to 1e-7 so this doesn't pass. It's not as if this is in the tail so I don't understand why the accuracy isn't that great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions