2

Is it possible to find fluctuations in a list, such that ones graph reaches a certain peak, it will start fluctuating between two values that are unknown.

I was considering to focus on all the numbers above the threshold

sum of numbers above thershold

I've wrote bit of python code to simulate this issues. The graph firstly increases to n value and it will fluctuate between two values m and k. enter image description here

Background:

The code is simulating a compartmental SIS model on a temporal network. That is each node of that is in one of the compartments (Susceptible - Infected - Susceptible). The infection spreads by each infected node tryign to infect neighbouring node with probability enter image description here and recover with probability enter image description here at each time step.

The infection will die out if it's below the threshold enter image description here where enter image description here. So what the code does, it runs in a while(True) loop checking if the infection dies out, and if it is above the coverage of infected is 40%. Between those two if statements, the infection goes into a steady state, that is it's above the threshold but below 40% coverage, and it fluctuates for infinite amount of time. I'm trying to find a way to find those fluctuations in a list.

The code for simulating this situation (the graph):

import random
import numpy as np
import matplotlib.pyplot as plt

n = 10
m = 11
k = 17

a = np.arange(0, n, 1)
a = np.asarray(a)
for i in range(100):
    a = np.append(a, random.randint(m, k))

plt.plot(a)
plt.show()
5
  • I'm unable to discern what you are asking for that is beyond the code that you have already created. Commented May 12, 2018 at 8:41
  • Well the code is only suppose to show/simulate the fluctuations. What I'm trying to find is a way to return True or False if there is a fluctuation in a list, in the code I provided that would be list 'a' Commented May 12, 2018 at 8:47
  • I'm also stuck on finding fluctuations in a list, and then going into steady state. Does that not mean that a list of values already exists and, if a fluctuation is found, there'd still potentially be other pre-existing values in that list beyond the index you identified? At what point are values being generated vs. being analysed? Commented May 12, 2018 at 8:47
  • I think my brain is being caught up in the terminology that you've used. The entire list is being generated and for each new element added to the list, you check previous elements to see whether you're now at a point of changing the way you generate random numbers? Commented May 12, 2018 at 8:51
  • The values are generated in the while(True) loop. So they will either increase or decrease and at one point it will hit the part where the values fluctuate. So yes @roganjosh I'm using the entire list and trying to find a point at which the values fluctuate. Commented May 12, 2018 at 9:12

1 Answer 1

2

The region in which the solution is oscillating can be detected by the presence of relative maxima and minima. The Signal Processing module of SciPy has several methods for finding those. Example:

from scipy.signal import argrelmin, argrelmax
extrema = np.concatenate((argrelmin(a)[0], argrelmax(a)[0]))
print((extrema.min(), extrema.max()))

prints (12, 108) for your simulated data, the beginning and end of oscillations. The beginning marks the switch from growth to oscillation, the end is just the end of observations.

This simple approach is not suitable for situations where oscillation is superimposed on a growth/decay pattern, like the function f(x) = x + 2*sin(x). But from your description of the data it seems to be enough.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.