pyrichlet.weight_models.DirichletProcess

class pyrichlet.weight_models.DirichletProcess(alpha=1, rng=None)
assignation_log_likelihood(d=None)

Returns the log-likelihood of an assignment d given the weights

complete(size)

Return an array of weights with at least n elements

This method appends weights to the truncated weighting structure self.w until reaching a length of size and then returns self.w. Note: This method sets a constraint on the minimum number of elements in the truncated weighting structure. No truncation is induced in case size is less than len(self.w) and the full length of self.w is returned.

Parameters:
sizeint

The desired size of the returned vector of weights

Returns:
np.array

Array of the weighted structure.

fit(d)

Fit the weighting structure to a vector of assignments

This method fits the parameters of the weighting model given the internal truncated weighting structure self.w. Any call to the methods random, tail or complete after calling this method results in a random draw from the posterior distribution.

Parameters:
darray[int], np.array

An array of integers representing the assigned group

fit_variational(variational_d)

Fits the variational distribution q

This method fits the variational distribution q that minimizes the Kullback-Leiber divergence from q(w) to p(w|d) ($D_{KL}(q||p)$) where d has a discrete finite random distribution given by q(d_i = j) = variational_d[j, i] and q is truncated up to k=len(variational_d) so that q(w_k=1) = 1.

get_normalized_cumulative_weights()

Returns the normalized cumulative weights

get_normalized_weights()

Returns the last weighting stricture normalized

get_size()

Returns the size of the truncated weighting structure

get_weights()

Returns the last weighting structure drawn

random(size=None)

Do a random draw of the truncated weighting structure up to n obs.

This method does a random draw from the posterior weighting distribution (or from the prior distribution if nothing has been fitted) and updates the internal truncated weighting structure self.w.

Parameters:
sizeint

The desired size of the returned vector of weights

Returns:
np.array

Array of the weighted structure.

random_assignment(size=None)

Returns a sample draw of the categorical assignment from the current state normalized weighting structure

reset()

Resets the conditional vector d to None

tail(x)

Return an array of weights such that the sum is greater than x

This method appends weights to the truncated weighting structure self.w until the sum of its elements is greater than the input x and then returns self.w.

Parameters:
xfloat

A float in the range $[0,1)$ for which the sum of weights must be greater.

Returns:
np.array

Array of the completed weighted structure

variational_mean_log_p_d__w(variational_d=None)

Returns the mean of log p(d|w)

This method returns the expected value of the logarithm of the probability of assignation d given w under the variational distribution q.

variational_mean_log_p_w()

Returns the mean of log p(w)

This method returns the expected value of the logarithm of the probability of assignation d given w under the variational distribution q.

variational_mean_log_q_w()

Returns the mean of log q(w)

This method returns the expected value of the logarithm of the probability of assignation d given w under the variational distribution q.

variational_mean_log_w_j(j)

Returns the mean of the logarithm of w_j

This method returns the expected value of the logarithm of w_j under the variational distribution q.

variational_mean_w_j(j)

Returns the mean of w_j

This method returns the expected value of the j-th weighting factor under the variational distribution q.

variational_mode_w_j(j)

Returns the mean of w_j

This method returns the expected value of the j-th weighting factor under the variational distribution q.

weighting_log_likelihood()

Return the given structure log-likelihood

This method returns log f(w) for the underlying weighting model.

Returns:
float

The log-likelihood value