-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexample.py
57 lines (49 loc) · 1.33 KB
/
example.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import funs.util as util
import funs.engine as engine
import matplotlib.pyplot as plt
import numpy as np
# Initialize random number generator
np.random.seed(123)
# Specify dataset & fitting parameters
xdim = 2
ydim = 20
numTrials = 5
trialDur = 1000 # in ms
binSize = 20 # in ms
maxEMiter = 100
dOffset = 1 # controls firing rate
# Sample from the model (make a toy dataset)
training_set = util.dataset(
seed = np.random.randint(10000),
xdim = xdim,
ydim = ydim,
numTrials = numTrials,
trialDur = trialDur,
binSize = binSize,
dOffset = dOffset,
fixTau = True,
fixedTau = np.linspace(0.1,0.5,xdim),
drawSameX = True)
# Initialize parameters using Poisson-PCA
initParams = util.initializeParams(xdim, ydim, training_set)
# Fit using vanilla (batch) EM
fitBatch = engine.PPGPFAfit(
experiment = training_set,
initParams = initParams,
inferenceMethod = 'laplace',
EMmode = 'Batch',
maxEMiter = maxEMiter)
# Fit using online EM
fitOnline = engine.PPGPFAfit(
experiment = training_set,
initParams = initParams,
EMmode = 'Online',
maxEMiter = maxEMiter,
inferenceMethod = 'laplace',
batchSize = 5)
# Make plots
training_set.plotTrajectory();plt.show()
fitBatch.plotParamSeq()
fitOnline.plotParamSeq();plt.show()
fitBatch.plotTrajectory()
fitOnline.plotTrajectory();plt.show()