0

I have been given the mean and variance. I need to produce a deterministic random walk from the given variables. These are the expected properties for the time series data:

  1. Mean: 27.57020098
  2. Median: 27.815
  3. Std Dev.:5.106888439
  4. Variance:26.08030952
  5. Maximum: 43.92
  6. Minimum: 0
  7. Range: 43.92

I've tried the following,

    steps = np.random.normal(loc=0, scale=5.034, size=1000) #std =5.304
    steps[0]=0
    P = 27.50 + np.cumsum(steps) #mean =27.5
    plt.plot(P)
    plt.title("Simulated Random Walk")
    plt.show()

Which produces,

Random Walk

Nelewout
  • 6,281
  • 3
  • 29
  • 39
  • 1
    What have you tried? This should not be a complex task, post your code and where you struggle and we'll help :) – rafaelc Aug 18 '18 at 12:27
  • How can you have a deterministic random walk? Deterministic and random are opposites, aren't they :o – figbeam Aug 18 '18 at 12:49
  • @figbeam deterministic randomity is a functionality, which, if you know what the input was, you can deduce what the output will be, but appears to be random for users. For instance, you can randomize numbers from 1 to 1000, by returning the millisecond value of the timestamp of the moment when the function was being called. If you know the algorithm and the input, you instantly know the output, But if you are a casual user, not knowing the algorithm, then the result will appear to be random for you. – Lajos Arpad Aug 18 '18 at 13:18
  • Thank you so much for response. Yes, I am aware those are opposite but, I have to generate a fake time series data with the given parameters. I have also tried with the geometric Brownian motion and brownian motion but was unable to get a deterministic result. – Sharvil Mainkar Aug 18 '18 at 13:23
  • @SharvilMainkar can you edit your question and explain what kind of values do you expect from an arbitrary mean or variance? There are several possibilities to implement this. – Lajos Arpad Aug 18 '18 at 13:46
  • i require to create a series which would give me data within this parameters. – Sharvil Mainkar Aug 18 '18 at 14:05
  • @SharvilMainkar how many possible values should you have? How should they be distributed in the interval? – Lajos Arpad Aug 18 '18 at 14:20
  • @LajosArpad The values should be minimun 1000. Normal/uniform distribution would work. – Sharvil Mainkar Aug 18 '18 at 15:45
  • @RafaelC Any solution? – Sharvil Mainkar Aug 18 '18 at 15:51
  • @SharvilMainkar thank you for the information, I have added an answer based on how I understood the problem to be solved. – Lajos Arpad Aug 18 '18 at 16:50
  • 1
    @Lajos Arpad: Ahhh..., I see. In my field we call it "pseudo-random". – figbeam Aug 18 '18 at 17:11
  • @figbeam that's their exact name, so you are right, but those, who do not know this technical term will use something else to describe the phenomena. Like "deterministic random", which is an equivalent. – Lajos Arpad Aug 18 '18 at 17:20
  • @figbeam Ohh my mistake I am new to this. I understand the contradiction. But random walk processes can be made deterministic right? – Sharvil Mainkar Aug 18 '18 at 17:55
  • @Sharvil Mainkar: I just got confused by the unfamiliar name. You can make a sequence that seemingly is random walk but still deterministic, as Lajos Arpad points out. – figbeam Aug 18 '18 at 18:17

2 Answers2

0

Let's consider the number of possible values are n. Your function returns a natural number, 0 <= i < n. This would be the i'th possible value. If you look at the current timestamp, convert it into milliseconds, the result being t, then a possible deterministic random would be

i = t mod n

now, get the i'th possible value. You will need to add the minimal offset (1000) to the result and get the i'th number.

EDIT:

If you know that the minimal number is 1000 and the gap between the i'th and (i + 1)'th element is exactly k (normal distribution), then the formula to use would be

result = 1000 + i * k

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • I did the code but was unable to get deterministic values. The Values must lie between the given range(in the question, between 0 and 43.92). – Sharvil Mainkar Aug 18 '18 at 17:50
0

With the standard library you can seed the random function with the same value each time which makes the sequence deterministic. I have included an example which illustrates the principle.

import random

seed = 'pseudo-random'          # Can be anything
random.seed(a=seed, version=2)  # Use the same seed every time

float_list = []    # List to contain a small sample of  values
mean =  27.57020098
dev = 5.106888439

for x in range(20):
    value = random.gauss(mean, dev)
    if value > 43.92: value = 43.92 # Limit max value
    if value < 0: value = 0         # Limit min value
    float_list.append('{:.3f}'.format(value))

print(float_list)

I don't know if np allows for this way of using the same seed each time.

figbeam
  • 7,001
  • 2
  • 12
  • 18