def _run_mscale(cdir, animation=ANIMATION): outdir = "%s_viz/" % (cdir) tl.mkdir("%s" % outdir) #--------------------------------# # (1) load modelDBs, Snaps mdbHs = {} SnapsHs = {} CGHs = {} outdirHs = {} for i in range(0, MSCALE_H): outdirHs[i] = "%s_Level%d/" % (outdir, i) tl.mkdir("%s" % outdirHs[i]) mdbHs[i] = tl.load_obj('%s_Level%d/MDB.obj' % (cdir, i)) SnapsHs[i] = tl.load_mat('%s_Level%d/Snaps.mat' % (cdir, i)) CGHs[i] = tl.load_obj('%s_Level%d/CGs.obj' % (cdir, i)) #--------------------------------# # (2) save multi-scale (LOCAL) arg_list = [] for i in range(0, MSCALE_H): arg_list.append([SnapsHs[i], mdbHs[i], CGHs[i], outdirHs[i]]) if (MULTI): _multi_save_all_L(arg_list) else: for i in range(0, MSCALE_H): _save_all_L(SnapsHs[i], mdbHs[i], CGHs[i], outdirHs[i]) #--------------------------------# # (3) save Xorg-cast (GLOBAL) Xorg = tl.loadsq('%sXorg.txt' % cdir).T # load Xorg Snaps = _save_all_G(Xorg, outdir, SnapsHs, mdbHs, outdir)
def _create_multiscale_seqs(Xorg, lstep, mscale_h, outdir): tl.msg("_create_multiscale_seq (lstep: %d, mscale_h: %d)"%(lstep, mscale_h)) tl.save_seq_txt_pdf(Xorg, "%sXorg"%outdir) # multi-scale sequences XHs={}; Xagg=tl.dcopy(Xorg); outdirHs={} wdHs={} # window size list for i in range(0,mscale_h): # window size at i-th level if(i<mscale_h-1): wdHs[i]=lstep*(2**(mscale_h-1-i)) # if HT=4: 3,2,1 ... (i.e., 8xlstep, 4xlstep, 2xlstep, 1) #if(i<mscale_h-1): wdHs[i]=lstep*(2**(mscale_h-2-i)) # if HT=4: 2,1,0 ... (i.e., 4xlstep, 2xlstep, lstep, 1) #if(i<mscale_h-1): wdHs[i]=lstep*(2**(mscale_h-3-i)) # if HT=4: 1,0,-1 ... (i.e., 2xlstep, lstep, 1/2xlstep, 1 else: wdHs[i]=1 # if, last seq for i in range(0,mscale_h): XHs[i]=tl.smoothWMAo(Xagg, wdHs[i]) # compute i-th level Xagg=Xagg-XHs[i] # delete current scale for i in range(0,mscale_h): #XHs[i]= XHs[i][int(wdHs[0]):,:] # delete longest-window XHs[i][0:int(wdHs[0]),:]=tl.NAN # delete longest-window outdirHs[i]='%s_Level%d/'%(outdir,i); tl.mkdir(outdirHs[i]) # directory # save sequence at i-th level tl.save_txt(XHs[i], '%sXorg.txt'%(outdirHs[i])) # save data tl.plt.clf(); tl.plt.plot(XHs[i]) # plot and save figure tl.savefig("%sXorg"%(outdirHs[i]), 'pdf') tl.msg("wdHs: ") tl.msg(wdHs) return (XHs, wdHs, outdirHs)
def _run_single(cdir, animation=ANIMATION): outdir = "%s_viz/" % (cdir) tl.mkdir("%s" % outdir) #--------------------------------# # (1) load modelDBs, Snaps mdb = tl.load_obj('%sMDB.obj' % (cdir)) Snaps = tl.load_mat('%sSnaps.mat' % (cdir)) CG = tl.load_obj('%sCGs.obj' % (cdir)) # (2) save results _save_all_L(Snaps, mdb, CG, outdir)
for i in range(para['dup']): print('-------start {}-------'.format(i)) tmp = simulation1(para) res1.append(tmp[0]) res2.append(tmp[1]) res3.append(tmp[2]) res4.append(tmp[3]) print('-------end {}-------'.format(i)) print(' ') """ 统计数据所用,保存成csv """ res1 = np.array(res1).reshape(-1, 1) res2 = np.array(res2).reshape(-1, 1) res3 = np.array(res3) res4 = np.array(res4) res = np.hstack((res1, res2, res3, res4)) res = pd.DataFrame(res, columns=['pro_RE', 'ori_RE', 'pro_A', 'pro_B', 'pro_C', 'ori_A', 'ori_B', 'ori_C']) print(res.mean()) save_path = 'result/Non supervision/' tool.mkdir(save_path) res.to_csv(save_path + 'size{}.csv'.format(para['I1']), sep=',', index=False) print('Done!')
def run_est_single(Xorg, lstep, outdir, wd_level=1): #--------------------------------# want_refinement = tl.YES #--------------------------------# mdb_cb = om_mdb.MDB('%s' % outdir) # create modelDB Snaps_cb = init_Snaps(Xorg, lstep, wd_level) # SnapShots mdb_cb = mdb_cb.update_Xminmax(Xorg) errF_cb = tl.INF #; Snaps_cb=[]; if (RHO_INIT == -1): rho_iter = _compute_rho_min(Xorg, lstep) else: rho_iter = RHO_INIT ERRs_full = [] ERRs_cb_i = [] outdir_tr = "%s_trials/" % outdir if (SAVE_TRIALS): tl.mkdir(outdir_tr) # create directory tl.msg("(%d) run_est_single: start trial (find opt rho) ..." % wd_level) for i_trial in range(0, MAXTRIAL): #--------------------------------# mdb_i = tl.dcopy(mdb_cb) Snaps_i = tl.dcopy(Snaps_cb) #--------------------------------# # set rho, cleansing (e.g., remove inappropriate regimes), etc. mdb_i.update_rho(rho_iter) (mdb_i, Snaps_i) = mdb_i.update_apoptosis(Snaps_i, AP_MD, AP_MS, want_refinement) mdb_i = mdb_i.init_objects() #--------------------------------# # start OrbitMap (mdb_i, Snaps_i) = _OrbitMap(Xorg, lstep, wd_level, mdb_i, "%sTrial_%d_" % (outdir_tr, i_trial), SAVE_TRIALS, SAVE_TRIALS) #tl.YES) #tl.NO) #--------------------------------# if (i_trial > 0 and Snaps_i['errF_half'] < errF_cb): # update best-fit (if trial > 0) errF_cb = Snaps_i['errF_half'] mdb_cb = tl.dcopy(mdb_i) Snaps_cb = tl.dcopy(Snaps_i) #--------------------------------# tl.msg( "(mscale-wd: %d) Trial %d rho=%f, c=%d, errE: %f, errF(half):%f, errF(full):%f" % (wd_level, i_trial, rho_iter, mdb_i.get_c(), Snaps_i['errE'], Snaps_i['errF_half'], Snaps_i['errF'])) ERRs_full.append([ i_trial, rho_iter, mdb_i.get_c(), Snaps_i['errE'], Snaps_i['errF_half'], Snaps_i['errF'] ]) tl.save_txt(ERRs_full, "%s_trials_results.txt" % (outdir)) #--------------------------------# if (EARLYSTOP and Snaps_i['errF_half'] >= errF_cb and i_trial >= MINTRIAL): break # if, no more better-fit, break if (mdb_i.get_c() <= 1 and i_trial > 0): break # if, # of regimes is less than one, then, stop #--------------------------------# #--------------------------------# rho_iter *= RHO_ITER_R_BU # rho: try larger value #--------------------------------# # final-best-fit (mdb_cb, Snaps_cb) = mdb_cb.update_apoptosis(Snaps_cb, AP_MD, AP_MS, want_refinement) mdb_cb = mdb_cb.init_objects() if (Snaps_cb['errF_half'] > Snaps_cb['errS']): mdb_cb.CC = tl.NO # if, not approp. (no causalchain), ignore model (mdb_cb, Snaps_cb) = _OrbitMap(Xorg, lstep, wd_level, mdb_cb, "%s" % (outdir), tl.YES, tl.YES) tl.msg("best est: c=%d, errE: %f, errF(half):%f, errF(full):%f" % (mdb_cb.get_c(), Snaps_cb['errE'], Snaps_cb['errF_half'], Snaps_cb['errF'])) return (mdb_cb, Snaps_cb)
#---------------# # main # #---------------# if __name__ == "__main__": tl.msg("om_trans") (DIR, st, wd, ncast, smin, cid) = _syn() #(DIR, st, wd, ncast, smin, cid) = _mocap_c() #(DIR, st, wd, ncast, smin, cid) = _mocap_c2() mdbfn = "%sMDB.obj" % (DIR) seqfn = "%sXorg.txt" % (DIR) OUTDIR = "%sout/" % (DIR) tl.mkdir(OUTDIR) tl.eprint(OUTDIR) mdb = tl.load_obj(mdbfn) # Xorg = tl.loadsq(seqfn).T #snapsfn="%sSnaps.mat"%(DIR) #Snaps=tl.load_mat(snapsfn) #print(len(mdb.MS)) #tl.eprint(Snaps['Re_full']) #tl.eprint(np.shape(Snaps['Re_full'])) #''' for k in mdb.MS: #print(mdb.MS) print(k) print(mdb.MS[k][0]['medoid']['cpt'])
mscale = args.mscale else: mscale = 1 # single-scale #--- print args ---# tl.comment('main_om.py - args') tl.msg("-------------------------") tl.msg("input-seqfn: [%s]" % iseqfn) tl.msg("ls-step-ahead: [%d]" % lstep) tl.msg("multi-scale: [%d]" % mscale) tl.msg("outdir: [%s]" % outdir) tl.msg("model dir (scan): [%s]" % mdir) tl.msg("t_st (opt): [%s]" % my_tst) tl.msg("duration (opt): [%s]" % my_n) tl.msg("-------------------------") try: tl.mkdir("%s" % outdir) except: tl.error("cannot find: %s" % outdir) #------------------------------# # LOAD DATA #------------------------------# data = tl.loadsq(iseqfn).T data = data[my_tst:, :] (n, d) = np.shape(data) #--- set data length (my_n) optional ---# if (my_n < n): data = data[0:my_n, :] (n, d) = np.shape(data) tl.msg("(n,d)=(%d,%d)" % (n, d)) Xorg = data # original data