Skip to content

Priors for the linear model mixing hyperparameter estimation

This class contains the priors developed for the hyperparameters of the mixing function for the first method, linear model mixing. This class can be expanded by the user to employ any other desired priors.

Priors

Source code in samba/priors.py
 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
class Priors:

    def __init__(self):

        r'''
        Prior class for the three mixing functions currently
        in the package -> logistic, cdf, and cosine. These are 
        found in the LMM() class. In future, users can input 
        these functions themselves for their choice of mixing 
        function and data set. 

        Example:
            Priors()

        Parameters:
            None.

        Returns:
            None.
        '''
        return None 


    def luniform(self, theta, a, b):

        r'''
        General uniform prior to be used to truncate the normal
        distributions used in the parameter priors. 

        Parameters:
            theta (float): The parameter in question.

            a (float): The lower cutoff of the uniform prior.

            b (float): The upper cutoff of the uniform prior.

        Returns:
            The value of the log uniform prior given the 
                value of the hyperparameter theta.
        '''

        if theta > a and theta < b:
            return 0.0
        else:
            return -np.inf


    def lpdf(self, params):

        r'''
        Log pdf of the priors for the parameters. Must be truncated
        for the sampler to walk in valid regions. 

        Parameters:
            params (numpy.ndarray): The hyperparameters of the 
                mixing function that are being estimated.

        Returns:
            The value of the total log pdf of the priors on the 
                hyperparameters.
        '''

        if isinstance(params, float) == True:
            params = np.array([params])

        if len(params) == 1:
            param_1 = self.luniform(params[0], 0.0, 1.0)

            return param_1

        if len(params) == 2:
            # param_1 = self.luniform(params[0], -20, 20) #0, 10
            # param_2 = self.luniform(params[1], -20, 20) #-50, 0
            param_1 = stats.norm.logpdf(params[0], 10.0, 2.0)
            param_2 = stats.norm.logpdf(params[1], -20.0, 10.0)

            return (param_1 + param_2)

        elif len(params) == 3:
            #g1 truncated between (0, 0.35) 
            g1 = self.luniform(params[0], 0.01, 0.3) + stats.norm.logpdf(params[0], 0.1, 0.05)   #0.1 for 2 v 2, #0.1 for 5 v 5

            #g3 truncated between (g1, 0.35)
            g3 = self.luniform(params[2], params[0], 0.55) + stats.norm.logpdf(params[2], 0.4, 0.05)   #0.4 for 2 v 2, #0.25 for 5 v 5

            #g2 truncated between (g3, 0.35)
            g2 = self.luniform(params[1], params[2], 0.8) + stats.norm.logpdf(params[1], 0.6, 0.05)  #0.6 for 2 v 2, #0.4 for 5 v 5

            return (g1 + g2 + g3)

        else:
            raise ValueError('The number of parameters does not match any available switching function.')

__init__()

Prior class for the three mixing functions currently in the package -> logistic, cdf, and cosine. These are found in the LMM() class. In future, users can input these functions themselves for their choice of mixing function and data set.

Example

Priors()

Returns:

Type Description

None.

Source code in samba/priors.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def __init__(self):

    r'''
    Prior class for the three mixing functions currently
    in the package -> logistic, cdf, and cosine. These are 
    found in the LMM() class. In future, users can input 
    these functions themselves for their choice of mixing 
    function and data set. 

    Example:
        Priors()

    Parameters:
        None.

    Returns:
        None.
    '''
    return None 

lpdf(params)

Log pdf of the priors for the parameters. Must be truncated for the sampler to walk in valid regions.

Parameters:

Name Type Description Default
params ndarray

The hyperparameters of the mixing function that are being estimated.

required

Returns:

Type Description

The value of the total log pdf of the priors on the hyperparameters.

Source code in samba/priors.py
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
def lpdf(self, params):

    r'''
    Log pdf of the priors for the parameters. Must be truncated
    for the sampler to walk in valid regions. 

    Parameters:
        params (numpy.ndarray): The hyperparameters of the 
            mixing function that are being estimated.

    Returns:
        The value of the total log pdf of the priors on the 
            hyperparameters.
    '''

    if isinstance(params, float) == True:
        params = np.array([params])

    if len(params) == 1:
        param_1 = self.luniform(params[0], 0.0, 1.0)

        return param_1

    if len(params) == 2:
        # param_1 = self.luniform(params[0], -20, 20) #0, 10
        # param_2 = self.luniform(params[1], -20, 20) #-50, 0
        param_1 = stats.norm.logpdf(params[0], 10.0, 2.0)
        param_2 = stats.norm.logpdf(params[1], -20.0, 10.0)

        return (param_1 + param_2)

    elif len(params) == 3:
        #g1 truncated between (0, 0.35) 
        g1 = self.luniform(params[0], 0.01, 0.3) + stats.norm.logpdf(params[0], 0.1, 0.05)   #0.1 for 2 v 2, #0.1 for 5 v 5

        #g3 truncated between (g1, 0.35)
        g3 = self.luniform(params[2], params[0], 0.55) + stats.norm.logpdf(params[2], 0.4, 0.05)   #0.4 for 2 v 2, #0.25 for 5 v 5

        #g2 truncated between (g3, 0.35)
        g2 = self.luniform(params[1], params[2], 0.8) + stats.norm.logpdf(params[1], 0.6, 0.05)  #0.6 for 2 v 2, #0.4 for 5 v 5

        return (g1 + g2 + g3)

    else:
        raise ValueError('The number of parameters does not match any available switching function.')

luniform(theta, a, b)

General uniform prior to be used to truncate the normal distributions used in the parameter priors.

Parameters:

Name Type Description Default
theta float

The parameter in question.

required
a float

The lower cutoff of the uniform prior.

required
b float

The upper cutoff of the uniform prior.

required

Returns:

Type Description

The value of the log uniform prior given the value of the hyperparameter theta.

Source code in samba/priors.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def luniform(self, theta, a, b):

    r'''
    General uniform prior to be used to truncate the normal
    distributions used in the parameter priors. 

    Parameters:
        theta (float): The parameter in question.

        a (float): The lower cutoff of the uniform prior.

        b (float): The upper cutoff of the uniform prior.

    Returns:
        The value of the log uniform prior given the 
            value of the hyperparameter theta.
    '''

    if theta > a and theta < b:
        return 0.0
    else:
        return -np.inf