def test_joint_logp_subtensor(): """Make sure we can compute a log-likelihood for ``Y[I]`` where ``Y`` and ``I`` are random variables.""" size = 5 mu_base = floatX(np.power(10, np.arange(np.prod(size)))).reshape(size) mu = np.stack([mu_base, -mu_base]) sigma = 0.001 rng = aesara.shared(np.random.RandomState(232), borrow=True) A_rv = Normal.dist(mu, sigma, rng=rng) A_rv.name = "A" p = 0.5 I_rv = Bernoulli.dist(p, size=size, rng=rng) I_rv.name = "I" A_idx = A_rv[I_rv, at.ogrid[A_rv.shape[-1]:]] assert isinstance(A_idx.owner.op, (Subtensor, AdvancedSubtensor, AdvancedSubtensor1)) A_idx_value_var = A_idx.type() A_idx_value_var.name = "A_idx_value" I_value_var = I_rv.type() I_value_var.name = "I_value" A_idx_logps = joint_logp(A_idx, { A_idx: A_idx_value_var, I_rv: I_value_var }, sum=False) A_idx_logp = at.add(*A_idx_logps) logp_vals_fn = aesara.function([A_idx_value_var, I_value_var], A_idx_logp) # The compiled graph should not contain any `RandomVariables` assert_no_rvs(logp_vals_fn.maker.fgraph.outputs[0]) decimals = select_by_precision(float64=6, float32=4) for i in range(10): bern_sp = sp.bernoulli(p) I_value = bern_sp.rvs(size=size).astype(I_rv.dtype) norm_sp = sp.norm(mu[I_value, np.ogrid[mu.shape[1]:]], sigma) A_idx_value = norm_sp.rvs().astype(A_idx.dtype) exp_obs_logps = norm_sp.logpdf(A_idx_value) exp_obs_logps += bern_sp.logpmf(I_value) logp_vals = logp_vals_fn(A_idx_value, I_value) np.testing.assert_almost_equal(logp_vals, exp_obs_logps, decimal=decimals)
def throw_a_coin(n): brv = bernoulli(0.5) return brv.rvs(size=n)
top.optimize_with_DL_constraint() return "successfull" if __name__ == "__main__": print(os.cpu_count()) volfractions = norm(loc=0.3, scale=0.05).ppf(lhs(50, samples=1)).reshape( 50, ) #norm(loc=0.3, scale=0.1).ppf(lhs(50, samples=1)).reshape(50,) # this gives the x values having y-values equal to volume_fraction # rmins_1 = uniform(1.1, 2).ppf(lhs(50, samples=1)).reshape(50,) # 0.1 < volume fraction < 0.4 => 1.1 < Rmin < 3 ; Rmin suit la loi uniforme (1.1, 3 ) # rmins_2 = uniform(2, 3).ppf(lhs(50, samples=1)).reshape(50,) # 0.4 < volume fraction < 0.6 => 2 < Rmin < 3 ; Rmin suit la loi uniforme (2, 3 ) # rmins_3 = uniform(3, 4).ppf(lhs(50, samples=1)).reshape(50,) # volume fraction > 0.6 => 3 < Rmin < 4; Rmin suit la loi uniforme (3, 4 ) filters = bernoulli(0.5).ppf(lhs(50, samples=1)).reshape( 50, ) # either present (1) or absent (0) tetas = uniform(0, 180).ppf(lhs(100, samples=1)).reshape(100, ).tolist( ) #uniform(0, 60).ppf(lhs(30, samples=1)).reshape(30,).tolist()+ uniform(60, 130).ppf(lhs(30, samples=1)).reshape(30,).tolist() + uniform(130, 180).ppf(lhs(30, samples=1)).reshape(30,).tolist() nbr_loads = poisson(2).ppf(lhs(50, samples=1)).reshape( 50, ) # most probable nbr_loads is 2 windows = poisson(100).ppf(lhs(50, samples=1)).reshape(50, ) nx = 100 ny = 100 window = int(nx / 2) # possible_fixed_nodes = np.arange(0, ny + 1).tolist() + [ m * (ny + 1) - 1 for m in range(2, nx + 1) ] + np.sort(np.arange( (ny + 1) * nx, (nx + 1) * (ny + 1))).tolist()[::-1] + np.sort( np.asarray([m * (ny + 1) for m in range(1, nx)])).tolist()[::-1] total_nbr_samples = 100
def bernoulli(p): return dists.bernoulli(p)
def __init__(self, h=100, N=100): self.h = h self.N = N self.default = float(h) / N self.D = D.bernoulli(self.default)
def throw_a_coin(n): from scipy.stats.distributions import bernoulli brv = bernoulli(0.5) return brv.rvs(size=n)
def D(self): return D.bernoulli(self.default)
def __init__(self,h=100,N=100): self.h=h self.N=N self.default=float(h)/N self.D=D.bernoulli(self.default)