Page 1 of 1

Using bayes functions in context?

Posted: Fri Dec 18, 2009 5:19 pm
by methodic
I am running into this issue -- when trying to use the bayes functions in context MAIN, it works as expected. When trying to use these in a defined function, I am getting an error with bayes-query.

Code: Select all

> (bayes-train '(A A B C C) '(A B B C C C) 'L)
(5 6)
> (bayes-query '(A C) L)
(0.579614219 0.420385781)

Code: Select all

> (context 'TEST)
TEST
TEST> (bayes-train '(A A B C C) '(A B B C C C) 'L)
(5 6)
TEST> (bayes-query '(A C) L)

ERR: context expected in function bayes-query : TEST:L
Anyone have any insight as to why this is happening? Am I not defining something properly?

Thanks in advance.

Re: Using bayes functions in context?

Posted: Fri Dec 18, 2009 5:50 pm
by itistoday
I think it's because since there is no existing L context, the symbol 'L inside of a different context is a symbol inside of that context, and context symbols must be in the MAIN context.

There are two ways around this:

#1: define the context first:

Code: Select all

> (context 'L)
L
L> (context 'TEST)
TEST
TEST> (bayes-train '(A A B C C) '(A B B C C C) 'L)
(5 6)
TEST> (bayes-query '(A C) L)
(0.579614219 0.420385781)
#2: context-qualify 'L inside of 'TEST:

Code: Select all

> (context 'TEST)
TEST
TEST> (bayes-train '(A A B C C) '(A B B C C C) 'MAIN:L)
(5 6)
TEST> (bayes-query '(A C) L)
(0.579614219 0.420385781)

Re: Using bayes functions in context?

Posted: Fri Dec 18, 2009 6:54 pm
by methodic
Thanks, I tried defining MAIN:K just without the tick. That solution worked. :)