-
Notifications
You must be signed in to change notification settings - Fork 1
/
phase_transition.py
51 lines (46 loc) · 1.76 KB
/
phase_transition.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
"""Tools for assessing the recoverability phase transition."""
import dual_certificates
import functools
import numpy as np
def point_probability(support_fn, sign_pattern_fn, kernel, interpolation_fn,
num_experiments=10):
"""Estimates success probability for a single problem distribution."""
num_successes = 0
for _ in range(num_experiments):
support = support_fn()
if support is None:
# num_successes += 1
continue
sign_pattern = sign_pattern_fn()
interpolator = interpolation_fn(support, sign_pattern, kernel)
success = dual_certificates.validate(
support, sign_pattern, interpolator)['status']
if success:
num_successes += 1
return num_successes / float(num_experiments)
def grid_probabilities(
support_fn,
sign_pattern_fn,
kernel,
interpolation_fn,
num_support_points_grid,
minimum_separation_grid,
num_experiments=10,
verbose=False):
results = np.zeros(
(len(num_support_points_grid), len(minimum_separation_grid)))
for i, num_support_points in enumerate(num_support_points_grid):
for j, min_separation in enumerate(minimum_separation_grid):
if verbose:
print i, j
this_support_fn = functools.partial(
support_fn, num_support_points, min_separation=min_separation)
this_sign_pattern_fn = functools.partial(
sign_pattern_fn, num_support_points)
results[i, j] = point_probability(
this_support_fn,
this_sign_pattern_fn,
kernel,
interpolation_fn,
num_experiments=num_experiments)
return results