def mom_call(self, k, dist): "Moment generator call backend wrapper" assert len(k) == len(dist) graph = self.graph self.dist, dist_ = dist, self.dist graph.add_node(dist, key=k) if hasattr(dist, "_mom"): if dist.advance: out = dist._mom(k, self) else: out = np.empty(k.shape[1:]) prm = self.D.build() prm.update(self.K.build()) out[:] = dist._mom(k, **prm) else: out = mom(dist, k, **self.meta) graph.add_node(dist, val=out) self.dist = dist_ return np.array(out)
def mom(self, K, **kws): """Raw statistical moments. Creates non-centralized raw moments from the random variable. If analytical options can not be utilized, Monte Carlo integration will be used. Parameters ---------- K : array_like Index of the raw moments. k.shape must be compatible with distribution shape. Sampling scheme when performing Monte Carlo rule : str rule for estimating the moment if the analytical method fails. Key Monte Carlo schemes --- ------------------------ "H" Halton sequence "K" Korobov set "L" Latin hypercube sampling "M" Hammersley sequence "R" (Pseudo-)Random sampling "S" Sobol sequence Key Quadrature schemes --- ------------------------ "C" Clenshaw-Curtis "Q" Gaussian quadrature "E" Gauss-Legendre composit : int, array_like optional If provided, composit quadrature will be used. Ignored in the case if gaussian=True. If int provided, determines number of even domain splits If array of ints, determines number of even domain splits along each axis If array of arrays/floats, determines location of splits antithetic : array_like, optional List of bool. Represents the axes to mirror using antithetic variable during MCI. Returns ------- out : ndarray Shapes are related through the identity k.shape==dist.shape+k.shape """ K = np.array(K, dtype=int) shape = K.shape dim = len(self) if dim > 1: shape = shape[1:] size = K.size / dim K = K.reshape(dim, size) try: out, G = self.G.run(K, "mom", **kws) except NotImplementedError: out = mom(self, K, **kws) return out.reshape(shape)
def mom(self, K, **kws): """Raw statistical moments. Creates non-centralized raw moments from the random variable. If analytical options can not be utilized, Monte Carlo integration will be used. Parameters ---------- K : array_like Index of the raw moments. k.shape must be compatible with distribution shape. Sampling scheme when performing Monte Carlo rule : str rule for estimating the moment if the analytical method fails. Key Monte Carlo schemes --- ------------------------ "H" Halton sequence "K" Korobov set "L" Latin hypercube sampling "M" Hammersley sequence "R" (Pseudo-)Random sampling "S" Sobol sequence Key Quadrature schemes --- ------------------------ "C" Clenshaw-Curtis "Q" Gaussian quadrature "E" Gauss-Legendre composit : int, array_like optional If provided, composit quadrature will be used. Ignored in the case if gaussian=True. If int provided, determines number of even domain splits If array of ints, determines number of even domain splits along each axis If array of arrays/floats, determines location of splits antithetic : array_like, optional List of bool. Represents the axes to mirror using antithetic variable during MCI. Returns ------- out : ndarray Shapes are related through the identity k.shape==dist.shape+k.shape """ K = np.array(K, dtype=int) shape = K.shape dim = len(self) if dim>1: shape = shape[1:] size = K.size/dim K = K.reshape(dim, size) try: out, G = self.G.run(K, "mom", **kws) except NotImplementedError: out = mom(self, K, **kws) return out.reshape(shape)