-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths1_simulate.py
52 lines (39 loc) · 1.27 KB
/
s1_simulate.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
# Standard library imports
import timeit
# Third party imports
import numpy as np
# Local application imports
from data.generation import generate_data
from vi.cavi import coordinates_ascent
from vi import postprocessing as pp
from s1_config import Params
# random seed for testing purposes
np.random.seed(255)
# load parameters
params = Params()
# generate data
data_dict = generate_data(params)
if params.include_noise == False:
data = data_dict["Datapoints"]
else:
data = data_dict["Noisy Datapoints"]
# start timer
t_0 = timeit.default_timer()
# CAVI
elbo_final, tau, gamma, phi = coordinates_ascent(data_dict, params)
# end timer
# end timer and compute elapsed time
t_1 = timeit.default_timer()
runtime = t_1 - t_0
# postprocessing
results, results_reduced =\
pp.full_postprocessing(data_dict, phi, gamma, tau, False)
# plots
title = "Clustering DPM - MMSE Mean"
indicatorArray = results_reduced["Estimated Cluster Indicators"]
meanArray = results_reduced["Estimated Cluster Means"]
pp.plot_clustering(data, title, indicatorArray, meanArray)
title = "Clustering DPM - Cluster Sample Mean"
indicatorArray = results_reduced["Estimated Cluster Indicators"]
meanArray = results_reduced["Sample Mean of Clusters" ]
pp.plot_clustering(data, title, indicatorArray, meanArray)