discretizeDistribution

PURPOSE ^

discretize a continuous distribution

SYNOPSIS ^

function disD = discretizeDistribution(disC, varargin)

DESCRIPTION ^

 discretize a continuous distribution

 Syntax: disD = discretizeDistribution(disC)

 The standard method samples 100 points by a uniform distribution in the 
   unit box with lower corner [0, .., 0] and upper corner [1, .., 1]. The 
   input disC is generated by obtainDistributionContinuous.

 discretizeDistribution(..,  'argument', value) specifies additional
   options of the procedure. The method itsef is selected by 'method' and
   available values, including additional parameters are:
     'uniform', 'box uniform' or 'uniform box' - samples uniformly inside a
        rectangular box. The parameters 'regionLower' and 'regionUpper' 
        specify the lower and upper coordinate of the box.
   'normal' - uses importance sampling from a normal distribution. The
        parameter 'mean' is the mean value and 'cov' represents the
        covariance matrix. 'cov' might be a vector that is transformed to
        a diagonal covariance matrix.

 The output structure contains all fields from the input distribution, 
   while 'type' is set to 'disC'. The following fields are added:
     parDiscrete - the method and the parameters used for generation
     positionMatrix - the coordinates (column index) of each sample 
       point (column vectors)
     valueVector - the assigned value for the sample points from
       disC.fhandle
     probabilityVector - the probability density for selection of 
       each sample point.
 
 See also: obtainDistributionContinuous, obtainDistributionDiscrete

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function disD = discretizeDistribution(disC, varargin)
0002 % discretize a continuous distribution
0003 %
0004 % Syntax: disD = discretizeDistribution(disC)
0005 %
0006 % The standard method samples 100 points by a uniform distribution in the
0007 %   unit box with lower corner [0, .., 0] and upper corner [1, .., 1]. The
0008 %   input disC is generated by obtainDistributionContinuous.
0009 %
0010 % discretizeDistribution(..,  'argument', value) specifies additional
0011 %   options of the procedure. The method itsef is selected by 'method' and
0012 %   available values, including additional parameters are:
0013 %     'uniform', 'box uniform' or 'uniform box' - samples uniformly inside a
0014 %        rectangular box. The parameters 'regionLower' and 'regionUpper'
0015 %        specify the lower and upper coordinate of the box.
0016 %   'normal' - uses importance sampling from a normal distribution. The
0017 %        parameter 'mean' is the mean value and 'cov' represents the
0018 %        covariance matrix. 'cov' might be a vector that is transformed to
0019 %        a diagonal covariance matrix.
0020 %
0021 % The output structure contains all fields from the input distribution,
0022 %   while 'type' is set to 'disC'. The following fields are added:
0023 %     parDiscrete - the method and the parameters used for generation
0024 %     positionMatrix - the coordinates (column index) of each sample
0025 %       point (column vectors)
0026 %     valueVector - the assigned value for the sample points from
0027 %       disC.fhandle
0028 %     probabilityVector - the probability density for selection of
0029 %       each sample point.
0030 %
0031 % See also: obtainDistributionContinuous, obtainDistributionDiscrete
0032 
0033 % The elk-library: convex geometry applied to crystallization modeling.
0034 %   Copyright (C) 2013 Alexander Reinhold
0035 %
0036 % This program is free software: you can redistribute it and/or modify it
0037 %   under the terms of the GNU General Public License as published by the
0038 %   Free Software Foundation, either version 3 of the License, or (at your
0039 %   option) any later version.
0040 %
0041 % This program is distributed in the hope that it will be useful, but
0042 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0043 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0044 %   General Public License for more details.
0045 %
0046 % You should have received a copy of the GNU General Public License along
0047 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0048 
0049 %% Yet unsupported sampling:
0050 %   'uniform sphere' or 'sphere uniform' - samples uniformly in a ball. The
0051 %       parameters 'ballCenter' and 'ballRadius' define the ball.
0052 %   'importance', 'box importance' or 'importance box' - uses importance
0053 %       sampling in a rectangular box, where the importance is based on the
0054 %       density function. Parameters as for 'uniform'. Note that a lot more
0055 %       points are sampled to obtain the total nSample points.
0056 %   'importance sphere' or 'sphere importance' - uses importance sampling
0057 %       for a ball
0058 %   'quasi box', 'box quasi' - uses the Sobolov series (a low discrepancy
0059 %       series) to sample from a rectangular box.
0060 %
0061 % Importance sampling does not improve performance for Monte Carlo
0062 %   integrations as rejection sampling from an original uniform
0063 %   distribution is used.
0064 
0065 %% input handling
0066 [o.nSample, o.method, o.regionLower, o.regionUpper, o.regionCenter, o.radius, ...
0067     o.mean, o.cov, optionStructIn] = mapOption(varargin, ...
0068     'nSample', 100, ...
0069     'method', 'box uniform', ...
0070     'regionLower', zeros([disC.nDim, 1]), ...
0071     'regionUpper', ones([disC.nDim, 1]), ...
0072     'regionCenter', zeros([disC.nDim, 1]), ...
0073     'regionRadius', 1, ...
0074     'mean', [], ...
0075     'cov', [], ...
0076     'options', struct());
0077 optionStruct = mergeStruct(optionStructIn, o);
0078 
0079 optionStruct.regionCenter = optionStruct.regionCenter(:);
0080 
0081 %% initialization
0082 disD = disC;
0083 disD = rmfield(disD, 'fhandle');
0084 disD.type = 'discrete distribution';
0085 disD.nSample = optionStruct.nSample;
0086 
0087 if strcmpi(optionStruct.method, 'uniform') || ...
0088    strcmpi(optionStruct.method, 'box uniform') || ...
0089    strcmpi(optionStruct.method, 'uniform box')
0090 
0091     %% case: uniform box
0092     % parameters
0093     regionLower = optionStruct.regionLower(:);
0094     regionUpper = optionStruct.regionUpper(:);
0095     disD.parDiscrete = struct('regionLower', regionLower, 'regionUpper', ...
0096         regionUpper);
0097 
0098     % sample point positions
0099     disD.positionMatrix = bsxfun(@plus, regionLower, ...
0100         diag(regionUpper-regionLower) * ...
0101         rand([disC.nDim, optionStruct.nSample]));
0102     
0103     % values at positions
0104     disD.valueVector = disC.fhandle(disD.positionMatrix);
0105     
0106     % probability at position
0107     disD.probabilityVector = disD.valueVector * 0 + ...
0108         1/prod(optionStruct.regionUpper - optionStruct.regionLower);
0109 elseif strcmpi(optionStruct.method, 'normal')
0110     
0111     %% case: normal distribution
0112     % parameters
0113     [mean, cov] = ensureMeanAndCov(disC.nDim, optionStruct.mean, ...
0114         optionStruct.cov);
0115     
0116     disD.parDiscrete = struct('mean', mean, 'cov', cov);
0117     
0118     % assign position & probability
0119     [disD.positionMatrix disD.probabilityVector] = sampleNormal(disC.nDim, ...
0120         optionStruct.nSample, mean, cov);
0121     
0122     % values at positions
0123     disD.valueVector = disC.fhandle(disD.positionMatrix);    
0124     
0125 else
0126     %% case: unknown >> error
0127     error('elk:distribution:wrongInput', ...
0128         ['The given method name (' method ') is not supported.']);
0129 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005