Question

In: Computer Science

Consider a one-dimensional random walker (using numpy) that can move every second. With probability pl =...

Consider a one-dimensional random walker (using numpy) that can move every second. With probability pl = 1/3 it moves to the left, with probability pr = 1/3 it moves to right, and with probability pr = 1/3 it rests and does not move. Assuming at time t = 0, the random walker is at x = 0, plot (using matplotlib) the probability density function and the cumulative probability function for t = 10, t = 100, and t = 1000 seconds. Make just two plots; each showing all three time points. Remember that you need to simulate random walks many times to get good statistics. Make the same two plots for pl = 0, pr = 1/2, and pr = 1/2. Do you understand why these plots look different? The plots that you make should be designed well. For example, they should label curves, axes, etc. (USING PYTHON)

Solutions

Expert Solution

imagine we would stand on the node of document 1 and would randomly (uniform) decide which edge to take to get to another node. Since we have only two edges, the probability that we would go to topic 1 is 0.5 just like the probability that we would go to topic 2. In total, we have a sum of 1.

If we do this imagination for all nodes, we end up with a matrix M with the starting points as columns and the probabilities in the respective rows. This matrix can be created in python with the following code:

import numpy as np

M = np.array([

[0, 0, 0, 1./3., 0.5],

[0, 0, 0, 1./3., 0],

[0, 0, 0, 1./3., 0.5],

[0.5, 1, 0.5, 0, 0],

[0.5, 0, 0.5, 0, 0]

])

The usual random walk wouldn’t go just one step but a couple of steps. Hence, the probability that you would end up on node document 3 from document 1 after 2 steps is the combination of these probabilities. To calculate the probabilities where a walker would end up after a couple of steps, the following script can help.

v = np.array([1., .0, .0, .0, .0]) # starting point

for step in range(n):

v = np.dot(M, v)

The variable v tells us the probability of the current nodes. As we are starting at document 1, the probability of being at that node is 100%. The dot multiplication is taking this probability and performs a vector multiplication with the probabilities of the next possible node. Hence, we get a vector which tells us the probabilities where we could end up based on the probabilities where we have been before. For the first step, this is simply the first column of M. From there on, we could be at topic 1 or topic 2 and have to multiply this probability with the probabilities of the next paths.


Related Solutions

Consider a particle of mass m that can move in a one-dimensional box of size L...
Consider a particle of mass m that can move in a one-dimensional box of size L with the edges of the box at x=0 and x = L. The potential is zero inside the box and infinite outside. You may need the following integrals: ∫ 0 1 d y sin ⁡ ( n π y ) 2 = 1 / 2 ,  for all integer  n ∫ 0 1 d y sin ⁡ ( n π y ) 2 y = 1...
Consider a particle that is free (U=0) to move in a two-dimensional space. Using polar coordinates...
Consider a particle that is free (U=0) to move in a two-dimensional space. Using polar coordinates as generalized coordinates, solve the differential equation for rho and demonstrate that the trajectory is a straight line.
The distribution function W(x) for a one dimensional random walk gives the probability that an object...
The distribution function W(x) for a one dimensional random walk gives the probability that an object moving randomly in the +x and -x directions is displaced by a distance x after N jumps, each jump of length l. The displacements are normally distributed which means the distribution function is W(x)=(1/sqrt2πσ^2)e^(−(x−<x>)^2)/2σ^2). In the displacement function, <x> is the average displacement <x>=Nl(p−q) and the variance is σ^2=<x^2>−<x>^2=4pqNl2σ^2. The parameter p is the probability of a displacement in the +x direction and q...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply Normalization: (X - Mean) / Deviation
Consider a system of ? point particles obeying quantum mechanics constrained to move in a two-dimensional...
Consider a system of ? point particles obeying quantum mechanics constrained to move in a two-dimensional plane (1 2-D ideal quantum gas) in a microcanonical ensemble. Find a formula for the entropy ? via Ω, the number of microstates with energy ≤ ? and show that it is an extensive property of the system.
*One dimensional infinite potential well - probability at a location An electron moving in a one-...
*One dimensional infinite potential well - probability at a location An electron moving in a one- dimensional infinite square well of width L is trapped in the n = 1 state. Compute the probability of finding the electron within the "volume" ?x = 0.019 L at 0.55 L to three decimal places.
Consider the hypothetical example using game theory. Assume that it is a one-off simultaneous move game,...
Consider the hypothetical example using game theory. Assume that it is a one-off simultaneous move game, and that each player only cares about their own payoff. LG and Samsung are deciding whether or not to release a new 360-degree camera. If both LG and Samsung release the camera, then LG will make $20 million profit, and Samsung will make $40 million profit. If LG releases the camera, and Samsung does not, then LG will make $30 million profit and Samsung...
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
1. Calculate the probability of locating an electron in a one-dimensional box of length 2.00 nm...
1. Calculate the probability of locating an electron in a one-dimensional box of length 2.00 nm and nx=4 between 0 and 0.286 nm. The probability is also plotted. You should compare (qualitatively) your numerical answer to the area under the curve on the graph that corresponds to the probability.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT