我在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
Run Code Online (Sandbox Code Playgroud)
但是每次我调用函数setPrior或setLikelihood时,前一个vaule都会从另一个中删除,可能性或者之前,如下所示:
>> setLikelihood(bayes)
this =
NaiveClass
Properties:
name: 'Primary'
numberOfMail: 3
laplaceCounts: 4
uniqueWords: []
totalMails: 12
totalWords: 8
likelihoodGivenClass: 2/25
prior: []
Methods
Run Code Online (Sandbox Code Playgroud)
然后另一个电话:
setPrior(bayes)
obj =
NaiveClass
Properties:
name: 'Primary'
numberOfMail: 3
laplaceCounts: 4
uniqueWords: []
totalMails: 12
totalWords: 8
likelihoodGivenClass: []
prior: 1/4
Methods
Run Code Online (Sandbox Code Playgroud)
这是什么?谢谢.
你应该听Mlint:

您正在使用该类,就好像它是一个引用,但它不会从句柄继承.快速解决:
classdef NaiveClass < handle
Run Code Online (Sandbox Code Playgroud)
然后阅读:http://www.mathworks.de/de/help/matlab/matlab_oop/comparing-handle-and-value-classes.html
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |