コード例 #1
0
ファイル: binomial.py プロジェクト: buptpriswang/bayespy
 def __init__(self, N):
     if not misc.isinteger(N):
         raise ValueError("Number of trials must be integer")
     if np.any(N < 0):
         raise ValueError("Number of trials must be non-negative")
     self.N = np.asanyarray(N)
     super().__init__()
コード例 #2
0
ファイル: binomial.py プロジェクト: ik362/bayespy
 def __init__(self, N):
     N = np.asanyarray(N)
     if not misc.isinteger(N):
         raise ValueError("Number of trials must be integer")
     if np.any(N < 0):
         raise ValueError("Number of trials must be non-negative")
     self.N = np.asanyarray(N)
     super().__init__()
コード例 #3
0
ファイル: poisson.py プロジェクト: zackxconti/bayespy
 def compute_fixed_moments(self, x):
     """
     Compute the moments for a fixed value
     """
     # Make sure the values are integers in valid range
     x = np.asanyarray(x)
     if not misc.isinteger(x):
         raise ValueError("Count not integer")
     # Now, the moments are just the counts
     return [x]
コード例 #4
0
ファイル: poisson.py プロジェクト: agile-innovations/bayespy
 def compute_fixed_moments(self, x):
     """
     Compute the moments for a fixed value
     """
     # Make sure the values are integers in valid range
     x = np.asanyarray(x)
     if not misc.isinteger(x):
         raise ValueError("Count not integer")
     # Now, the moments are just the counts
     return [x]
コード例 #5
0
ファイル: multinomial.py プロジェクト: ifloripa/bayespy
    def __init__(self, trials):
        """
        Create VMP formula node for a multinomial variable

        `trials` is the total number of trials.
        """
        if not misc.isinteger(trials):
            raise ValueError("Number of trials must be integer")
        if np.any(trials < 0):
            raise ValueError("Number of trials must be non-negative")
        self.N = trials
        super().__init__()
コード例 #6
0
ファイル: multinomial.py プロジェクト: BayesianHuman/bayespy
    def __init__(self, trials):
        """
        Create VMP formula node for a multinomial variable

        `trials` is the total number of trials.
        """
        if not misc.isinteger(trials):
            raise ValueError("Number of trials must be integer")
        if np.any(trials < 0):
            raise ValueError("Number of trials must be non-negative")
        self.N = trials
        super().__init__()
コード例 #7
0
ファイル: binomial.py プロジェクト: ik362/bayespy
 def compute_fixed_moments_and_f(self, x, mask=True):
     """
     Compute the moments and :math:`f(x)` for a fixed value.
     """
     # Make sure the values are integers in valid range
     x = np.asanyarray(x)
     if not misc.isinteger(x):
         raise ValueError("Counts must be integer")
     if np.any(x < 0) or np.any(x > self.N):
         raise ValueError("Invalid count")
     # Now, the moments are just the counts
     u = [x]
     f = (special.gammaln(self.N + 1) - special.gammaln(x + 1) -
          special.gammaln(self.N - x + 1))
     return (u, f)
コード例 #8
0
ファイル: binomial.py プロジェクト: jamesmcinerney/bayespy
 def compute_fixed_moments_and_f(self, x, mask=True):
     """
     Compute the moments and :math:`f(x)` for a fixed value.
     """
     # Make sure the values are integers in valid range
     x = np.asanyarray(x)
     if not misc.isinteger(x):
         raise ValueError("Counts must be integer")
     if np.any(x < 0) or np.any(x > self.N):
         raise ValueError("Invalid count")
     # Now, the moments are just the counts
     u = [x]
     f = (special.gammaln(self.N+1) -
          special.gammaln(x+1) -
          special.gammaln(self.N-x+1))
     return (u, f)
コード例 #9
0
ファイル: multinomial.py プロジェクト: BayesianHuman/bayespy
    def compute_fixed_moments(self, x):
        """
        Compute the moments for a fixed value

        `x` must be a vector of counts.
        """

        # Check that counts are valid
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Counts must be integer")
        if np.any(x < 0):
            raise ValueError("Counts must be non-negative")

        # Moments is just the counts vector
        u0 = x.copy()
        return [u0]
コード例 #10
0
    def compute_fixed_moments(self, x):
        """
        Compute the moments for a fixed value
        """

        # Check that x is valid
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Values must be integers")
        if np.any(x < 0) or np.any(x >= self.categories):
            raise ValueError("Invalid category index")

        u0 = np.zeros((np.size(x), self.categories))
        u0[[np.arange(np.size(x)), np.ravel(x)]] = 1
        u0 = np.reshape(u0, np.shape(x) + (self.categories, ))

        return [u0]
コード例 #11
0
    def compute_fixed_moments(self, x):
        """
        Compute the moments for a fixed value

        `x` must be a vector of counts.
        """

        # Check that counts are valid
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Counts must be integer")
        if np.any(x < 0):
            raise ValueError("Counts must be non-negative")

        # Moments is just the counts vector
        u0 = x.copy()
        return [u0]
コード例 #12
0
ファイル: categorical.py プロジェクト: BayesianHuman/bayespy
    def compute_fixed_moments(self, x):
        """
        Compute the moments for a fixed value
        """

        # Check that x is valid
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Values must be integers")
        if np.any(x < 0) or np.any(x >= self.D):
            raise ValueError("Invalid category index")

        u0 = np.zeros((np.size(x), self.D))
        u0[[np.arange(np.size(x)), np.ravel(x)]] = 1
        u0 = np.reshape(u0, np.shape(x) + (self.D,))

        return [u0]
コード例 #13
0
ファイル: poisson.py プロジェクト: agile-innovations/bayespy
    def compute_fixed_moments_and_f(self, x, mask=True):
        """
        Compute the moments and :math:`f(x)` for a fixed value.
        """

        # Check the validity of x
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Values must be integers")
        if np.any(x < 0):
            raise ValueError("Values must be positive")

        # Compute moments
        u0 = np.copy(x)
        u = [u0]

        # Compute f(x)
        f = -special.gammaln(x+1)

        return (u, f)
コード例 #14
0
ファイル: poisson.py プロジェクト: zackxconti/bayespy
    def compute_fixed_moments_and_f(self, x, mask=True):
        """
        Compute the moments and :math:`f(x)` for a fixed value.
        """

        # Check the validity of x
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Values must be integers")
        if np.any(x < 0):
            raise ValueError("Values must be positive")

        # Compute moments
        u0 = np.copy(x)
        u = [u0]

        # Compute f(x)
        f = -special.gammaln(x+1)

        return (u, f)
コード例 #15
0
ファイル: multinomial.py プロジェクト: BayesianHuman/bayespy
    def compute_fixed_moments_and_f(self, x, mask=True):
        """
        Compute the moments and :math:`f(x)` for a fixed value.
        """

        # Check that counts are valid
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Counts must be integers")
        if np.any(x < 0):
            raise ValueError("Counts must be non-negative")
        if np.any(np.sum(x, axis=-1) != self.N):
            raise ValueError("Counts must sum to the number of trials")

        # Moments is just the counts vector
        u0 = x.copy()
        u = [u0]

        f = special.gammaln(self.N+1) - np.sum(special.gammaln(x+1), axis=-1)
        
        return (u, f)
コード例 #16
0
ファイル: multinomial.py プロジェクト: pfjob09/bayespy
    def compute_fixed_moments_and_f(self, x, mask=True):
        """
        Compute the moments and :math:`f(x)` for a fixed value.
        """

        # Check that counts are valid
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Counts must be integers")
        if np.any(x < 0):
            raise ValueError("Counts must be non-negative")
        if np.any(np.sum(x, axis=-1) != self.N):
            raise ValueError("Counts must sum to the number of trials")

        # Moments is just the counts vector
        u0 = x.copy()
        u = [u0]

        f = special.gammaln(self.N+1) - np.sum(special.gammaln(x+1), axis=-1)
        
        return (u, f)
コード例 #17
0
    def compute_fixed_moments_and_f(self, x, mask=True):
        """
        Compute the moments and :math:`f(x)` for a fixed value.
        """

        # Check the validity of x
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Values must be integers")
        if np.any(x < 0) or np.any(x >= self.D):
            raise ValueError("Invalid category index")

        # Form a binary matrix with only one non-zero (1) in the last axis
        u0 = np.zeros((np.size(x), self.D))
        u0[[np.arange(np.size(x)), np.ravel(x)]] = 1
        u0 = np.reshape(u0, np.shape(x) + (self.D, ))
        u = [u0]

        # f(x) is zero
        f = 0

        return (u, f)
コード例 #18
0
ファイル: logistic.py プロジェクト: BayesianHuman/bayespy
    def compute_fixed_moments_and_f(self, x, mask=True):
        """
        Compute the moments and :math:`f(x)` for a fixed value.
        """

        # Check the validity of x
        x = np.asanyarray(x)
        if not misc.isinteger(x):
            raise ValueError("Values must be integers")
        if np.any(x < 0) or np.any(x >= self.D):
            raise ValueError("Invalid category index")

        # Form a binary matrix with only one non-zero (1) in the last axis
        u0 = np.zeros((np.size(x), self.D))
        u0[[np.arange(np.size(x)), np.ravel(x)]] = 1
        u0 = np.reshape(u0, np.shape(x) + (self.D,))
        u = [u0]

        # f(x) is zero
        f = 0

        return (u, f)