<< Chapter < Page | Chapter >> Page > |
qsample.m Simulates a sample for a given population density. Determines sample parameters and approximate population parameters. Assumes dfsetup or acsetup has been run. Takes asinput the distribution matrices and the sample size n . Uses a random number generator to obtain the probability matrix U and uses the m-function dquant to determine the sample. Assumes dfsetup or acsetup has been run.
% QSAMPLE file qsample.m Simulates sample for given population density
% Version of 1/31/96% Determines sample parameters
% and approximate population parameters.% Assumes dfsetup or acsetup has been run
X = input('Enter row matrix of VALUES ');PX = input('Enter row matrix of PROBABILITIES ');
n = input('Sample size n = ');m = length(X);
U = rand(1,n);T = dquant(X,PX,U);
ex = sum(T)/n;EX = dot(X,PX);
vx = sum(T.^2)/n - ex^2;VX = dot(X.^2,PX) - EX^2;
disp('The sample is in column vector T')disp(['Sample average ex = ', num2str(ex),])disp(['Approximate population mean E(X) = ',num2str(EX),])disp(['Sample variance vx = ',num2str(vx),])disp(['Approximate population variance V(X) = ',num2str(VX),])
targetset.m Setup for arrival at a target set of values. Used in conjunction with the m-procedure targetrun to determine the number of trials needed to visit k of a specified set of target values. Input consists of the distribution matrices and the specified set E of target values.
% TARGETSET file targetset.m Setup for sample arrival at target set
% Version of 6/24/95X = input('Enter population VALUES ');
PX = input('Enter population PROBABILITIES ');ms = length(X);
x = 1:ms; % Value indicesdisp('The set of population values is')
disp(X);E = input('Enter the set of target values ');
ne = length(E);e = zeros(1,ne);
for i = 1:nee(i) = dot(E(i) == X,x); % Target value indices
endF = [0 cumsum(PX)];A = F(1:ms);
B = F(2:ms+1);disp('Call for targetrun')
targetrun.m Assumes the m-file targetset has provided the basic data. Input consists of the number r of repetitions and the number k of the target states to visit. Calculates and displays various results.
% TARGETRUN file targetrun.m Number of trials to visit k target values
% Version of 6/24/95 Rev for Version 5.1 1/30/98% Assumes the procedure targetset has been run.
r = input('Enter the number ofrepetitions ');
disp('The target set is')disp(E)
ks = input('Enter the number of target values to visit ');if isempty(ks)
ks = ne;end
if ks>ne
ks = ne;end
clear T % Trajectory in value indices (reset)R0 = zeros(1,ms); % Indicator for target value indices
R0(e) = ones(1,ne);S = zeros(1,r); % Number of trials for each run (reset)
for k = 1:rR = R0;
i = 1;while sum(R)>ne - ks
u = rand(1,1);s = ((A<u)&(u<= B))*x';
if R(s) == 1 % Deletes indices as values reachedR(s) = 0;
endT(i) = s;
i = i+1;end
S(k) = i-1;end
if r == 1disp(['The number of trials to completion is ',int2str(i-1),])disp(['The initial value is ',num2str(X(T(1))),])disp(['The terminal value is ',num2str(X(T(i-1))),])N = 1:i-1;
TR = [N;X(T)]';
disp('To view the trajectory, call for TR')else
[t,f]= csort(S,ones(1,r));
D = [t;f]';
p = f/r;AV = dot(t,p);
SD = sqrt(dot(t.^2,p) - AV^2);MN = min(t);
MX = max(t);disp(['The average completion time is ',num2str(AV),])disp(['The standard deviation is ',num2str(SD),])disp(['The minimum completion time is ',int2str(MN),])disp(['The maximum completion time is ',int2str(MX),])disp(' ')
disp('To view a detailed count, call for D.')disp('The first column shows the various completion times;')
disp('the second column shows the numbers of trials yielding those times')plot(t,cumsum(p))
gridtitle('Fraction of Runs t Steps or Less')
ylabel('Fraction of runs')xlabel('t = number of steps to complete run')
end
Notification Switch
Would you like to follow the 'Applied probability' conversation and receive update notifications?