Contents

function [rangeVec,mixProb] = approximate(F,Frange,k,varargin)

approximate.m

Finds mixing probabilities to approximate a given c.d.f. of a symmetric distribution,

$$ F(x) $$

with a mixture of uniform distributions,

$$ \hat{F}(x)=\sum_{i=1}^k p_i G(x,\sigma_i). $$

Input:
   F ~ Handle to function defining aproximate c.d.f.
   Frange ~ Width of symmetric support for F
   k ~ Number of approximating uniform distributions to use
Output:
   rangeVec ~
   mixProb ~

Set up the vector of mixing distributions.

Each element of rangeVec gives half of the support for a uniform distribution centered at zero.

rangeVec=(Frange/k):(Frange/k):Frange;

%Set up the uniform c.d.f.
%x(:,1) is the c.d.f. argument, x(:,2)=rangeVec=half range.
g=@(x) (-x(:,2)<x(:,1)).*(x(:,1)<x(:,2)).*(x(:,1)+x(:,2))./(2*x(:,2))+(x(:,1)>=x(:,2));
Input argument "Frange" is undefined.

Error in ==> approximate at 27
rangeVec=(Frange/k):(Frange/k):Frange;

Set up the vector of approximation points.

On these points, the approximation is exact by construction.

y=-Frange*(k-1)/k:Frange/k:0;

Set up the linear equations characterizing

$$p_1,p_2,...,p_k.$$

f=F(y');                            %Value of the true c.d.f. at the approximation points
gargs=[kron(y',ones(k,1)) kron(ones(k,1),rangeVec')];
gvec=g(gargs);                      %Values of the approximating c.d.f.'s at the approximation points.
gmat=reshape(gvec,k,k);             %Each column of gmat corresponds to one approximation point, each row corresponds to an approximating distribution.

Calculate mixing probabilities & construct approximation.

mixProb=inv(gmat')*f;

Fhat= @(x) mixProb'*g([x*ones(k,1) rangeVec']);

Plot a comparison.

if nargin > 3

    x=-Frange:0.001:Frange;
    y1=zeros(size(x));
    y2=zeros(size(x));
    for i=1:max(size(x));
        y1(i)=F(x(i));
        y2(i)=Fhat(x(i));
    end

    plot(x,y1,'-k');
    hold;
    plot(x,y2,'-.r');
    legend('Original Distribution','Approximation','Location','NorthWest');
end

End of File

end