# Path: distributions/dbg/special.py

# 
# Path: distributions/dbg/random.py
# def sample_chi2(nu):
#     return chi2.rvs(nu)
# 
# def sample_normal(mu, sigmasq):
#     return norm.rvs(mu, sigmasq)


from distributions.dbg.special import sqrt, log, pi, gammaln
from distributions.dbg.random import sample_chi2, sample_normal
from distributions.mixins import SharedMixin, GroupIoMixin, SharedIoMixin

    def merge(self, shared, source):
        count = self.count + source.count
        delta = source.mean - self.mean
        source_part = float(source.count) / count
        cross_part = self.count * source_part
        self.count = count
        self.mean += source_part * delta
        self.count_times_variance += \
            source.count_times_variance + cross_part * delta * delta

    def score_value(self, shared, value):
        """
        \cite{murphy2007conjugate}, Eq. 176
        """
        post = shared.plus_group(self)
        return score_student_t(
            value,
            post.nu,
            post.mu,
            ((1 + post.kappa) * post.sigmasq) / post.kappa)

    def score_data(self, shared):
        """
        \cite{murphy2007conjugate}, Eq. 171
        """
        post = shared.plus_group(self)
        return gammaln(post.nu / 2.) - gammaln(shared.nu / 2.) \
            + 0.5 * log(shared.kappa / post.kappa) \
            + (0.5 * shared.nu) * log(shared.nu * shared.sigmasq) \

# Path: distributions/dbg/special.py

# 
# Path: distributions/dbg/random.py
# def sample_chi2(nu):
#     return chi2.rvs(nu)
# 
# def sample_normal(mu, sigmasq):
#     return norm.rvs(mu, sigmasq)


# Path: distributions/dbg/models/nich.py
from distributions.dbg.special import sqrt, log, pi, gammaln
from distributions.dbg.random import sample_chi2, sample_normal
from distributions.mixins import SharedMixin, GroupIoMixin, SharedIoMixin


    def merge(self, shared, source):
        count = self.count + source.count
        delta = source.mean - self.mean
        source_part = float(source.count) / count
        cross_part = self.count * source_part
        self.count = count
        self.mean += source_part * delta
        self.count_times_variance += \
            source.count_times_variance + cross_part * delta * delta

    def score_value(self, shared, value):
        """
        \cite{murphy2007conjugate}, Eq. 176
        """
        post = shared.plus_group(self)
        return score_student_t(
            value,
            post.nu,
            post.mu,
            ((1 + post.kappa) * post.sigmasq) / post.kappa)

    def score_data(self, shared):
        """
        \cite{murphy2007conjugate}, Eq. 171
        """
        post = shared.plus_group(self)
        return gammaln(post.nu / 2.) - gammaln(shared.nu / 2.) \
            + 0.5 * log(shared.kappa / post.kappa) \
            + (0.5 * shared.nu) * log(shared.nu * shared.sigmasq) \

            - (0.5 * post.nu) * log(post.nu * post.sigmasq) \