• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 195,  comments - 30,  trackbacks - 0
            At first, let's define the sample function:

            def sample(dist, num_samples=1):
                """
                Uses the inverse CDF method to return samples drawn from an
                (unnormalized) discrete distribution.

                Arguments:

                dist -- (unnormalized) distribution

                Keyword arguments:

                num_samples -- number of samples to draw
                
            """

                cdf = cumsum(dist)
                r = uniform(size=num_samples) * cdf[-1]

                return cdf.searchsorted(r)
            As we can see, the sample function input two parameters, one is dist, which can be an un-normalized distribution, another is the sample we want to draw.

            Let's see how to generate corpus for Dirichlet--multinomial unigram language model
            def generate_corpus(beta, mean, N):
                """
                Returns a corpus of tokens drawn from a Dirichlet--multinomial
                unigram language model. Each token is an instance of one of V
                unique word types, represented by indices 0, , V - 1.

                Arguments:

                beta -- concentration parameter for the Dirichlet prior
                mean -- V-dimensional mean of the Dirichlet prior
                N -- number of tokens to generate
                
            """

                pass # YOUR CODE GOES HERE
                #print mean
                #print beta 
                #print dot(mean,beta)
                #print dirichlet(mean*beta,size=1)
                temp=sample(dirichlet(beta*array(mean),size=1),N)
                #print temp
                return temp
            please keep in mind the dirichlet function is  “from numpy.random.mtrand import dirichlet"
            and the parameters it receives are corresponding to beta*array(mean). beta is the concentration factor, and mean is the vector which sum to 1.



            another way is to generate corpus is using the property:
            P(D'|D,H)= Nv+beta_nv/N+beta
            def generate_corpus_collapsed(beta, mean, N):
                """
                Returns a corpus of tokens drawn from a Dirichlet--multinomial
                unigram language model using the 'collapsed' generative process
                (i.e., phi is not explicitly represented). Each token is an
                instance of one of V unique word types.

                Arguments:

                beta -- concentration parameter for the Dirichlet prior
                mean -- V-dimensional mean of the Dirichlet prior
                N -- number of tokens to generate
                
            """

                V = len(mean) # vocabulary size

                corpus = zeros(N, dtype=int) # corpus

                Nv = zeros(V, dtype=int) # counts for each word type

                pass # YOUR CODE GOES HERE
                for n in xrange(N):
                    corpus[n]=sample((Nv+beta*array(mean))/(n+beta),1)
                    Nv[corpus[n]]+=1;    
                return corpus

            Let's see how to generate corpus for Mixture of Dirichlet-multinomial unigram language model 

            def generate_corpus(alpha, m, beta, n, D, Nd):
                """
                Returns a grouped corpus drawn from a mixture of
                Dirichlet--multinomial unigram language models.

                Arguments:

                alpha -- concentration parameter for the Dirichlet prior over theta
                m -- T-dimensional mean of the Dirichlet prior over theta
                beta -- concentration parameter for the Dirichlet prior over phis
                n -- V-dimensional mean of the Dirichlet prior over phis
                D -- number of documents to generate
                Nd -- number of tokens to generate per document
                
            """
                corpus = GroupedCorpus()

                pass # YOUR CODE GOES HERE
                #determine the topic the distribution for topic dirichlet(dot(m,alpha),size=1)
                #given the topic, the distribtuion for word dirichlet(dot(n,beta),size=1)
                theta=dirichlet(alpha*array(m),1)
                phis=dirichlet(beta*array(n),len(m))
                for d in range(0,D):
                    [t]=sample(theta,1)
                    #print groupVcab
                    corpus.add(str(d),str(t),[str(x) for x in sample(phis[t,:],Nd)])           
                return corpus
            注意是T個topic (group),  phis=dirichlet(beta*array(n),len(m))  產生了T個 dirichlet distribution,相同的topic t應該取同一個 dirichlet distribution phis[t,:]
            posted on 2012-10-28 10:13 luis 閱讀(630) 評論(0)  編輯 收藏 引用 所屬分類: Python
            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久国产一区二区三区香蕉 | 99久久无码一区人妻a黑| 久久一区二区三区免费| 久久精品国产男包| 亚洲AV无码久久精品成人| 久久99国内精品自在现线| 久久精品成人国产午夜| 日本高清无卡码一区二区久久| 少妇久久久久久被弄高潮| 91精品国产高清久久久久久io| 久久中文精品无码中文字幕| 色天使久久综合网天天| 久久久久久久亚洲精品| 狠狠干狠狠久久| 亚洲美日韩Av中文字幕无码久久久妻妇| 精品一区二区久久| 久久婷婷色综合一区二区| 久久久国产乱子伦精品作者| 久久久久亚洲AV无码观看| 国产欧美一区二区久久| 婷婷久久香蕉五月综合加勒比| 亚洲国产成人久久综合碰碰动漫3d| 亚洲中文久久精品无码ww16| 久久久久久久波多野结衣高潮| 久久免费视频观看| 久久青草国产精品一区| 久久久久久久女国产乱让韩| 久久996热精品xxxx| 国产精品欧美久久久天天影视| 国产成人久久精品一区二区三区 | 四虎影视久久久免费观看| 久久九九青青国产精品| 国产精品免费福利久久| 亚洲狠狠婷婷综合久久久久| 国产色综合久久无码有码| 狠狠色丁香久久婷婷综合图片| 国产精久久一区二区三区| 久久久久亚洲AV无码专区桃色 | 精品永久久福利一区二区| 无码伊人66久久大杳蕉网站谷歌 | 久久精品?ⅴ无码中文字幕|