示例#1
0
def update(val):
    gamma = sgamma.val
    alpha = salpha.val
    beta = sbeta.val
    G = sG.val
    n = min(sn.val, G)
    nsteps = int(snsteps.val)
    lambdaval = int(slambda.val)
    deltaval = int(sdelta.val)
    # re-do the plot
    ax = subplot(111)
    data = loadGroupData.load_data(data_N)
    t_data = range(len(data[0]))
    # clear old plot
    cla()

    yvals = myfun(gamma, alpha, beta, G, n, nsteps, lambdaval, deltaval)
    #t = range(len(yvals))
    #t = [ float(item)/nsteps for item in t]
    t = range(len(yvals[0]))
    # assert len(yvals)==len(t), "unequal lengths for plotting"
    #print '----------------------------'
    #print yvals
    plot(t_data, data[3], 'r+')
    plot(t_data, data[1], 'b+')
    plot(t, yvals[0], lw=2, color='blue')
    plot(t, yvals[1], lw=2, color='black')
    plot(t, yvals[2], lw=2, color='red')
    ptitle= "Wechat Group g=%2.2f a=%2.2f b=%2.2f init=%2.2f , nsteps=%3d" % \
    (gm0, a0, b0, n0/G0, nsteps0)
    title(ptitle)
    xlabel("time")
    ylabel("value")
    axis([0, nsteps, 0, G + 50])
    draw()
示例#2
0
csvfile = file('../../rawresult/simpleSIR.csv', 'rb')
reader = csv.reader(csvfile)
params = list()
comermse = list()
atrmse = list()
gormse = list()
for line in reader:
	params.append(line)
test = list()

total = 135621
for i in range(total):
	#print i
	if i % 1000 == 0:
		print i
	rawdata = loadGroupData.load_data(i)
	at = list()
	for j in range(length):
		at.append(float(rawdata[1][j]) - float(rawdata[3][j]))

	come = numpy.array(rawdata[1][:length])
	go = numpy.array(rawdata[3][:length])
	result = list()
	#res = getCurve(params[i], 0)
	t1, t2 = getCurve(params[i], 0, len(come))
	temp = rmse(t1, come)
	s1 += temp
	result.append(temp)
	come = [k/float(params[i][2]) for k in come]
	temp = rmse(t2, come)
	result.append(temp)
示例#3
0
import loadGroupData
import optGroupData
import disGroupData
from lmfit import report_fit

traindays = 20
begin = 0
end = 135621
mode = 0  #[0, 1, 2, 3, 4, 5] for [multi, single, SIRd, SIR, SI, SpikeM]
name = ['multi', 'single', 'SIRd', 'SIR', 'SI']

fw = open('../../' + name[mode] + '_res/params.csv', 'w')
for i in range(begin, end):
    rawdata = loadGroupData.load_data(i)
    result = optGroupData.optimize(rawdata, mode)
    report_fit(result.params)
    fw.write(str(i) + ',')
    fw.write(str(result.params))
    fw.write('\n')
    path = '../../' + name[mode] + '/'
    #disGroupData.display_bi(rawdata,result,result_test,path+str(i)+'.png')
    p = disGroupData.display(rawdata, result, path + str(i) + '.png', mode)
    if peaks.has_key(p):
        peaks[p] += 1
    else:
        peaks[p] = 1
    print 'No.' + str(i) + ' items finished.(' + name[i] + ')'
fw.close()
print peaks
示例#4
0
b0 = 0.05  # beta default
G0 = 300  # matches the Glass-Mackey for white blood cells
n0 = 10  # matches GM
nsteps0 = 50
lambda0 = 0
delta0 = 1

s = myfun(gm0, a0, b0, G0, n0, nsteps0, lambda0, delta0)
# create the horizontal axis
t = range(len(s[0]))
print "duration = ", len(s) / nsteps0
#t = [ float(item)/nsteps0 for item in t]
# l, = plot(t,s, lw=2, color='red')
# l = plot(t,s, lw=2, color='red')
data_N = 8
data = loadGroupData.load_data(data_N)
t_data = range(len(data[0]))

plot(t_data, data[0], 'b+')
plot(t_data, data[1], 'r+')

plot(t, s[0], lw=2, color='blue')
plot(t, s[1], lw=2, color='black')
plot(t, s[2], lw=2, color='red')
xlabel("time")
ylabel("value")
ptitle= "Wechat Group g=%2.2f a=%2.2f b=%2.2f init=%2.2f , nsteps=%3d" % \
    (gm0, a0, b0, n0/G0, nsteps0)
title(ptitle)
axis([0, nsteps0, 0, G0 + 50])
示例#5
0
import loadGroupData
import optGroupData
import disGroupData
from lmfit import report_fit

traindays = 20  #how many days used to train(42 for all)
begin = 0    #start with which group
end = 135622    #end with which group
mode = 0 #[0, 1, 2, 3, 4] for [multi, single, SIRd, SIR, SI]
name = ['multi', 'single', 'SIRd', 'SIR', 'SI']

fw=open('../../' + name[mode] + '_res/params.csv','w')
for i in range(begin, end):
    rawdata=loadGroupData.load_data(i, traindays)
    result=optGroupData.optimize(rawdata, mode)
    report_fit(result.params)
    fw.write(str(result.params))
    fw.write('\n')
    path='../../'+name[mode]+'/'
    #disGroupData.display_bi(rawdata,result,result_test,path+str(i)+'.png')
    print 'No.' + str(i) + ' items finished.('+name[i]+')'
fw.close()
print peaks
示例#6
0
def getItem(order, mode):
    rawdata = loadGroupData.load_data(i)
    result = optGroupData.optimize(rawdata, mode)
    return str(result.params)