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
data.append(line) csvfile.close() csvfile = file('../../badID.csv', 'rb') reader = csv.reader(csvfile) baddata = list() for line in reader: baddata.append(line) csvfile.close() fw = open('../multi_predict/params.csv','w') for line in data: flag = False for per in baddata: if line[0] == per[0]: flag = True break if flag: continue index = int(line[0]) rawdata = loadGroupData.load_data(index) front = list() for i in range(4): front.append(rawdata[i][:-10]) result=optGroupData.optimize(front) report_fit(result.params) fw.write(str(result.params)) fw.write('\n') path='../multi_predict/' p = disGroupData.display(rawdata,result,path+line[0]+'.png') fw.close() print 'Finished.'
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
rmse = list() for i in range(3): mae.append(list()) rmse.append(list()) fw = open('SIFront.csv', 'w') error = 0 for i in range(2022): if i in badID: print '!' + str(i) continue print i rawdata = loadGroupData.load_data(i) front = list() for j in range(4): front.append(rawdata[j][:-10]) result = optGroupData.optimize(front) m, r = getRes(result.params, rawdata, 0) if len(m) == 0: error += 1 continue temp = list() temp.append(m) temp.append(r) mrfile.append(temp) fw.write(str(result.params)) fw.write('\n') for j in range(3): mae[j].append(m[j]) rmse[j].append(r[j]) fw.close() print error
def getItem(order, mode): rawdata = loadGroupData.load_data(i) result = optGroupData.optimize(rawdata, mode) return str(result.params)