Advertisement
x89codered89x

XDomainStatistics.m

Dec 14th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.57 KB | None | 0 0
  1. classdef XDomainStatistics < handle
  2.     %The purpose of this class is to keep basic statistics recursively
  3.     %about empirically estimated one dimensional densities
  4.     properties (SetAccess = 'private', GetAccess = 'public')        
  5.         Ex = [];
  6.         Exx = [];
  7.         xMax = [];
  8.         xMin = [];        
  9.         cumWeight = 0;
  10.     end
  11.     methods
  12.         function XDS = XDomainStatistics()
  13.            XDS.Ex = 0;
  14.            XDS.Exx = 0;
  15.            XDS.cumWeight = 0;
  16.            XDSXDS.xMax = realmin('double');
  17.            XDS.xMin = realmax('double');            
  18.         end
  19.         function Variance = Var(XDS)
  20.            Variance = XDS.Exx - (XDS.Ex)^2;
  21.         end      
  22.         function addPoint(XD,x,weight)  
  23.             if nargin == 2
  24.                 weight = 1;
  25.             end
  26.            
  27.             if weight > 0 && numel(XD.Ex) > 0              
  28.                 %Ex
  29.                 XD.Ex = (XD.Ex*XD.cumWeight + x*weight)/(XD.cumWeight + weight);
  30.  
  31.                 %Exx            
  32.                 XD.Exx = (XD.Exx*XD.cumWeight + (x^2)*weight)/(XD.cumWeight + weight);
  33.  
  34.                 %xMax
  35.                 XD.xMax = max(XD.xMax,x);
  36.  
  37.                 %xMin
  38.                 XD.xMin = min(XD.xMin,x);        
  39.                
  40.                 %cumWeight
  41.                 XD.cumWeight = XD.cumWeight + weight;
  42.             else
  43.                 %Error weight or MMB.cumWeight is negative
  44.                 display(['Error: Cannot add (x,weight) double (',num2str(x),', ',num2str(weight),').']);
  45.             end
  46.         end
  47.     end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement