Public
Edited
Mar 25, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
numberOfTrajectories = Math.floor(maxSteps / period)
Insert cell
Insert cell
Insert cell
noiseFunction = d3.randomNormal(0, sigma)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
growthRate = mu - (sigma * sigma) / 2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
simulatedTrajectories = {
// Initialise an array of runs
const data = []
// For each run…
for( let r = 0; r < numberOfTrajectories; r++){
// Determine the starting point of the run in the data array so each run is added consecutively in the array.
const startingArrayPos = (r * period)
// Initialise the start of each run with the initialValue and reset the timeStep to 0
data[startingArrayPos] = {timeStep: 0, value: initialValue, run: r}
// Step through each timeStep
for(let t = 1; t < period; t++){
// Determine the previous value, which will be the value of the immediately preceeding timeStep
const previousValue = data[startingArrayPos+t-1]['value']
// Calculate the new value, by multiplying the previous value by mu + a sample from the noise function.
const newValue = previousValue * (mu + noiseFunction())
data[startingArrayPos+t] = {timeStep: t, value: newValue, run: r}
}
}
return data
}

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more