2016-12-15 14 views
-2

10のトピックのすべてのドキュメントを分割したいと思います。トピックの分布と共分散マトリックスのディメンションを除いて、収束した結果とよく合います。
なぜトピックの分布が10ではなく9次元のベクトルであり、その共分散行列が10 * 10ではなく9 * 9行列であるのはなぜですか?トピックの分布の異なる次元

中国語でトピックモデルを実装するには、library(topicmodels)と機能CTM()を使用しています。

私のコードは以下の通りです:

library(rJava); 
library(Rwordseg); 
library(NLP); 
library(tm); 
library(tmcn) 
library(tm) 
library(Rwordseg) 
library(topicmodels) 

installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Law.scel","Law"); 
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\NationalInstitution.scel","NationalInstitution"); 
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Place.scel","Place"); 
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Psychology.scel","Psychology"); 
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Politics.scel","Politics"); 
listDict(); 

#read file 
d.vec <- segmentCN("samgovWithoutID.csv", returnType = "tm") 
samgov.segment <- read.table("samgovWithoutID.segment.csv", header = TRUE, fill = TRUE, stringsAsFactors = F, sep = ",",fileEncoding='utf-8') 
fix(samgov.segment) 

# create DTM(document term matrix) 
d.corpus <- Corpus(VectorSource(samgov.segment$content)) 
inspect(d.corpus[1:10]) 
d.corpus <- tm_map(d.corpus, removeWords, stopwordsCN()) 
ctrl <- list(removePunctuation = TRUE, removeNumbers= TRUE, wordLengths = c(1, Inf), stopwords = stopwordsCN(), wordLengths = c(2, Inf)) 
d.dtm <- DocumentTermMatrix(d.corpus, control = ctrl) 
inspect(d.dtm[1:10, 110:112]) 

# impletment topic models 
ctm10<-CTM(d.dtm,k=10, control=list(seed=2014012692)) 
Terms10 <- terms(ctm10, 10) 
Terms10[,1:10] 

ctm20<-CTM(d.dtm,k=20, control=list(seed=2014012692)) 
Terms20 <- terms(ctm20, 20) 
Terms20[,1:20] 

Rメーカー(ハイライト部分を参照)での結果:

enter image description here

ヘルプドキュメント:

enter image description here

+3

[再現可能な例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)を入力してください。あなたのコメントは – figurine

+0

Thx! – Jeffy

答えて

1

確率10バラ以上の分布luesには9つのフリーパラメータがあります。最初の9の確率を教えたら、最後の値の確率からそれらの確率の合計を差し引いて1にする必要があります。

10次元ロジスティック正規分布は、ガウス分布から10次元ベクトルをサンプリングし、それを累乗して1.0になるように正規化することによってそのベクトルを「潰す」ことに相当します。同じ10次元確率分布を累乗して正規化する無限個の10次元ベクトルがあります。各値に任意の定数cを加えればよいのです。これは、ガウスの平均には、より制約の厳しい分布よりも1つ多い、10の自由パラメータがあるからです。

ガウスを「識別可能」にする方法はいくつかあります。 1つは、平均ベクトルの要素の1つを0.0に固定することです。そのため、9次元の平均と共分散行列が表示されます。つまり、10番目の値は常に0であり、分散はありません。

関連する問題