2014-03-25 6 views
2

topicmodels의 LDA 함수에서 재현 가능한 결과를 생성 할 수 없었습니다. 자신의 문서에서 예제를 수행하려면R의 topicmodels 패키지에서 LDA 함수로 정확한 결과를 재현하는 방법

library(topicmodels) 
set.seed(0) 
lda1 <- LDA(AssociatedPress[1:20, ], control=list(seed=0), k=2) 
set.seed(0) 
lda2 <- LDA(AssociatedPress[1:20, ], control=list(seed=0), k=2) 
identical(lda1, lda2) 
# [1] FALSE 

가 어떻게 LDA에 두 개의 별도의 통화에서 동일한 결과를 얻을 수 있나요?

제쳐두고 (패키지 작성자가 여기에있는 경우) control=list(seed=0) 스 니펫은 불행하고 불필요합니다. 뒤에는 if (missing(seed)) seed <- as.integer(Sys.time())의 줄이 있습니다. 이렇게하면 프로세스를보다 안정적으로 무작위로 만들지 않고 지정된 시드 만 실행 취소합니다. 내가 놓친 게 있니?

업데이트 : @hrbrmstr이 아래에서 발견했듯이, 컨트롤로 시드를 전달하면 효과적으로 동일한 개체가 생성되며, 유일한 차이점은 임시 로컬 파일 위치입니다. 따라서이 질문은 오해의 정도입니다 (그래도 함수가 set.seed()을 존중한다면 명확 해 보입니다).

+0

[seedmodels jstats journal entry] (http://epub.wu.ac.at/3987/1/topicmodels.pdf)의 9 페이지에있는'nstart' 및'best'와 함께'seed'가 언급됩니다. [PDF]. 나는 당신이 모든 것을'control = list (...) '매개 변수 세트에 포함 시켜서 완전히 재현 가능한 결과를 얻을 수 있도록해야한다고 생각합니다. – hrbrmstr

+0

컨트롤에 nstart = 1과 best = T를 추가해도 여전히 동일하지 않습니다 (lda1, lda2) == T –

답변

3

하지 정말 "대답"하지만

나는 다음과 갈 준 :-) 코드 조각을 게시 할 수있는 다른 방법이 없다 :

library(topicmodels) 

data(AssociatedPress) 

lda1 <- LDA(AssociatedPress[1:20, ], control=list(seed=0), k=2) 
lda2 <- LDA(AssociatedPress[1:20, ], control=list(seed=0), k=2) 

identical(lda1, lda2) 
[1] FALSE 

all.equal(lda1, lda2) 
[1] "Attributes: < Component 5: Attributes: < Component 10: 1 string mismatch > >" 

a1 <- posterior(lda1, AssociatedPress) 
a2 <- posterior(lda2, AssociatedPress) 

identical(a1, a2) 
[1] TRUE 

all.equal(a1, a2) 
[1] TRUE 

all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] "Attributes: < Component 10: 1 string mismatch >" 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 
all.equal([email protected],[email protected]) 
[1] TRUE 

identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] FALSE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 
identical([email protected],[email protected]) 
[1] TRUE 

상당한 @control은 "불평등"인가는?

+0

아, 참으로'@control' 슬롯 안에서는'@ 접두사 '슬롯 만 다릅니다. 이것은 컴퓨터의 tmp 폴더를 유지합니다. 아마도 중간 데이터 단계가 수행됩니다. 감사합니다. 답변으로 표시하고 그에 따라 질문을 편집합니다. –

+0

니스! 나는 다른 복잡한 데이터 구조와 약간의 차이점을 보였고 그래서 이전에 좀 더 많은 절개가 열매를 맺기를 희망했다. 기쁜 데 도움이되었습니다. – hrbrmstr