/* MODEL NUMBER 0184
MODEL NAME: RandomWalk1D
SHORT DESCRIPTION: 20,000 1-D random walks are taken, the summation of Gaussian distributed steps
with mean of 0 and variance = 1 or uniformly distributed steps from -1 to 1. The positions at a
specific step number are selected, binned, and compared with a Gaussian model.
*/
//JAVA FUNCTIONS EMBEDDED IN MML
// GRIDDING THE DATA
source procedure regrid(ntime, y@n, j@n; xgrid@xL,totgrid@xL) {
// Note the above syntax: inputs first, comma separated,
// then a semi-colon,
// outputs last, comma separated.
//
// Remember those empty parentheses as in xL.ct()
language="java";
maincode={{
RegularGridData n = (RegularGridData) y.grid(0);
RegularGridData xL = (RegularGridData) xgrid.grid(0);
double time=ntime.realVal();
double[] cgrid = new double[xL.ct()];
for (int i=0; i-1) && (ixnsteps-1
realState xend(n); // xend backs up x 1 step
when(n=n.min) {x=0.0;}
when(n=n.min) {xend=0; }
realState icnt(n);
when (n=n.min) icnt=0;
// Choose steps from either a uniform distribution or Gaussian distribution
choice STEPS("Uniform Dist from -1 to 1","Gaussian(0,1)")=2;
real choose = STEPS;
// CALCULATE THE STEPS AND THE DISPLACEMENTS FOR ALL WALKS
real stepx(n);
stepx=if(choose=2) randomg() /* from Gaussian with mean=0, vaiance=1 */
else if(random()>0.5) random() else -random();/* from uniform from -1 to 1 */
event(n>n.min) {x=x+stepx;icnt=icnt+1;}
event(n>n.min and icnt>nsteps-1) {xend=x-stepx; x=0.0; icnt=0;}
real y(n); real j(n);
y=x;
j=icnt;
// GRID EACH WALK AT POSITION x(ntime) IN BINS OF SIZE xL.delta
real L=25;
realDomain xL; xL.min=-L; xL.max=L; xL.delta=0.1;
real ntime=10;
real xgrid(xL), totgrid(xL);
regrid(ntime, y@n, j@n,xgrid@xL,totgrid@xL);
// CONSTRUCT GAUSSIAN MODEL TO FIT BINNED DATA
real model(xL);
real xmean=0;
real sigma=if(choose=2) sqrt(ntime) else sqrt(ntime/3);
// NOTE: sigma depends on from which distribution the steps
// are chosen
real A=xL.delta;
model=A*(1./(sigma*sqrt(2*PI))*exp(-(xL-xmean)^2/(2*sigma^2)));
// CONSTRUCT CUMULATIVE DISTRIBUTION
real CumulativeModel(xL);
when(xL=xL.min) {CumulativeModel=0;}
CumulativeModel:xL=model/xL.delta;
}
/*
DETAILED DESCRIPTION: 1 DIMENSIONAL DIFFUSION, RANDOM DIRECTION, RANDOM STEP SIZE
N walks (nwalks) are taken consisting of N steps (nsteps). Each
walk starts at x=0. The steps are either left or right depending
on a uniform random number(0 to 1) being greater than 1/2; the
step lengths are taken from a uniform random distribution from
0 to 1. The final positions are gridded into bins of width xL.delta.
The distribution and the cumulative distributions are plotted along
the expected Gaussian distribution and the expected cumulative
distribution. The Gaussian distribution is given by
Gaussian distribution = (A/(sigma*sqrt(2*PI))*exp(-(xL-xmean)^2/(2*sigma^2)));
where A= xL.delta, tmean=0, and sigma = sqrt(ntime/3) for steps drawn from
the uniform distribution from -1 to 1, or sigma = sqrt(ntime) for
steps drawn from the Gaussian distribution with mean = 0 and variance = 1.
SHORTCOMINGS/GENERAL COMMENTS:
- Specific inadequacies or next level steps
KEY WORDS: Diffusion, Random walk, Stochastic, one dimension, 1-D, Transport Physiology
REFERENCES:
None.
REVISION HISTORY:
COPYRIGHT AND REQUEST FOR ACKNOWLEDGMENT OF USE:
Copyright (C) 1999-2013 University of Washington. From the National Simulation Resource,
Director J. B. Bassingthwaighte, Department of Bioengineering, University of Washington, Seattle WA 98195-5061.
Academic use is unrestricted. Software may be copied so long as this copyright notice is included.
This software was developed with support from NIH grant HL073598.
Please cite this grant in any publication for which this software is used and send an email
with the citation and, if possible, a PDF file of the paper to: staff@physiome.org.
*/