Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab erasing my values

Tags:

oop

matlab

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.

like image 295
Pedro.Alonso Avatar asked Jul 10 '26 04:07

Pedro.Alonso


1 Answers

You should listen to Mlint: mlint warnings

You are using the class as if it were a reference, but it does not inherit from handle. Quick fix:

 classdef NaiveClass < handle

And then read this: http://www.mathworks.de/de/help/matlab/matlab_oop/comparing-handle-and-value-classes.html

like image 97
DasKrümelmonster Avatar answered Jul 11 '26 21:07

DasKrümelmonster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!