/
launchers_profile.py
82 lines (60 loc) · 2.65 KB
/
launchers_profile.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# encoding: utf-8
"""
launchers_profile.py
Created by Loic Matthey on 2012-10-10
Copyright (c) 2012 . All rights reserved.
"""
# import matplotlib.pyplot as plt
from datagenerator import *
from randomfactorialnetwork import *
from statisticsmeasurer import *
from slicesampler import *
from utils import *
from dataio import *
# from gibbs_sampler_continuous_fullcollapsed_randomfactorialnetwork import *
def launcher_profile_me(args):
print "-------- Profiling ----------"
import cProfile
import pstats
cProfile.runctx('profiling_run()', globals(), locals(), filename='profile_sampler.stats')
stat = pstats.Stats('profile_sampler.stats')
stat.strip_dirs().sort_stats('cumulative').print_stats()
return {}
def launcher_profiling_run(args):
N = 100
T = 2
# D = 64
M = 128
R = 2
# random_network = RandomNetwork.create_instance_uniform(K, M, D=D, R=R, W_type='identity', W_parameters=[0.2, 0.7])
# data_gen = DataGenerator(N, T, random_network, type_Z='discrete', weighting_alpha=0.6, weight_prior='recency', sigma_y = 0.02)
# sampler = Sampler(data_gen, dirichlet_alpha=0.5/K, sigma_to_sample=True, sigma_alpha=3, sigma_beta=0.5)
#
# (log_y, log_z, log_joint) = sampler.run(10, verbose=True)
N = args.N
T = args.T
# K = args.K
M = args.M
R = args.R
# num_samples = args.num_samples
# weighting_alpha = args.alpha
# Build the random network
sigma_y = 0.02
sigma_x = 0.1
time_weights_parameters = dict(weighting_alpha=0.9, weighting_beta=1.0, specific_weighting=0.1, weight_prior='uniform')
cued_feature_time = T-1
random_network = RandomFactorialNetwork.create_full_conjunctive(M, R=R)
# random_network = RandomFactorialNetwork.create_full_features(M, R=R, sigma=sigma_x)
# random_network = RandomFactorialNetwork.create_mixed(M, R=R, sigma=sigma_x, ratio_feature_conjunctive=0.2)
# Construct the real dataset
print "Building the database"
data_gen = DataGeneratorRFN(N, T, random_network, sigma_y=sigma_y, time_weights_parameters=time_weights_parameters, cued_feature_time=cued_feature_time, sigma_x=sigma_x)
# Measure the noise structure
print "Measuring noise structure"
data_gen_noise = DataGeneratorRFN(3000, T, random_network, sigma_y=sigma_y, time_weights_parameters=time_weights_parameters, cued_feature_time=cued_feature_time)
stat_meas = StatisticsMeasurer(data_gen_noise)
# stat_meas = StatisticsMeasurer(data_gen)
print "Sampling..."
sampler = Sampler(data_gen, n_parameters=stat_meas.model_parameters, tc=cued_feature_time)
sampler.plot_likelihood(sample=True, num_samples=1000)