SGVM_SAMPLE_DIST samples distribution object DIST N times. RVS = SGVM_SAMPLE_DIST(N, DIST, VMIN, VMAX) Returns N samples of a distribution object, DIST, that fall within the interval [VMIN, VMAX]. VMIN and VMAX are row vectors of size 1 x D, where D is the dimension of samples in distribution DIST. Inputs N - number of samples desired DIST - object with method "resample" to sample the distribution VMIN - minimum value allowable in retured samples VMAX - maximum value allowable in retured samples Outputs RVS - Nx1 vector of samples
0001 function rvs = sgvm_sample_dist(N, dist, vmin, vmax) 0002 %SGVM_SAMPLE_DIST samples distribution object DIST N times. 0003 % RVS = SGVM_SAMPLE_DIST(N, DIST, VMIN, VMAX) 0004 % 0005 % Returns N samples of a distribution object, DIST, that fall within the interval 0006 % [VMIN, VMAX]. VMIN and VMAX are row vectors of size 1 x D, where D is the dimension 0007 % of samples in distribution DIST. 0008 % 0009 % Inputs 0010 % N - number of samples desired 0011 % DIST - object with method "resample" to sample the distribution 0012 % VMIN - minimum value allowable in retured samples 0013 % VMAX - maximum value allowable in retured samples 0014 % Outputs 0015 % RVS - Nx1 vector of samples 0016 0017 % SynGrid 0018 % Copyright (c) 2018, Power Systems Engineering Research Center (PSERC) 0019 % by Eran Schweitzer, Arizona State University 0020 % 0021 % This file is part of SynGrid. 0022 % Covered by the 3-clause BSD License (see LICENSE file for details). 0023 0024 if nargin == 2 0025 vmin = -inf; 0026 vmax = inf; 0027 end 0028 0029 rvs = dist.resample(N); 0030 mask = any((rvs < vmin) | (rvs > vmax), 2); 0031 while sum(mask) > 0 0032 tmp = dist.resample(sum(mask)); 0033 rvs(mask,:) = tmp; 0034 mask = any((rvs < vmin) | (rvs > vmax), 2); 0035 end