Ejemplo n.º 1
0
    def __init__(self, N, B,
                 mu=0.0, sigma=1.0,
                 mu_self=None, sigma_self=None,
                 **kwargs):
        super(_FixedWeightsMixin, self).__init__(N, B)
        self._mu = expand_scalar(mu, (N, N, B))
        self._sigma = expand_cov(mu, (N, N, B, B))

        if (mu_self is not None) and (sigma_self is not None):
            self._mu[np.arange(N), np.arange(N), :] = expand_scalar(mu_self, (N, B))
            self._sigma[np.arange(N), np.arange(N), :] = expand_cov(sigma_self, (N, B, B))
Ejemplo n.º 2
0
    def __init__(self, N, B,
                 mu_0=0.0, sigma_0=1.0, kappa_0=1.0, nu_0=3.0,
                 is_diagonal_weight_special=True,
                 **kwargs):
        super(_IndependentGaussianMixin, self).__init__(N, B)

        mu_0 = expand_scalar(mu_0, (B,))
        sigma_0 = expand_cov(sigma_0, (B,B))
        self._gaussian = Gaussian(mu_0=mu_0, sigma_0=sigma_0, kappa_0=kappa_0, nu_0=max(nu_0, B+2.))

        self.is_diagonal_weight_special = is_diagonal_weight_special
        if is_diagonal_weight_special:
            self._self_gaussian = \
                Gaussian(mu_0=mu_0, sigma_0=sigma_0, kappa_0=kappa_0, nu_0=nu_0)
Ejemplo n.º 3
0
    def __init__(self,
                 T,
                 N,
                 B,
                 mu=0.0,
                 sigma=0.001,
                 mu_self=None,
                 sigma_self=None,
                 **kwargs):
        super(_FixedWeightsMixin, self).__init__(T, N, B)
        self._mu = expand_scalar(mu, (N, T, N, B))
        self._sigma = expand_cov(sigma, (N, T, N, B, B))

        # initialize sigma
        self._sigma[0, :, 0, :, :] = 0.001
        self._sigma[1, :, 1, :, :] = 0.001
        self._sigma[1, :, 0, :, :] = 0.001
        self._sigma[0, :, 1, :, :] = 0.001

        if (mu_self is not None) and (sigma_self is not None):
            self._mu[np.arange(N), :,
                     np.arange(N), :] = expand_scalar(mu_self, (N, T, B))
            self._sigma[np.arange(N), :,
                        np.arange(N), :] = expand_cov(sigma_self, (N, T, B, B))
Ejemplo n.º 4
0
dim = 2
N = 10
r = 2 + 2 * (np.arange(N) // (N / 2.))
th = np.linspace(0, 4 * np.pi, N, endpoint=False)
x = r * np.cos(th)
y = r * np.sin(th)
L = np.hstack((x[:, None], y[:, None]))

# Weight model
W = np.zeros((N, N))
# Distance matrix
D = ((L[:, None, :] - L[None, :, :])**2).sum(2)
sig = np.exp(-D / 2)
Sig = np.tile(sig[:, :, None, None], (1, 1, 1, 1))

Mu = expand_scalar(0, (N, N, 1))

for n in range(N):
    for m in range(N):
        W[n, m] = npr.multivariate_normal(Mu[n, m], Sig[n, m])

# Adjacency model
fig, axs = plt.subplots(4, 5)
P = [0.1, 0.3, 0.5, 0.7]
i0 = 3

import pickle
sm = pickle.load(
    open('/Users/pillowlab/Dropbox/pyglm-master/Practices/model2.pkl', 'rb'))

A = 1 * (np.random.rand(N, N) < P[i0])
Ejemplo n.º 5
0
 def rho(self, value):
     self._rho = expand_scalar(value, (self.N,))
Ejemplo n.º 6
0
 def mu_b(self, value):
     self._mu_b = expand_scalar(value, (1,))
Ejemplo n.º 7
0
 def mu_w(self, value):
     N, B = self.N, self.B
     self._mu_w = expand_scalar(value, (N, B))
Ejemplo n.º 8
0
 def rho(self, value):
     self._rho = expand_scalar(value, (self.N, ))
Ejemplo n.º 9
0
 def mu_b(self, value):
     self._mu_b = expand_scalar(value, (1, ))
Ejemplo n.º 10
0
 def mu_w(self, value):
     N, B = self.N, self.B
     self._mu_w = expand_scalar(value, (N, B))
Ejemplo n.º 11
0
 def __init__(self, N, B, rho=0.5, rho_self=None, **kwargs):
     super(_FixedAdjacencyMixin, self).__init__(N, B)
     self._rho = expand_scalar(rho, (N, N))
     if rho_self is not None:
         self._rho[np.diag_indices(N)] = rho_self