def random(self, n: int, seed: int = None): if np.isnan(self.params): raise RuntimeError('Clayton copula parameter cannot be nan') u = random_uniform(n, self.dim, seed) if self.params - 1 < 1e-7: return random_uniform(n, self.dim, seed) if np.isclose(self.params, 1): return u alpha = 1 / self.params fr = skew_stable.rvs(alpha, beta=1, gamma=cospi2(alpha) ** self.params, pm=1, size=n) return self.psi(-np.log(u) / fr[:, None])
def random(self, n: int, seed: int = None) -> np.ndarray: theta = self._theta if np.isnan(theta): raise RuntimeError('Clayton copula parameter cannot be nan') if abs(theta) < 6.06e-6: # magic number return random_uniform(n, self.dim, seed) r = random_uniform(n, self.dim, seed) if self.dim == 2: r[:, 1] = (r[:, 0] ** (-theta) * (r[:, 1] ** (-theta / (theta + 1)) - 1) + 1) ** (-1 / theta) return r else: gam = rng.standard_gamma(1 / theta, n)[:, None] r = -np.log(r) / gam return self.psi(r)
def random(self, n: int, seed: int = None) -> np.ndarray: theta = self._theta if np.isnan(theta): raise RuntimeError('Clayton copula parameter cannot be nan') if abs(theta) < 1e-7: return random_uniform(n, self.dim, seed) r = random_uniform(n, self.dim, seed) if self.dim == 2: r[:, 1] = (r[:, 0]**(-theta) * (r[:, 1]**(-theta / (theta + 1)) - 1) + 1)**(-1 / theta) return r else: gam = rng.standard_gamma(1 / theta, n)[:, None] r = -np.log(r) / gam return self.psi(r)
def random(self, n: int, seed: int = None): u = random_uniform(n, self.dim, seed) if abs(self.params) < 1e-7: return u if self.dim == 2: v = u[:, 1] a = -abs(self.params) v = -1 / a * np.log1p(-v * np.expm1(-a) / (np.exp(-a * u[:, 0]) * (v - 1) - v)) u[:, 1] = 1 - v if self.params > 0 else v return u # alpha too large if log1mexp(self.params) == 0: return np.ones((n, self.dim)) fr = random_log_series_ln1p(-self.params, n)[:, None] return self.psi(-np.log(u) / fr)
def random(self, n: int, seed: int = None) -> np.ndarray: return random_uniform(n, self.dim, seed)
def random(self, n: int, seed: int = None): return random_uniform(n, self.dim, seed)