Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- classdef Density <handle
- %The purpose of this class is to empirically estimate
- %one dimensional probability densities using linear interpolation
- %
- %Dependent files:
- %
- % XDomainFunction.m , http://pastebin.com/qY5DRj3i
- % XDomainStatistics.m , http://pastebin.com/h42ZWauh
- %
- properties (GetAccess = 'private', SetAccess = 'private')
- Function;
- Statistics;
- end
- methods
- function D = Density(D,dx)
- if nargin == 1
- dx = 1;
- end
- %add function properties
- D.Statistics = XDomainStatistics();
- D.Function = XDomainFunction(-dx/2,dx/2);
- end
- function [n_float, supportPointsAdded] = addPoint(D,x,weight)
- if nargin == 2
- weight = 1;
- end
- %update density
- D.Function.addPoint(x,weight);
- %add linear interpolated weight to function
- D.Statistics.addPoint(x,weight);
- n_float = D.Function.getNFloat(x);
- supportPointsAdded = D.Function.supportPointsAdded;
- end
- function p = prob(D,x)
- %x is scalar
- p = D.Function.linearInterpolatedValue(x)/D.Statistics.cumWeight;
- end
- %Extra Statistics member functions
- function n_MaxP = nMaxP(D)
- n_MaxP = D.Function.nMaxValue;
- end
- function n_MinP = nMinP(D)
- n_MinP = D.Function.nMinValue;
- end
- function minP = minP(D)
- minP = D.Function.minValue()/D.Statistics.cumWeight;
- end
- function maxP = maxP(D)
- maxP = D.Function.maxValue()/D.Statistics.cumWeight;
- end
- %Overloaded Statistics
- function ExpectedValue = Ex(D)
- ExpectedValue = D.Statistics.Ex;
- end
- function ExpectedValueSquared = Exx(D)
- ExpectedValueSquared = D.Statistics.Exx;
- end
- function Variance = Var(D)
- Variance = D.Statistics.Var;
- end
- function functionX = fX(D,nn)
- if nargin == 2
- functionX = D.Function.fX(nn)/D.Statistics.cumWeight;
- else
- functionX = D.Function.fX/D.Statistics.cumWeight;
- end
- end
- function domainX = X(D,nn)
- if nargin == 2
- domainX = D.Function.X(nn);
- else
- domainX = D.Function.X;
- end
- end
- function differentialX = dX(D)
- differentialX = D.Function.dX;
- end
- function cumulativeSum = cumWeight(D)
- cumulativeSum = D.Statistics.cumWeight;
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement