Code Monkey home page Code Monkey logo

Comments (2)

gdaiha avatar gdaiha commented on May 27, 2024

Analyzing better how _safe_norm_ppf was built, I think the only needed fix that we could do was to remove the outside loop and only pass:

_safe_norm_ppf(1 - alpha / 2, loc=self.point_estimate, scale=self.stderr), _safe_norm_ppf(alpha / 2, loc=self.point_estimate, scale=self.stderr)

A simple simulation between the two methods:

import scipy
import timeit
import numpy as np

from time import perf_counter
from contextlib import contextmanager

size = 10000

@contextmanager
def catchtime() -> float:
    start = perf_counter()
    yield lambda: perf_counter() - start
    print(f'Time: {perf_counter() - start:.3f} seconds')

loc_array = np.random.normal(loc=0, scale=0.1, size=size)
scale_array = np.abs(np.random.normal(loc=0, scale=0.001, size=size))

print('Method without loop')
with catchtime() as t:
  a = scipy.stats.norm.ppf(q=0.05, loc=loc_array, scale=scale_array), scipy.stats.norm.ppf(q=0.95, loc=loc_array, scale=scale_array)

print(a)

print('Method with loop')
with catchtime() as t:
  b = np.array([scipy.stats.norm.ppf(q=0.05, loc=loc, scale=scale) for loc, scale in zip(loc_array, scale_array)]), np.array([scipy.stats.norm.ppf(q=0.95, loc=loc, scale=scale) for loc, scale in zip(loc_array, scale_array)])

print(b)

That prints:

Method without loop

Time: 0.003 seconds

(array([ 0.05063444, -0.00281694, 0.09580098, ..., -0.0103138 ,
0.05915183, 0.09202236]), array([ 0.05225244, -0.00042525, 0.09687321, ..., -0.00561028,
0.06531339, 0.0939663 ]))

Method with loop

Time: 2.423 seconds

(array([ 0.05063444, -0.00281694, 0.09580098, ..., -0.0103138 ,
0.05915183, 0.09202236]), array([ 0.05225244, -0.00042525, 0.09687321, ..., -0.00561028,
0.06531339, 0.0939663 ]))

[ 0.05063444 -0.00281694 0.09580098 ... -0.0103138 0.05915183
0.09202236]

from econml.

gdaiha avatar gdaiha commented on May 27, 2024

Issue solved by #879

from econml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.