Question: Using Python 3 Using Python 3 Using Python 3 The task is to optimize your solution by using line_profiler. Your submission will contain two jupyter
Using Python 3
Using Python 3
Using Python 3


The task is to optimize your solution by using "line_profiler". Your submission will contain two jupyter notebook files: your first (original) solution an optimized solution by using line_profiler both of which will include the line_profiler results. The problem is to simulate the following dynamical scenario. There is a unit square [0, 1]2. The time is discrete = 0, 1, 2, .. .. At every time stem there are n points within the square; call these positions Xo, X1, X2, , x 1 . At t = 0 positions of the points are randomly and uniformly distributed. At every time step t 2 0, we calculate L(t) which corresponds to a path length that one would need to myopically traverse all n points. In other words, L(t) is calculated as follows: Mark all points non-visited. Among all the n points, choose uniformly one point, and mark it visited. Then iteratively traverse the non-visited points while visiting the closest point. Denote by L(t) the distance of such a path. Algorithmically it as: let path length 0 mark all the n points non-visited; pick one point, uniformly at random; call it previous_point, and mark the previous_point visited; Then repeat (n -1) times 1. pick the point among the non-visited points, which is the closest to the previous_point, and call it current point; 2. calculate the Euclidean distance between the current_point and the previous_point; 3. increment path length by that distance; 4. mark the current point as visited; 5. re-label the current_point to be the previous point. Your myopic path-lenght L(t) := path-length. Now, one would like to examine how a random perturbation of a fraction of the positions can change the value of L(t) over time t0, 1,2,.... That is, given an integer T, which corresponds to the number of iterations, n the number of points, and alpha which is fraction of points you perturb at new time step, your function will return and plot the values: L(0), L(1), , L(T-1). To do so: Set t-0: at time t, calculate L(t); at the next time step t1, you pick uniformly int(a - n) points which you will perturb; . assign these int(a , n) points random positions within the unit square; calculate new L(t); and repeat T times. Your main function should look like: def main(n, alpha, T): "n: there are n points in the unit square alpha: alpha is the portion of points you redistribute at every time step T: number of iterations return: length_array: list of caluclated values L(O), L(1),dots, L(T-1) plot the diagram L(t) for t-, 1,..,T-1 " return length array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
