Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate new components in data #18

Open
wangjiusi opened this issue Dec 18, 2018 · 0 comments
Open

Generate new components in data #18

wangjiusi opened this issue Dec 18, 2018 · 0 comments

Comments

@wangjiusi
Copy link

wangjiusi commented Dec 18, 2018

Hi, I am bothering you again.

I have encountered some difficulties in understanding the initialization of new categories based on the selected data set (Kmeans++).
More specifically, the code in DiagGaussObsModel.py

` def calcSmoothedMu(self, X, W=None):
''' Compute smoothed estimate of mean of statistic xxT.

    Args
    ----
    X : 2D array, size N x D

    Returns
    -------
    Mu_1 : 2D array, size D
        Expected value of Var[ X[n,d] ]
    Mu_2 : 1D array, size D
        Expected value of Mean[ X[n] ]
    '''
    if X is None:
        Mu1 = self.Prior.beta / self.Prior.nu
        Mu2 = self.Prior.m
        return Mu1, Mu2

    if X.ndim == 1:
        X = X[np.newaxis,:]
    N, D = X.shape
    # Compute suff stats
    if W is None:
        sum_wxx = np.sum(np.square(X), axis=0)
        sum_wx = np.sum(X, axis=0)
        sum_w = X.shape[0]
    else:
        W = as1D(W)
        sum_wxx = np.dot(W, np.square(X))
        sum_wx = np.dot(W, X)
        sum_w = np.sum(W)

    post_kappa = self.Prior.kappa + sum_w
    post_m = (self.Prior.m * self.Prior.kappa + sum_wx) / post_kappa
    Mu_2 = post_m

    prior_kmm = self.Prior.kappa * (self.Prior.m * self.Prior.m)
    post_kmm = post_kappa * (post_m * post_m)
    post_beta = sum_wxx + self.Prior.beta + prior_kmm - post_kmm
    Mu_1 = post_beta / (self.Prior.nu + sum_w)

    assert Mu_1.ndim == 1
    assert Mu_1.shape == (D,)
    assert Mu_2.shape == (D,)
    return Mu_1, Mu_2`

I know that it is calculating the center of the initial category, but I can't understand the rules of this calculation. Can you give me some advice?

Similarly, the code in ZeroMeanGaussObsModel.py

` def calcSmoothedMu(self, X, W=None):
Compute smoothed estimate of mean of statistic xxT.

    Args
    ----
    X : 2D array, size N x D

    Returns
    -------
    Mu : 2D array, size D x D
    '''
    Prior_nu = self.Prior.nu - self.D - 1
    # Prior_nu = self.Prior.nu

    if X is None:
        Mu = self.Prior.B / (Prior_nu)
        return Mu
    if X.ndim == 1:
        X = X[np.newaxis,:]
    N, D = X.shape
    # Compute suff stats
    if W is None:
        sum_wxxT = np.dot(X.T, X)
        sum_w = X.shape[0]
    else:
        W = as1D(W)
        wX = np.sqrt(W)[:,np.newaxis] * X
        sum_wxxT = np.dot(wX.T, wX)
        sum_w = np.sum(W)
    Mu = (self.Prior.B + sum_wxxT) / (Prior_nu + sum_w)
    assert Mu.ndim == 2
    assert Mu.shape == (D, D,)
    return Mu`
@wangjiusi wangjiusi changed the title Generate new components Generate new components in data Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant