我正在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时,前一个vaule都会从另一个中删除,可能性或者先验,如下所示:
>> 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
这是什么? 感谢。
答案 0 :(得分:5)
你应该听Mlint:
您正在使用该类,就好像它是一个引用,但它不会从句柄继承。快速修复:
classdef NaiveClass < handle
然后阅读:http://www.mathworks.de/de/help/matlab/matlab_oop/comparing-handle-and-value-classes.html