-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_combined_analysis.py
More file actions
174 lines (142 loc) · 3.79 KB
/
test_combined_analysis.py
File metadata and controls
174 lines (142 loc) · 3.79 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import pytest
import autofit as af
from autofit import AbstractPaths, DirectoryPaths, AbstractPriorModel
from autofit.non_linear.paths.null import NullPaths
from autofit.non_linear.paths.sub_directory_paths import SubDirectoryPaths
def test_make_result():
model = af.Model(af.ex.Gaussian)
factor_graph_model = af.FactorGraphModel(
af.AnalysisFactor(
model,
af.Analysis(),
)
)
result = factor_graph_model.make_result(
samples_summary=af.SamplesSummary(
max_log_likelihood_sample=af.Sample(
0,
0,
0,
kwargs={
("0", "centre"): 1.0,
("0", "normalization"): 1.0,
("0", "sigma"): 1.0,
},
),
model=af.Collection(model),
),
paths=NullPaths(),
)
assert len(result.child_results) == 1
assert isinstance(result.model, af.Collection)
(child_result,) = result.child_results
assert child_result.model == model
class MockAnalysis(af.Analysis):
def __init__(self):
super().__init__()
calls = []
self.calls = calls
class Visualizer(af.Visualizer):
@staticmethod
def visualize_before_fit(
analysis,
paths: SubDirectoryPaths,
model: AbstractPriorModel,
):
calls.append(("visualize_before_fit", paths.analysis_name))
@staticmethod
def visualize(
analysis,
paths: SubDirectoryPaths,
instance,
during_analysis,
):
calls.append(
(
"visualize",
paths.analysis_name,
during_analysis,
)
)
self.Visualizer = Visualizer
def log_likelihood_function(self, instance):
return 0.0
def save_attributes(self, paths: SubDirectoryPaths):
self.calls.append(("save_attributes", paths.analysis_name))
def save_results(self, paths: SubDirectoryPaths, result):
self.calls.append(("save_results", paths.analysis_name))
@pytest.fixture
def analysis():
return MockAnalysis()
@pytest.fixture
def model():
return af.Model(af.ex.Gaussian)
@pytest.fixture
def factor_graph(analysis, model):
return af.FactorGraphModel(
af.AnalysisFactor(
prior_model=model,
analysis=analysis,
)
)
@pytest.fixture
def instance(model):
return af.Collection(model).instance_from_prior_medians()
@pytest.mark.parametrize(
"during_analysis",
[True, False],
)
def test_visualize(
analysis,
factor_graph,
instance,
during_analysis,
):
factor_graph.visualize(
DirectoryPaths(),
instance,
during_analysis,
)
assert analysis.calls == [
(
"visualize",
"analyses/analysis_0",
during_analysis,
),
]
def test_visualize_before_fit(
analysis,
factor_graph,
instance,
model,
):
factor_graph.visualize_before_fit(
DirectoryPaths(),
af.Collection(model),
)
assert analysis.calls == [
("visualize_before_fit", "analyses/analysis_0"),
]
def test_save_attributes(
analysis,
factor_graph,
instance,
):
factor_graph.save_attributes(
DirectoryPaths(),
)
assert analysis.calls == [
("save_attributes", "analyses/analysis_0"),
]
def test_save_results(
analysis,
factor_graph,
instance,
):
factor_graph.save_results(
DirectoryPaths(),
[None],
)
assert analysis.calls == [
("save_results", "analyses/analysis_0"),
]