neurotools.stats.mcint module

Routines for monte-carlo integration

neurotools.stats.mcint.monte_carlo_expectation(f, maxiter=1000000, converge=0.01, verbose=False)[source]

x = monte_carlo_expectation(f,maxiter,converge)

Evaluate expectation of f using Monte-Carlo integration. For simplicit (for now), this casts the return value of f() to a float64 array Ensure the return value is compatible with this datatype. This uses the standard error of the mean to check for convergence. It converges slowly at 1/sqrt(n)

Example:

def f():
    x = randn(2)+array([9,-9])
    return x
Ex = monte_carlo_moments(f,verbose=1,maxiter=100000,converge=1e-2)
print('Ex:\n',Ex)
Parameters:
  • f – function that returns array_like.

  • maxiter – maximum number of samples to draw

  • converge – maximum absolute error tolerated

Returns:

Estimate of the mean of f

Return type:

number or array-like

neurotools.stats.mcint.monte_carlo_moments(f, maxiter=1000000, converge=0.01, verbose=False)[source]

x = monte_carlo_expectation(f,maxiter,converge)

Evaluate expectation of f using Monte-Carlo integration. For simplicit (for now), this casts the return value of f() to a float64 array Ensure the return value is compatible with this datatype. This uses the standard error of the mean to check for convergence. It converges very slowly (1/sqrt(n)), so don’t ask for too much precision.

Example:

def f():
    x = randn(2)+array([9,-9])
    return x
Ex,Exx = monte_carlo_moments(f,verbose=1,maxiter=100000,converge=1e-2)
print('Ex:\n',Ex)
print('Exx:\n',Exx)
Parameters:
  • f – function that returns array_like.

  • maxiter – maximum number of samples to draw

  • converge – maximum absolute error tolerated

Return type:

Estimate of the mean and second moment of f