-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
36 lines (24 loc) · 1005 Bytes
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
import torch
from torch import nn
from torch.distributions.multivariate_normal import MultivariateNormal
class PoissonGp():
def __init__(self, T, W, sigma):
self.T = T
self.W = W
self.sigma = sigma
def CovarianceFunction(self, t1, t2, k):
result = torch.exp(-1*((t1-t2)**2)/(2*(self.sigma[k]**2)))
return result
def CovarianceMatrix(self, k):
Matrix = torch.ones((self.T, self.T))
for i in range(self.T):
for j in range(self.T):
Matrix[i][j] = self.CovarianceFunction(i, j, k)
return Matrix
def Data(self):
X = torch.stack([MultivariateNormal(torch.zeros(100), self.CovarianceMatrix(i)).sample() for i in range(self.p)])
C = torch.matmul(self.W, X)
C = torch.exp(C)
Y = torch.poisson(C)
return Y