skgpuppy.Utilities module

class skgpuppy.Utilities.cache_wrapper(func)

Bases: object

Wrapper to cache the function values

skgpuppy.Utilities.expected_value_monte_carlo(func, mu, Sigma_x, n=1000)
Parameters:
  • func – a function that expects an 1D np array
  • mu – the mean of a multivariate normal
  • Sigma_x – the cov of a multivariate nromal
  • n – the number of samples to use
Returns:

The expected value of func(x) * p_mvnorm(x|mu,Sigma_x)

skgpuppy.Utilities.integrate(func, bounds)

Converting the arguments to nquad style

Parameters:
  • func (function with parameter x (iterable of length n)) – function to integrate
  • bounds (iterable of pairs of length n) – bounds for the integration
Returns:

value of the integral

skgpuppy.Utilities.integrate_hermgauss(func, mean, sigma, order=1)

1-d Gauss-Hermite quadrature

Parameters:
  • func – lambda x: y (x: float)
  • mean – mean of normal weight function
  • sigma – standard dev of normal weight function
  • order – the order of the integration rule
Returns:

\(E[f(X)] (X \sim \mathcal{N}(\mu,\sigma^2)) = \int_{-\infty}^{\infty}f(x)p(x),\mathrm{d}x\) with p being the normal density

skgpuppy.Utilities.integrate_hermgauss_nd(func, mean, Sigma_x, order)

n-d Gauss-Hermite quadrature

Parameters:
  • func – lambda x: y (x: vector of floats)
  • mean – mean vector of normal weight function
  • Sigma_x – covariance matrix of normal weight function
  • order – the order of the integration rule
Returns:

\(E[f(X)] (X \sim \mathcal{N}(\mu,\sigma^2)) = \int_{-\infty}^{\infty}f(x)p(x),\mathrm{d}x\) with p being the normal density

skgpuppy.Utilities.minimize(func, theta_start, bounds=None, constr=[], method='all', fprime=None)
Parameters:
  • func – function to minimize
  • theta_start – start parameters
  • bounds – array of bounds. Each bound is a tuple (min,max)
  • constr – inequality constraints >= 0 as array of functions
  • method – all, tnc, l_bfgs_b, cobyla, slsqp, bfgs, powell, cg, simplex or list of some of them
  • fprime – gradient
Returns:

The theta with the minimal function value

Note

constr for cobyla, slsqp, bounds for tnc, l_bfgs_b, slsqp

skgpuppy.Utilities.mvnorm(x, mean, K)
Parameters:
  • x – input vector
  • mean – vector of means
  • K – Covariance Matrix
Returns:

density at x

skgpuppy.Utilities.norm(x, mean, sigma)

Density function of the normal distribution

Parameters:
  • x
  • mean
  • sigma
Returns:

density at x