Author : Jasperyang
School : BUPT算法
是這樣的,我在看Blei大牛03年的hlda論文中提到了CRP,以爲這是個頗有意思的數學現象,而且深刻了解後便於後面的研究,便經過查找不一樣資料加以理解。ide
中國餐館過程是一個典型的Dirichlet過程混合模型。能夠將中國餐館過程描述以下: 函數
假設一箇中國餐館中,能夠有無限個桌子,來吃飯的第一位顧客坐了第一張桌子。學習
對於每一位顧客,都按照下面的規則來選擇桌子坐下,對於第n個顧客:spa
$$ \frac{n_{k}}{a_{0}+n-1}$$rest
其中,nk 表示第k個桌子上已經有的顧客數。n−1表示在這個顧客以前,已有的顧客總數。 a0就是個參數(需設置)。code
顧客能夠選擇坐在一個沒有人坐的桌子上K+1的機率爲 blog
$$ \frac{a_{0}}{a_{0}+n-1}$$圖片
在這裏,能夠將顧客類比成數據,將每一張桌子類別成類。get
這麼講不具體,下面貼個R語言的代碼詳細說。
# Generate table assignments for `num_customers` customers, according to # a Chinese Restaurant Process with dispersion parameter `alpha`. # # returns an array of integer table assignments def chinese_restaurant_process(num_customers, alpha) return [] if num_customers <= 0 table_assignments = [1] # first customer sits at table 1 next_open_table = 2 # index of the next empty table # Now generate table assignments for the rest of the customers. 1.upto(num_customers - 1) do |i| if rand < alpha.to_f / (alpha + i) # Customer sits at new table. table_assignments << next_open_table next_open_table += 1 else # Customer sits at an existing table. # He chooses which table to sit at by giving equal weight to each # customer already sitting at a table. which_table = table_assignments[rand(table_assignments.size)] table_assignments << which_table end end table_assignments end
輸出以下:
> chinese_restaurant_process(num_customers = 10, alpha = 1) 1, 2, 3, 4, 3, 3, 2, 1, 4, 3 # table assignments from run 1 1, 1, 1, 1, 1, 1, 2, 2, 1, 3 # table assignments from run 2 1, 2, 2, 1, 3, 3, 2, 1, 3, 4 # table assignments from run 3 > chinese_restaurant_process(num_customers = 10, alpha = 3) 1, 2, 1, 1, 3, 1, 2, 3, 4, 5 1, 2, 3, 3, 4, 3, 4, 4, 5, 5 1, 1, 2, 3, 1, 4, 4, 3, 1, 1 > chinese_restaurant_process(num_customers = 10, alpha = 5) 1, 2, 1, 3, 4, 5, 6, 7, 1, 8 1, 2, 3, 3, 4, 5, 6, 5, 6, 7 1, 2, 3, 4, 5, 6, 2, 7, 2, 1
這裏的alpha就是a0,會發現,a0越大,最後分出來的桌子可能會越多。
以上這麼講是 Hierarchical Topic Models and the Nested Chinese Restaurant Process 這篇論文的原意。
這個位置選擇方式也就是公式的合理性是在別的文章中講解的。
首先須要介紹一下狄利克雷過程。
Dirichlet Process (DP)被稱爲分佈的分佈。從DP抽取出的每一個樣本(一個函數)均可以被認爲是一個離散隨機變量的分佈函數,這個隨機變量以非零機率值在可數無窮個離散點上取值。比較有意思的是,從DP能夠推導出幾個很是著名的問題: Chinese Restaurant Process (CRP)、Polya Urn Scheme和Stick-breaking Process。簡單的介紹能夠見Edwin Chen的博文「Infinite Mixture Models with Nonparametric Bayes and the Dirichlet Process」,這篇詳解了包括dp,crp等好幾個過程,可是沒有講數學推導。
DP的特性使得它在非參數貝葉斯聚類模型中能夠被用做參數的先驗分佈。Dirichlet Process Mixture (DPM)是這種非參數貝葉斯聚類模型中的一個典型表明。DPM能夠認爲是有限混合(Finite Mixture,FM)模型的一個推廣,FM(如Gaussian Mixture模型)必須首先給定類數,而DPM則不須要,它能夠依據數據自行判斷類數。理論上來講,DPM的類數隨着log(樣本點數量)的增加速度增加。目前研究者已經提出了不少訓練DPM的算法,從Gibbs Sampling,到Collapsed Gibbs Sampling,到Variational方法。
想進一步瞭解DP和DPM的同窗,能夠去Yee W. Teh的主頁上看看,裏面能夠找到不少相關的papers,slides,presentations,以及用Matlab寫的DPM開源軟件。想仔細瞭解DPM的各個算法及具體推導,建議看看Xiaodong Yu的博文,裏面也有他總結的一個很詳細的學習筆記(雖然裏面有一些小筆誤),以及更多的參考資料。
在hlda中將這個crp推廣到多層級的topic其實很簡單,就是先找一家餐館也就是一個root_topic,而後在這家餐館裏的每一個桌子上放的是別的餐館的名字,一次類推,就能夠無限的延續下去。
這篇主要就是講 Chinese Restaurant Process ,後續的文章我可能會去詳解HLDA。