dirichlet

How to get N random integer numbers whose sum is equal to M

依然范特西╮ 提交于 2021-02-10 20:21:58
问题 I want to make a list of N random INTEGER numbers whose sum is equal to M number. I have used numpy and dirichlet function in Python, but this generate double random number array, I would like to generate integer random number. import numpy as np np.random.dirichlet(np.ones(n))*m The solution can use other distribution the sense is resolve the problem. 回答1: The problem with using dirichlet for this is that it is a distribution over real numbers. It will yield a vector of numbers in the range

Dirichlet Multinomial model in JAGS with categorical X

南楼画角 提交于 2021-02-08 10:01:13
问题 Can someone help with JAGS code for a Bayesian multinomial logistic model with one categorical X variable (Dirichlet prior)? My representative sample is the matrix "z" in the code below that represents the 3 outcomes and "site", in the bottom line of code, is the categorical x variable. I can get the code that estimates each of the 3 outcomes but I'm stumped on how to add a categorical X (hospital site). I would like to use the first outcome, z[, 1], as the reference and 'a' as the reference

Dirichlet Multinomial model in JAGS with categorical X

时光总嘲笑我的痴心妄想 提交于 2021-02-08 10:00:22
问题 Can someone help with JAGS code for a Bayesian multinomial logistic model with one categorical X variable (Dirichlet prior)? My representative sample is the matrix "z" in the code below that represents the 3 outcomes and "site", in the bottom line of code, is the categorical x variable. I can get the code that estimates each of the 3 outcomes but I'm stumped on how to add a categorical X (hospital site). I would like to use the first outcome, z[, 1], as the reference and 'a' as the reference

Dirichlet process in PyMC 3

偶尔善良 提交于 2019-12-24 00:20:49
问题 I would like to implement to implement the Dirichlet process example referenced in Implementing Dirichlet processes for Bayesian semi-parametric models (source: here) in PyMC 3. In the example the stick-breaking probabilities are computed using the pymc.deterministic decorator: v = pymc.Beta('v', alpha=1, beta=alpha, size=N_dp) @pymc.deterministic def p(v=v): """ Calculate Dirichlet probabilities """ # Probabilities from betas value = [u*np.prod(1-v[:i]) for i,u in enumerate(v)] # Enforce sum

How to decide group assignments in Dirichlet process clustering

旧巷老猫 提交于 2019-12-13 01:43:26
问题 As in the Dirichlet clustering, the dirichlet process can be represented by the following: Chinese Restaurant Process Stick Breaking Process Poly Urn Model For instance, if we consider Chinese Restaurant Process the process is as follows: Initially the restaurant is empty The first person to enter (Alice) sits down at a table (selects a group). The second person to enter (Bob) sits down at a table. Which table does he sit at? He sits down at a new table with probability α/(1+α) He sits with

fftw3 for poisson with dirichlet boundary condition for all side of computational domain

廉价感情. 提交于 2019-12-13 01:14:14
问题 I am trying to solve Poison equation with Dirichlet boundary condition for four sides of computational domain. As known that I should use FFTW_RODFT00 to satisfy the condition. However, the result is not correct.Could you please help me? #include <stdio.h> #include <math.h> #include <cmath> #include <fftw3.h> #include <iostream> #include <vector> using namespace std; int main() { int N1=100; int N2=100; double pi = 3.141592653589793; double L1 = 2.0; double dx = L1/(double)(N1-1); double L2=

KeyError while printing trace in PyMC

独自空忆成欢 提交于 2019-12-12 01:39:16
问题 I had read that by default some names are assigned to Stochastic vaiables. I am writing the relevant portion of my code below. lam = pm.Uniform('lam', lower=0.0, upper=5, doc='lam') parameters = pm.Dirichlet('parameters',[1,1,1,1], doc='parameters') rv = [ pm.Multinomial("rv"+str(i), count[i], prob_distribution[i], value = data[i], observed = True) for i in xrange(0, len(count)) ] m = pm.MCMC([lam, parameters, rv]) m.sample(10) print m.trace('lam')[:] print m.trace('parameters_0')[:] The last

LDA and topic model

孤者浪人 提交于 2019-12-07 10:23:06
问题 I have studied LDA and Topic model for several weeks.But due to my poor mathematics ability, i can not fully understand its inner algorithms.I have used the GibbsLDA implementation, input a lot of documents, and set topic number as 100, i got a file named "final.theta" which stores the topic proportion of each topic in each document.This result is good, i can use the topic proportion to do many other things. But when i tried Blei's C language implementation on LDA, i only got a file named

R Supervised Latent Dirichlet Allocation Package

我们两清 提交于 2019-12-06 18:29:27
问题 I'm using this LDA package for R. Specifically I am trying to do supervised latent dirichlet allocation (slda). In the linked package, there's an slda.em function. However what confuses me is that it asks for alpha, eta and variance parameters. As far as I understand, I thought these parameters are unknowns in the model. So my question is, did the author of the package mean to say that these are initial guesses for the parameters? If yes, there doesn't seem to be a way of accessing them from