3

I'm writing a OOP on Matlab, a naive bayes for separating email. Like this

 classdef NaiveClass

%NaiveClass what this will do is hold on his emails
% the p(message|class) compute the probability 
% have the specific class info as well as who are they brothers
%   

properties
    name
    numberOfMail
    laplaceCounts
    uniqueWords
    totalMails
    totalWords
    likelihoodGivenClass
    prior
end

methods
    function identify(thisNaiveClass)
        disp('I''m a bayes node')
    end

    function set = setPrior(obj)

        obj.prior = (obj.numberOfMail + 1) / (obj.totalMails + obj.laplaceCounts)

    end

    function like = setLikelihood(this)

        this.likelihoodGivenClass = (1 + 1) / (this.totalWords + 17)

    end

 end

end

But every time I call the function setPrior or setLikelihood the previous vaule get deleted from the other, the likelihood or the prior, like this:

>> setLikelihood(bayes)
this = 
NaiveClass

Properties:
                name: 'Primary'
        numberOfMail: 3
       laplaceCounts: 4
         uniqueWords: []
          totalMails: 12
          totalWords: 8
likelihoodGivenClass: 2/25
               prior: []
Methods 

And then the other call:

setPrior(bayes)
obj = 
NaiveClass

Properties:
                name: 'Primary'
        numberOfMail: 3
       laplaceCounts: 4
         uniqueWords: []
          totalMails: 12
          totalWords: 8
likelihoodGivenClass: []
               prior: 1/4
Methods

So what is this? Thanks.

4

1 回答 1

5

你应该听 Mlint: 警告

您正在使用该类,就好像它是一个引用一样,但它不是从句柄继承的。快速解决:

 classdef NaiveClass < handle

然后阅读: http: //www.mathworks.de/de/help/matlab/matlab_oop/comparing-handle-and-value-classes.html

于 2013-07-29T16:41:55.707 回答