# Path: distributions/dbg/random.py
# def score_student_t(x, nu, mu, sigma):
#     """
#     multivariate score_student_t
# 
#     \cite{murphy2007conjugate}, Eq. 313
#     """
#     p = len(mu)
#     z = x - mu
#     S = inner(inner(z, inv(sigma)), z)
#     score = (
#         gammaln(0.5 * (nu + p))
#         - gammaln(0.5 * nu)
#         - 0.5 * (
#             p * log(nu * pi)
#             + log(det(sigma))
#             + (nu + p) * log(1 + S / nu)
#         )
#     )
#     return score
# 
# def sample_normal_inverse_wishart(mu0, lambda0, psi0, nu0):
#     D, = mu0.shape
#     assert psi0.shape == (D, D)
#     assert lambda0 > 0.0
#     assert nu0 > D - 1
#     cov = sample_inverse_wishart(nu0, psi0)
#     mu = np.random.multivariate_normal(mean=mu0, cov=(1. / lambda0) * cov)
#     return mu, cov


import numpy as np
import math
from scipy.special import multigammaln
from distributions.dbg.random import (
    score_student_t,
    sample_normal_inverse_wishart,
)
from distributions.mixins import SharedMixin, GroupIoMixin, SharedIoMixin
#
# - Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
# - Neither the name of Salesforce.com nor the names of its contributors
#   may be used to endorse or promote products derived from this
#   software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE



NAME = 'NormalInverseWishart'
EXAMPLES = [
    {
        'shared': {
            'mu': np.zeros(2),
            'kappa': 2.,
            'psi': np.eye(2),

# Path: distributions/dbg/random.py
# def score_student_t(x, nu, mu, sigma):
#     """
#     multivariate score_student_t
# 
#     \cite{murphy2007conjugate}, Eq. 313
#     """
#     p = len(mu)
#     z = x - mu
#     S = inner(inner(z, inv(sigma)), z)
#     score = (
#         gammaln(0.5 * (nu + p))
#         - gammaln(0.5 * nu)
#         - 0.5 * (
#             p * log(nu * pi)
#             + log(det(sigma))
#             + (nu + p) * log(1 + S / nu)
#         )
#     )
#     return score
# 
# def sample_normal_inverse_wishart(mu0, lambda0, psi0, nu0):
#     D, = mu0.shape
#     assert psi0.shape == (D, D)
#     assert lambda0 > 0.0
#     assert nu0 > D - 1
#     cov = sample_inverse_wishart(nu0, psi0)
#     mu = np.random.multivariate_normal(mean=mu0, cov=(1. / lambda0) * cov)
#     return mu, cov


# Path: distributions/dbg/models/niw.py
import numpy as np
import math
from scipy.special import multigammaln
from distributions.dbg.random import (
    score_student_t,
    sample_normal_inverse_wishart,
)
from distributions.mixins import SharedMixin, GroupIoMixin, SharedIoMixin

#
# - Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
# - Neither the name of Salesforce.com nor the names of its contributors
#   may be used to endorse or promote products derived from this
#   software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE



NAME = 'NormalInverseWishart'
EXAMPLES = [
    {
        'shared': {
            'mu': np.zeros(2),
            'kappa': 2.,
            'psi': np.eye(2),

            'nu': 3.,