Issue
Let us assume a loop like below:
import numpy as np
ax = []; ay = []
for n in range(N):
avgC = np.zeros(M)
for m in range(M):
...
Cost = aFuncation
avgC[m] = Cost
ax.append(n); ay.append(np.mean(avgC))
I would like to use ax
and ay
to plot a live time series which shows how np.mean(avgC)
evolves over different iterations of n
. At the same time, I would like to plot the standrad deviation of the distribution according to avgC
(a figure like below example).
Solution
First you should think about what the term "confidence interval" actually means in your case. To construct confidence intervals, you must specify for what quantity you construct the confidence interval, and you should give more background information how the values are distributed in your case. I assume for now, that your "Cost" values are normal distributed and you want the mean and standard deviation of the distribution plotted at each point n
. Note that this is not the confidence interval on the mean. If you are unsure about this, you should probably edit your question and include more detailed information on the statistical properties of your investigation.
That being said, with this code you can plot the mean and a standard deviation band at each point n
:
import numpy as np
import matplotlib.pyplot as plt
N = 25
M = 10
def aFuncation(x):
return np.random.normal(100*np.exp(-x), 10.0)
ax = np.zeros(N)
ay = np.zeros(N)
astd = np.zeros(N)
for n in range(N):
avgC = np.zeros(M)
for m in range(M):
Cost = aFuncation(n)
avgC[m] = Cost
ax[n] = n
ay[n] = np.mean(avgC)
astd[n] = np.std(avgC)
plt.fill_between(ax, ay-astd, ay+astd, alpha=0.3, color='black')
plt.plot(ax,ay,color='red')
plt.show()
Answered By - Jakob Stark
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.