random-walk

Variance in random Walk with Matlab

落花浮王杯 提交于 2021-02-11 12:55:51
问题 I'm new to the forum and a beginner in programming. I have the task to program a random walk in Matlab (1D or 2D) with a variance that I can adjust. I found the code for the random walk, but I'm really confused where to put the variance. I thought that the random walk always has the same variance (= t ) so maybe I'm just lost in the math. How do I control the variance? 回答1: For a simple random walk, consider using the Normal distribution with mean 0 (also called 'drift') and a non-zero

OpenCL Intel Iris Integrated Graphics exits with Abort Trap 6: Timeout Issue

两盒软妹~` 提交于 2021-02-07 19:19:16
问题 I am attempting to write a program that executes Monte Carlo simulations using OpenCL. I have run into an issue involving exponentials. When the value of the variable steps becomes large, approximately 20000, the calculation of the exponent fails unexpectedly, and the program quits with "Abort Trap: 6". This seems to be a bizarre error given that steps should not affect memory allocation. I have tried setting normal , alpha , and beta to 0 but this does not resolve the problem however

How to repeat 1000 times this random walk simulation in R?

﹥>﹥吖頭↗ 提交于 2021-02-05 05:19:25
问题 I'm simulating a one-dimensional and symmetric random walk procedure: y[t] = y[t-1] + epsilon[t] where white noise is denoted by epsilon[t] ~ N(0,1) in time period t . There is no drift in this procedure. Also, RW is symmetric, because Pr(y[i] = +1) = Pr(y[i] = -1) = 0.5 . Here's my code in R: set.seed(1) t=1000 epsilon=sample(c(-1,1), t, replace = 1) y<-c() y[1]<-0 for (i in 2:t) { y[i]<-y[i-1]+epsilon[i] } par(mfrow=c(1,2)) plot(1:t, y, type="l", main="Random walk") outcomes <- sapply(1

1D Random Walk from Matlab to Python

落花浮王杯 提交于 2021-01-27 18:02:13
问题 I have a Matlab code that generates a 1D random walk. %% probability to move up or down prob = [0.05, 0.95]; start = 2; %% start with 2 positions(1) = start; for i=2:1000 rr = rand(1); down = rr<prob(1) & positions(i-1)>1; up = rr>prob(2) & positions(i-1)<4; positions(i) = positions(i-1)-down + up; figure(1), clf plot(positions) This gives me the plot below 1D Random Walk with Matlab I need to try to translate this in Python and I have came up with this (using numpy): import random import

1D Random Walk from Matlab to Python

☆樱花仙子☆ 提交于 2021-01-27 17:51:18
问题 I have a Matlab code that generates a 1D random walk. %% probability to move up or down prob = [0.05, 0.95]; start = 2; %% start with 2 positions(1) = start; for i=2:1000 rr = rand(1); down = rr<prob(1) & positions(i-1)>1; up = rr>prob(2) & positions(i-1)<4; positions(i) = positions(i-1)-down + up; figure(1), clf plot(positions) This gives me the plot below 1D Random Walk with Matlab I need to try to translate this in Python and I have came up with this (using numpy): import random import

Computing the mean square displacement of a 2d random walk in Python

好久不见. 提交于 2020-05-16 08:54:23
问题 I'm simulating a 2-dimensional random walk, with direction 0 < θ < 2π and T=1000 steps. I already have a code which simulates a single walk, repeats it 12 times, and saves each run into sequentially named text files: a=np.zeros((1000,2), dtype=np.float) print a # Prints array with zeros as entries # Single random walk def randwalk(x,y): # Defines the randwalk function theta=2*math.pi*rd.rand() x+=math.cos(theta); y+=math.sin(theta); return (x,y) # Function returns new (x,y) coordinates x, y =

Random Tour Generation Issues

帅比萌擦擦* 提交于 2020-01-06 18:42:41
问题 I am trying to generate a random tour from the graph. I am using the adjacency-list method. There is a problem with the vertices. When I add a vertex to a particular list, the vertex gets added to all the lists in the graph. I do not understand why! Here's the code: public static void main(String[] args) { defaultData(6); } public static void defaultData(int n) { Integer costs[] = { 26, 95, 38, 74, 80, 73, 73, 92, 22, 97, 13, 81, 41, 17, 4, 2, 47, 54, 21, 68, 78, 4, 77, 3, 66, 55, 99, 42, 62,

How do I put arena limits on a random walk?

微笑、不失礼 提交于 2019-12-21 14:12:30
问题 I'm building a biased correlated random walk, and I've managed to build the RW, and bias it for westerly movement. The issue: I need the walk to be bound on one (or all) side(s). The current code is: walk<-function(n.times){ plot(524058:542800,2799758:2818500,type="n", xlab="Easting",ylab="Northing")#aren‌​a y<-2815550 ##startY x<-542800 #startX N<-4000 E<-4000 points(x,y,pch=16,col="red",cex=1) for (i in 1:n.times) { yi <- sample(c(N,N/2,N/4,N/8,N/12,N/16, 0,-N,-N/2,-N/4,-N/8,-N/12,-N/16),1)

How do I put arena limits on a random walk?

十年热恋 提交于 2019-12-21 14:12:23
问题 I'm building a biased correlated random walk, and I've managed to build the RW, and bias it for westerly movement. The issue: I need the walk to be bound on one (or all) side(s). The current code is: walk<-function(n.times){ plot(524058:542800,2799758:2818500,type="n", xlab="Easting",ylab="Northing")#aren‌​a y<-2815550 ##startY x<-542800 #startX N<-4000 E<-4000 points(x,y,pch=16,col="red",cex=1) for (i in 1:n.times) { yi <- sample(c(N,N/2,N/4,N/8,N/12,N/16, 0,-N,-N/2,-N/4,-N/8,-N/12,-N/16),1)

Random walk pandas

独自空忆成欢 提交于 2019-12-21 04:31:11
问题 I am trying to quickly create a simulated random walk series in pandas. import pandas as pd import numpy as np dates = pd.date_range('2012-01-01', '2013-02-22') y2 = np.random.randn(len(dates))/365 Y2 = pd.Series(y2, index=dates) start_price = 100 would like to build another date series starting at start_price at beginning date and growing by the random growth rates. pseudo code: P0 = 100 P1 = 100 * exp(Y2) P2 = P1 * exp(Y2) very easy to do in excel, but I cant think of way of doing it