-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistribution_discovery.py
44 lines (26 loc) · 999 Bytes
/
distribution_discovery.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
#!/usr/bin/env python
from __future__ import print_function
import numpy as np
def grad_norm(array, norm='l1'):
grad = np.gradient(array)
if norm == 'l1':
integrand = np.absolute(grad)
elif norm == 'l_infty':
integrand = np.max(np.absolute(grad))
else:
print('Using l2 norm')
integrand = np.square(grad)
return np.sum( integrand )
def choose_distribution(*dists, **kwargs):
"""! Chooses a distribution for a model based on the test outlined in Dewhurst et al. 2018
@param dists (list): list of distributions to check. These are intended to be generated by
the diffusion transform action on a the particular model.
Optional parameters
@kwarg norm (str): the type of norm to use. Should be one of 'l1', 'l2', or 'l_infty'.
"""
norm = kwargs.get('norm', 'l1')
vals = {}
for dist in dists:
test_val = grad_norm(dist, norm=norm)
vals[f.__name__] = test_val
return vals