Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- classdef XDomainStatistics < handle
- %The purpose of this class is to keep basic statistics recursively
- %about empirically estimated one dimensional densities
- properties (SetAccess = 'private', GetAccess = 'public')
- Ex = [];
- Exx = [];
- xMax = [];
- xMin = [];
- cumWeight = 0;
- end
- methods
- function XDS = XDomainStatistics()
- XDS.Ex = 0;
- XDS.Exx = 0;
- XDS.cumWeight = 0;
- XDSXDS.xMax = realmin('double');
- XDS.xMin = realmax('double');
- end
- function Variance = Var(XDS)
- Variance = XDS.Exx - (XDS.Ex)^2;
- end
- function addPoint(XD,x,weight)
- if nargin == 2
- weight = 1;
- end
- if weight > 0 && numel(XD.Ex) > 0
- %Ex
- XD.Ex = (XD.Ex*XD.cumWeight + x*weight)/(XD.cumWeight + weight);
- %Exx
- XD.Exx = (XD.Exx*XD.cumWeight + (x^2)*weight)/(XD.cumWeight + weight);
- %xMax
- XD.xMax = max(XD.xMax,x);
- %xMin
- XD.xMin = min(XD.xMin,x);
- %cumWeight
- XD.cumWeight = XD.cumWeight + weight;
- else
- %Error weight or MMB.cumWeight is negative
- display(['Error: Cannot add (x,weight) double (',num2str(x),', ',num2str(weight),').']);
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement