-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmallows_model.py
More file actions
57 lines (52 loc) · 1.7 KB
/
Copy pathmallows_model.py
File metadata and controls
57 lines (52 loc) · 1.7 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
import numpy as np
import mallows_kendall as mk
import mallows_hamming as mh
def check_theta_phi(theta, phi):
"""This function automatically converts theta to phi or phi to theta as
list or float depending on the values and value types given as input.
Parameters
----------
theta: float or list
Dispersion parameter theta to convert to phi (can be None)
phi: float or list
Dispersion parameter phi to convert to theta (can be None)
Returns
-------
tuple
tuple containing both theta and phi (of list or float type depending on the input type)
"""
if not ((phi is None) ^ (theta is None)):
print("Set valid values for phi or theta")
if phi is None and type(theta)!=list:
phi = theta_to_phi(theta)
if theta is None and type(phi)!=list:
theta = phi_to_theta(phi)
if phi is None and type(theta)==list:
phi = [theta_to_phi(t) for t in theta]
if theta is None and type(phi)==list:
theta = [phi_to_theta(p) for p in phi]
return np.array(theta), np.array(phi)
def theta_to_phi(theta):
""" This functions converts theta dispersion parameter into phi
Parameters
----------
theta: float
Real dispersion parameter
Returns
-------
float
phi real dispersion parameter
"""
return np.exp(-theta)
def phi_to_theta(phi):
"""This functions converts phi dispersion parameter into theta
Parameters
----------
phi: float
Real dispersion parameter
Returns
-------
float
theta real dispersion parameter
"""
return -np.log(phi)