random-walk

Random walk pandas

纵然是瞬间 提交于 2019-12-21 04:31:07
问题 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

Perform a RandomWalk step with Tensorflow Probability's RandomWalkMetropolis function

醉酒当歌 提交于 2019-12-13 04:39:11
问题 I am new to Tensorflow Probability and would like to do a RandomWalk Montecarlo simulation. Let's say I have tensor r that represents a state. I want the tfp.mcmc.RandomWalkMetropolis function to return a proposal for a new state r'. tfp.mcmc.RandomWalkMetropolis(r) >>> <tensorflow_probability.python.mcmc.random_walk_metropolis.RandomWalkMetropolis object at 0x14abed2185c0> Instead of the same state, or a slightly perturbed state only this RandomWalkMetropolis object is returned. The

Calculate correlation of data generated by function in R

随声附和 提交于 2019-12-12 16:27:44
问题 I have created the following function in R : timeseriesmodel <- function(N, x0, delta, variance) { z<-cumsum(rnorm(n=N, mean=0, sd=sqrt(variance))) t<-1:N x<-x0+t*delta+z return(x)} This function returns a vector 'x' of length 'N', representing the data points of a random walk with drift. In my case: timeseriesmodel(250,1,0,1.2) Now I should repeat this function 100 times, ending up with 100 timeseries data sets of length 250. Then I have to estimate the correlation between the 249th and

Get bad result for random walk

廉价感情. 提交于 2019-12-11 08:46:38
问题 I want to implement random walk and compute the steady state. Suppose my graph is given as in the following image: The graph above is defined in a file as follows: 1 2 0.9 1 3 0.1 2 1 0.8 2 2 0.1 2 4 0.1 etc To read and build this graph, I use the following method: def _build_og(self, original_ppi): """ Build the original graph, without any nodes removed. """ try: graph_fp = open(original_ppi, 'r') except IOError: sys.exit("Could not open file: {}".format(original_ppi)) G = nx.DiGraph() edge

Generating a Smooth Random Trend (Random Walk) in JavaScript

天涯浪子 提交于 2019-12-06 12:20:07
问题 I am looking for a JavaScript implementation of a random walk/random trend algorithm. I need something that will stick with a trend (so, just plain random deltas are out) while still staying within some specified boundaries. I tried writing something off the top of my head by choosing numbers based on a weighted average (the weight was calculated using the Gaussian function) and ended up with a slightly smoother line (not good enough). I then took a less direct approach and tried searching on

Random Walk on Bipartite Graph with Gremlin

时光毁灭记忆、已成空白 提交于 2019-12-06 06:46:29
问题 I would like to rank items according to a given users preference (items liked by the user) based on a random walk on a directed bipartite graph using gremlin in groovy. The graph has the following basic structure: [User1] ---'likes'---> [ItemA] <---'likes'--- [User2] ---'likes'---> [ItemB] Hereafter the query that I came up with: def runRankQuery(def userVertex) { def m = [:] def c = 0 while (c < 1000) { userVertex .out('likes') // get all liked items of current or similar user .shuffle[0] //

Probability to visit nodes in a random walk on graph

拥有回忆 提交于 2019-12-06 03:32:03
问题 I have a finite undirected graph in which a node is marked as "start" and another is marked as "goal". An agent is initially placed at the start node and it navigates through the graph randomly, i.e. at each step it chooses uniformly at random a neighbor node and moves to it. When it reaches the goal node it stops. I am looking for an algorithm that, for each node, gives an indication about the probability that the agent visits it, while traveling from start to goal. Thank you. 回答1: As is

Visualizing a 2d random walk in python

折月煮酒 提交于 2019-12-05 02:04:01
问题 I'm trying to make a random walk in 2d, and plot the 2d walk. I've been able to make the walk, but the plot is not exactly what I wanted. Would it be possible to see the walk live in python ? Or just add a label to every point so that you know which point came first and which point came second etc. ? import numpy as np import matplotlib.pyplot as plt import random def randomWalkb(length): steps = [] x,y = 0,0 walkx,walky = [x],[y] for i in range(length): new = random.randint(1,4) if new == 1:

Generating a Smooth Random Trend (Random Walk) in JavaScript

百般思念 提交于 2019-12-04 19:41:08
I am looking for a JavaScript implementation of a random walk/random trend algorithm. I need something that will stick with a trend (so, just plain random deltas are out) while still staying within some specified boundaries. I tried writing something off the top of my head by choosing numbers based on a weighted average (the weight was calculated using the Gaussian function) and ended up with a slightly smoother line (not good enough). I then took a less direct approach and tried searching on the internet, and although I found a few outlines, there was nothing specific enough that I understood

Random Walk on Bipartite Graph with Gremlin

£可爱£侵袭症+ 提交于 2019-12-04 13:30:35
I would like to rank items according to a given users preference (items liked by the user) based on a random walk on a directed bipartite graph using gremlin in groovy. The graph has the following basic structure: [User1] ---'likes'---> [ItemA] <---'likes'--- [User2] ---'likes'---> [ItemB] Hereafter the query that I came up with: def runRankQuery(def userVertex) { def m = [:] def c = 0 while (c < 1000) { userVertex .out('likes') // get all liked items of current or similar user .shuffle[0] // select randomly one liked item .groupCount(m) // update counts for selected item .in('likes') // get