gpt4 book ai didi

Matlab 删除我的值(value)观

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:33 27 4
gpt4 key购买 nike

我正在 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

那这是什么?谢谢。

最佳答案

你应该听听 Mlint: mlint warnings

您正在使用该类,就好像它是一个引用,但它不继承自 handle。快速修复:

 classdef NaiveClass < handle

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

关于Matlab 删除我的值(value)观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17928669/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com