3

メールを分離するための素朴なベイズであるMatlabでOOPを書いています。このような

 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

しかし、関数 setPrior または setLikelihood を呼び出すたびに、次のように、前の値が他方の尤度または事前値から削除されます。

>> setLikelihood(bayes)
this = 
NaiveClass

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

そして、他の呼び出し:

setPrior(bayes)
obj = 
NaiveClass

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

それで、これは何ですか?ありがとう。

4

1 に答える 1

5

Mlint に耳を傾ける必要があります。 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 に答える