def test1(): mat_contents = sio.loadmat(pathdat + 'dict_pca_2fa_2freq.mat') #dict_pca coeff = np.array(mat_contents["coeff"].astype(np.float32)) par = mat_contents["par"] batch_size = 800 Nk = par[0]['irfreq'][0][0][0] #892#far.shape[0]#par.irfreq# Ndiv = coeff.shape[1] #par[0]['ndiv'][0][0][0]#16 Nscan = 3 orig_Ndiv = coeff.shape[0] // Nscan npar = 8 ## model = tf_wrap.tf_model_top([None, Ndiv], [None, npar], tf_prediction_func, tf_optimize_func, tf_error_func, arg=0.5) #model.restore(pathdat + 'test_model_save_2fa_2freq') fa1 = 45.0 #par[0]['fa1'][0][0][0].astype(np.float32)#35#30 #deg fa2 = 30.0 #par[0]['fa2'][0][0][0].astype(np.float32) tr = par[0]['tr'][0][0][0].astype(np.float32) #3.932#4.337 #ms ti = par[0]['ti'][0][0][0].astype(np.float32) #11.0 #ms te = par[0]['te'][0][0][0].astype(np.float32) #1.5 #ms far, trr, ter = simut.rftr_const(Nk, 1.0, tr, te) M0 = simut.def_M0() #run tensorflow on cpu, count of gpu = 0 config = tf.ConfigProto() #(device_count = {'GPU': 0}) #allow tensorflow release gpu memory config.gpu_options.allow_growth = True t1t2_group = np.zeros((4, 2), dtype=np.float64) t1t2_group[0, 0] = 600.0 / 5000.0 #600 #0.12 t1t2_group[0, 1] = 40.0 / 500.0 #40 #0.08 t1t2_group[1, 0] = 1000.0 / 5000.0 #1000 #0.2 t1t2_group[1, 1] = 80.0 / 500.0 #80 #0.16 t1t2_group[2, 0] = 3000.0 / 5000.0 #3000 #0.6 t1t2_group[2, 1] = 200.0 / 500.0 #200 #0.4 t1t2_group[3, 0] = 0.0 / 5000.0 t1t2_group[3, 1] = 0.0 / 500.0 for i in range(1000000): batch_ys = np.random.uniform(0, 1, (batch_size, npar)).astype(np.float64) batch_ys[:, 2] = np.random.uniform(0, 1.0 / tr, (batch_size)).astype( np.float64) #np.zeros(batch_size)# batch_ys_tmp = np.random.uniform(0, 4, (batch_size)) for k in range(batch_size): if batch_ys_tmp[k] <= 4 and batch_ys_tmp[k] > 3: batch_ys[k, 0] = t1t2_group[0, 0] + np.random.uniform( -0.05, 0.025) #0.07 to 0.145 batch_ys[k, 1] = t1t2_group[0, 1] + np.random.uniform( -0.05, 0.025) #0.04 to 0.105 batch_ys[k, 4] = 1.0 batch_ys[k, 5] = 0.0 batch_ys[k, 6] = 0.0 elif batch_ys_tmp[k] <= 3 and batch_ys_tmp[k] > 2: batch_ys[k, 0] = t1t2_group[1, 0] + np.random.uniform( -0.035, 0.035) #-0.035,0.035 #0.145 to 0.255 batch_ys[k, 1] = t1t2_group[1, 1] + np.random.uniform( -0.035, 0.035) #0.105 to 0.215 batch_ys[k, 4] = 0.0 batch_ys[k, 5] = 1.0 batch_ys[k, 6] = 0.0 elif batch_ys_tmp[k] <= 2 and batch_ys_tmp[k] > 1: batch_ys[k, 0] = t1t2_group[2, 0] + np.random.uniform( -0.15, 0.25) #-0.15,0.25 #0.45 to 0.85 batch_ys[k, 1] = t1t2_group[2, 1] + np.random.uniform( -0.15, 0.25) #0.55 to 0.65 batch_ys[k, 4] = 0.0 batch_ys[k, 5] = 0.0 batch_ys[k, 6] = 1.0 else: batch_ys[k, 0] = t1t2_group[3, 0] #+ np.random.uniform(-0.0,0.02) batch_ys[k, 1] = t1t2_group[3, 1] #+ np.random.uniform(-0.0,0.08) batch_ys[k, 4] = 0.0 batch_ys[k, 5] = 0.0 batch_ys[k, 6] = 0.0 T1r, T2r, dfr, PDr = ssmrf.set_par(batch_ys[..., 0:4]) b1r = 2.0 * batch_ys[..., 7] + 0.5 batch_xs_c1 = ssmrf.bloch_sim_batch_cuda3(batch_size, 100, Nk, PDr, T1r, T2r, dfr, b1r, M0, trr, ter, fa1 * far, ti) batch_xs_c2 = ssmrf.bloch_sim_batch_cuda3(batch_size, 100, Nk, PDr, T1r, T2r, dfr, b1r, M0, trr, ter, fa2 * far, ti) #batch_xs_c3 = ssmrf.bloch_sim_batch_cuda2( batch_size, 100, Nk, PDr, T1r, T2r, dfr, M0, trr, ter, np.absolute(fa2*far), ti ) batch_xs_c3 = ssmrf.bloch_sim_batch_cuda3(batch_size, 100, Nk, PDr, T1r, T2r, dfr + 107.0, b1r, M0, trr, ter, fa2 * far, ti) #ut.plot(np.absolute(batch_xs_c[0,:])) batch_xs = np.zeros((batch_size, Nscan * orig_Ndiv), dtype=batch_xs_c1.dtype) if orig_Ndiv is not Nk: batch_xs[:, 0:orig_Ndiv] = ( simut.average_dict(batch_xs_c1, orig_Ndiv) ) #(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) batch_xs[:, orig_Ndiv:2 * orig_Ndiv] = ( simut.average_dict(batch_xs_c2, orig_Ndiv) ) #(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) batch_xs[:, 2 * orig_Ndiv:3 * orig_Ndiv] = ( simut.average_dict(batch_xs_c3, orig_Ndiv) ) #(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) batch_xs = batch_xs + np.random.ranf(1)[0] * np.random.uniform( -0.002, 0.002, (batch_xs.shape)) batch_xs = np.absolute(batch_xs) if 1: batch_xs = np.dot(batch_xs, coeff) else: batch_xs = batch_xs for dd in range(batch_xs.shape[0]): tc1 = batch_xs[dd, :] normtc1 = np.linalg.norm(tc1) if normtc1 > 0.01: batch_xs[dd, :] = tc1 else: batch_ys[dd, :] = np.zeros([1, npar]) batch_xs = batch_xs / np.ndarray.max(batch_xs.flatten()) model.test(batch_xs, batch_ys) model.train(batch_xs, batch_ys) if i % 100 == 0: prey = model.prediction(batch_xs, np.zeros(batch_ys.shape)) for nn in range(npar): ut.plot(prey[..., nn], batch_ys[..., nn], line_type='.', pause_close=1) model.save(pathdat + 'test_model_save_b1_2fa_2freq')
def test1(): mat_contents = sio.loadmat(pathdat + 'dict_pca.mat') #dict_pca #dictall = np.array(mat_contents["avedictall"].astype(np.float32)) #label = np.array(mat_contents["dict_label"].astype(np.float32)) coeff = np.array(mat_contents["coeff"].astype(np.float32)) #cn_orders = np.array(mat_contents["cn_orders"].astype(np.float32)) par = mat_contents["par"] batch_size = 800 Nk = par[0]['irfreq'][0][0][0] #892#far.shape[0]#par.irfreq# Ndiv = coeff.shape[1] #par[0]['ndiv'][0][0][0]#16 orig_Ndiv = coeff.shape[0] npar = 4 model = tf_wrap.tf_model_top([None, Ndiv], [None, npar], tf_prediction_func, tf_optimize_func, tf_error_func, arg=0.5) fa = par[0]['fa'][0][0][0].astype(np.float32) #35#30 #deg tr = par[0]['tr'][0][0][0].astype(np.float32) #3.932#4.337 #ms ti = par[0]['ti'][0][0][0].astype(np.float32) #11.0 #ms #print(fa) #print(tr) #print(ti) #print(Nk) #print(Ndiv) far, trr = simut.rftr_const(Nk, fa, tr) M0 = simut.def_M0() #run tensorflow on cpu, count of gpu = 0 config = tf.ConfigProto() #(device_count = {'GPU': 0}) #allow tensorflow release gpu memory config.gpu_options.allow_growth = True for i in range(1000000): batch_ys = np.random.uniform(0, 1, (batch_size, 4)).astype(np.float64) #batch_ys[:,0] = batch_ys[:,0] + 1.0*batch_ys[:,1]/10.0 #batch_ys[:,0] = np.random.uniform(0.07,1.0,(batch_size)).astype(np.float64) #batch_ys[:,1] = np.random.uniform(0.0,0.2,(batch_size)).astype(np.float64) batch_ys[:, 2] = np.random.uniform(0, 1.0 / tr, (batch_size)).astype(np.float64) #batch_ys[:,2] = np.zeros(batch_size) #batch_ys[:,3] = np.ones(batch_size)#np.random.uniform(0.4,1,(batch_size)).astype(np.float64)# #batch_ys[:,0] = np.round(batch_ys[:,0]*20)/20 #batch_ys[:,1] = np.round(batch_ys[:,1]*20)/20 #batch_ys[:,2] = np.round(batch_ys[:,2]*20)/20 #batch_ys[:,3] = np.round(batch_ys[:,3]*5)/5 #batch_ys[:,3] = np.round(batch_ys[:,3]*5)/5 # intial seq simulation with t1t2b0 values #seq_data = ssad.irssfp_arrayin_data( batch_size, Nk ).set( batch_ys ) T1r, T2r, dfr, PDr = ssmrf.set_par(batch_ys) batch_xs_c = ssmrf.bloch_sim_batch_cuda(batch_size, 100, Nk, PDr, T1r, T2r, dfr, M0, trr, far, ti) #ut.plot(np.absolute(batch_xs_c[0,:])) if orig_Ndiv is not Nk: batch_xs = np.absolute( simut.average_dict(batch_xs_c, orig_Ndiv) ) #(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) #batch_xs = np.absolute(simut.average_dict_cnorders(batch_xs_c, cn_orders)) #np.absolute(np.dot(batch_xs_c, cn_orders)) else: batch_xs = np.absolute(batch_xs_c) #ut.plot(np.absolute(batch_xs[0,:])) batch_xt = batch_xs batch_xs = batch_xs + np.random.ranf(1)[0] * np.random.uniform( -0.1, 0.1, (batch_xs.shape)) #batch_xs = batch_xs/np.ndarray.max(batch_xs.flatten()) if 1: batch_xs = np.dot(batch_xs, coeff) batch_xt = np.dot(batch_xt, coeff) else: batch_xs = batch_xs batch_xt = batch_xs #batch_ys[:,3] = np.zeros(batch_size) for dd in range(batch_xs.shape[0]): tc1 = batch_xs[dd, :] #- np.mean(imall[i,:]) tc2 = batch_xt[dd, :] normtc1 = np.linalg.norm(tc1) normtc2 = np.linalg.norm(tc2) if normtc2 > 0.1: #and batch_ys[dd,0]*5000 > 3*500*batch_ys[dd,1] and batch_ys[dd,0]*5000 < 20*500*batch_ys[dd,1] batch_xs[dd, :] = tc1 #/normtc1 batch_xt[dd, :] = tc2 #/normtc2 else: # batch_xs[dd,:] = np.zeros([1,Ndiv]) # batch_xt[dd,:] = np.zeros([1,Ndiv]) batch_ys[dd, :] = np.zeros([1, npar]) batch_xs = batch_xs / np.ndarray.max(batch_xs.flatten()) batch_xt = batch_xt / np.ndarray.max(batch_xt.flatten()) #for kk in range(batch_xs.shape[1]): # batch_xs [:,kk] = (batch_xs[:,kk])/np.std(batch_xs[:,kk] )#- np.mean(batch_xs[:,kk]) # batch_xt [:,kk] = (batch_xt[:,kk])/np.std(batch_xt[:,kk] )#- np.mean(batch_xt[:,kk]) #ut.plot(np.real(batch_xs[0,:]),pause_close = 1) #batch_ys[:,3] = np.ones(batch_size) * np.random.ranf(1)[0] #batch_xs = batch_xs * batch_ys[0,3] #* np.random.ranf(1)[0]# model.test(batch_xs, batch_ys) model.train(batch_xt, batch_ys) model.train(batch_xs, batch_ys) if i % 100 == 0: prey = model.prediction(batch_xs, np.zeros(batch_ys.shape)) ut.plot(prey[..., 0], batch_ys[..., 0], line_type='.', pause_close=1) ut.plot(prey[..., 1], batch_ys[..., 1], line_type='.', pause_close=1) ut.plot(prey[..., 2], batch_ys[..., 2], line_type='.', pause_close=1) ut.plot(prey[..., 3], batch_ys[..., 3], line_type='.', pause_close=1) model.save(pathdat + 'test_model_save')
def test1(): mat_contents = sio.loadmat(pathdat+'dict_pca.mat');#dict_pca #dictall = np.array(mat_contents["avedictall"].astype(np.float32)) #label = np.array(mat_contents["dict_label"].astype(np.float32)) coeff = np.array(mat_contents["coeff"].astype(np.float32)) #cn_orders = np.array(mat_contents["cn_orders"].astype(np.float32)) par = mat_contents["par"] batch_size = 800 Nk = par[0]['irfreq'][0][0][0]#892#far.shape[0]#par.irfreq# Ndiv = coeff.shape[1]#par[0]['ndiv'][0][0][0]#16 orig_Ndiv = coeff.shape[0] npar = 7 model = tf_wrap.tf_model_top([None, Ndiv], [None, npar], tf_prediction_func, tf_optimize_func, tf_error_func, arg = 0.5) fa = par[0]['fa'][0][0][0].astype(np.float32)#35#30 #deg tr = par[0]['tr'][0][0][0].astype(np.float32)#3.932#4.337 #ms ti = par[0]['ti'][0][0][0].astype(np.float32)#11.0 #ms te = 1.5 #ms #print(fa) #print(tr) #print(ti) #print(Nk) #print(Ndiv) far, trr,ter = simut.rftr_const(Nk, fa, tr, te) M0 = simut.def_M0() #run tensorflow on cpu, count of gpu = 0 config = tf.ConfigProto()#(device_count = {'GPU': 0}) #allow tensorflow release gpu memory config.gpu_options.allow_growth=True t1t2_group = np.zeros((4, 2),dtype = np.float64) t1t2_group[0,0] = 600.0/5000.0 t1t2_group[0,1] = 40.0/500.0 t1t2_group[1,0] = 1000.0/5000.0 t1t2_group[1,1] = 80.0/500.0 t1t2_group[2,0] = 3000.0/5000.0 t1t2_group[2,1] = 200.0/500.0 t1t2_group[3,0] = 0.0/5000.0 t1t2_group[3,1] = 0.0/500.0 for i in range(1000000): batch_ys = np.random.uniform(0,1,(batch_size,npar)).astype(np.float64) batch_ys[:,2] = np.zeros(batch_size)#np.random.uniform(0,1.0/tr,(batch_size)).astype(np.float64) batch_ys_tmp = np.random.uniform(0,4,(batch_size)) for k in range(batch_size): if batch_ys_tmp[k] <= 4 and batch_ys_tmp[k] > 3: batch_ys[k,0] = t1t2_group[0,0] + np.random.uniform(-0.05,0.025) batch_ys[k,1] = t1t2_group[0,1] + np.random.uniform(-0.05,0.025) batch_ys[k,4] = 1.0 batch_ys[k,5] = 0.0 batch_ys[k,6] = 0.0 elif batch_ys_tmp[k] <= 3 and batch_ys_tmp[k] > 2: batch_ys[k,0] = t1t2_group[1,0] + np.random.uniform(-0.025,0.025) batch_ys[k,1] = t1t2_group[1,1] + np.random.uniform(-0.025,0.025) batch_ys[k,4] = 0.0 batch_ys[k,5] = 1.0 batch_ys[k,6] = 0.0 elif batch_ys_tmp[k] <= 2 and batch_ys_tmp[k] > 1: batch_ys[k,0] = t1t2_group[2,0] + np.random.uniform(-0.15,0.25) batch_ys[k,1] = t1t2_group[2,1] + np.random.uniform(-0.15,0.25) batch_ys[k,4] = 0.0 batch_ys[k,5] = 0.0 batch_ys[k,6] = 1.0 else: batch_ys[k,0] = t1t2_group[3,0] batch_ys[k,1] = t1t2_group[3,1] batch_ys[k,4] = 0.0 batch_ys[k,5] = 0.0 batch_ys[k,6] = 0.0 T1r, T2r, dfr, PDr = ssmrf.set_par(batch_ys[...,0:4]) batch_xs_c = ssmrf.bloch_sim_batch_cuda2( batch_size, 100, Nk, PDr, T1r, T2r, dfr, M0, trr, ter, far, ti ) #ut.plot(np.absolute(batch_xs_c[0,:])) if orig_Ndiv is not Nk: batch_xs = np.absolute(simut.average_dict(batch_xs_c, orig_Ndiv))#(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) else: batch_xs = np.absolute(batch_xs_c) #ut.plot(np.absolute(batch_xs[0,:])) #batch_xt = batch_xs batch_xs = batch_xs + np.random.ranf(1)[0]*np.random.uniform(-0.1,0.1,(batch_xs.shape)) #batch_xs = batch_xs/np.ndarray.max(batch_xs.flatten()) if 1: batch_xs = np.dot(batch_xs, coeff) #batch_xt = np.dot(batch_xt, coeff) else: batch_xs = batch_xs #batch_xt = batch_xs for dd in range(batch_xs.shape[0]): tc1 = batch_xs[dd,:] #- np.mean(imall[i,:]) #tc2 = batch_xt[dd,:] normtc1 = np.linalg.norm(tc1) #normtc2 = np.linalg.norm(tc2) if normtc1 > 0.05: #and batch_ys[dd,0]*5000 > 3*500*batch_ys[dd,1] and batch_ys[dd,0]*5000 < 20*500*batch_ys[dd,1] batch_xs[dd,:] = tc1#/normtc1 #batch_xt[dd,:] = tc2#/normtc2 else: # batch_xs[dd,:] = np.zeros([1,Ndiv]) # batch_xt[dd,:] = np.zeros([1,Ndiv]) batch_ys[dd,:] = np.zeros([1,npar]) batch_xs = batch_xs/np.ndarray.max(batch_xs.flatten()) #batch_xt = batch_xt/np.ndarray.max(batch_xt.flatten()) #for kk in range(batch_xs.shape[1]): # batch_xs [:,kk] = (batch_xs[:,kk])/np.std(batch_xs[:,kk] )#- np.mean(batch_xs[:,kk]) # batch_xt [:,kk] = (batch_xt[:,kk])/np.std(batch_xt[:,kk] )#- np.mean(batch_xt[:,kk]) #ut.plot(np.real(batch_xs[0,:]),pause_close = 1) #batch_xs = batch_xs * batch_ys[0,3] #* np.random.ranf(1)[0]# model.test(batch_xs, batch_ys) model.train(batch_xs, batch_ys) if i % 100 == 0: prey = model.prediction(batch_xs,np.zeros(batch_ys.shape)) ut.plot(prey[...,0], batch_ys[...,0], line_type = '.', pause_close = 1) ut.plot(prey[...,1], batch_ys[...,1], line_type = '.', pause_close = 1) ut.plot(prey[...,2], batch_ys[...,2], line_type = '.', pause_close = 1) ut.plot(prey[...,3], batch_ys[...,3], line_type = '.', pause_close = 1) ut.plot(prey[...,4], batch_ys[...,4], line_type = '.', pause_close = 1) model.save(pathdat + 'test_model_save')
def test1(): mat_contents = sio.loadmat(pathdat + 'dict_pca.mat') #dict_pca #dictall = np.array(mat_contents["avedictall"].astype(np.float32)) #label = np.array(mat_contents["dict_label"].astype(np.float32)) par = mat_contents["par"] read_coeff_flag = 1 # 0 not use coeff; 1 read coeff from mat file; 2 generate coeff by pca abs_flag = 0 #apply pca on absolute time course batch_size = 800 Nk = par[0]['irfreq'][0][0][0] #892#far.shape[0]#par.irfreq# if read_coeff_flag is 1: coeff = np.array(mat_contents["coeff"].astype(np.float32)) Ndiv = coeff.shape[1] #Nk #par[0]['ndiv'][0][0][0]#16 orig_Ndiv = coeff.shape[0] #Nk elif read_coeff_flag is 2: Ndiv = 20 #20 pca orig_Ndiv = Nk #coeff.shape[0]#Nk else: Ndiv = Nk #coeff.shape[1]#Nk #par[0]['ndiv'][0][0][0]#16 orig_Ndiv = Nk #coeff.shape[0]#Nk npar = 4 model = tf_wrap.tf_model_top([None, Ndiv], [None, npar], tf_prediction_func, tf_optimize_func, tf_error_func) fa = par[0]['fa'][0][0][0].astype(np.float32) #35#30 #deg tr = par[0]['tr'][0][0][0].astype(np.float32) #3.932#4.337 #ms ti = par[0]['ti'][0][0][0].astype(np.float32) #11.0 #ms #print(fa) #print(tr) #print(ti) #print(Nk) #print(Ndiv) far, trr = simut.rftr_const(Nk, fa, tr) #far,trr = simut.rftr_rand(Nk, fa, tr, 2*tr) M0 = simut.def_M0() #run tensorflow on cpu, count of gpu = 0 config = tf.ConfigProto() #(device_count = {'GPU': 0}) #allow tensorflow release gpu memory config.gpu_options.allow_growth = True #compute pca if read_coeff_flag is 2: batch_ys = np.random.uniform(0, 1, (batch_size, 4)).astype(np.float64) #batch_ys[:,0] = np.random.uniform(0.1,0.6,(batch_size)).astype(np.float64) #batch_ys[:,1] = np.random.uniform(0.1,0.3,(batch_size)).astype(np.float64) #batch_ys[:,2] = np.random.uniform(0,1.0/tr,(batch_size)).astype(np.float64) #batch_ys[:,3] = np.random.uniform(0.1,1.0,(batch_size)).astype(np.float64)# np.ones(batch_size)## np.random.uniform(0.5,1,(batch_size)).astype(np.float64)# # intial seq simulation with t1t2b0 values npca = Ndiv T1r, T2r, dfr, PDr = ssmrf.set_par(batch_ys) batch_xs_c = ssmrf.bloch_sim_batch_cuda(batch_size, 100, Nk, PDr, T1r, T2r, dfr, M0, trr, far, ti) #ut.plot(np.absolute(batch_xs_c[0,:]),pause_close =1) if orig_Ndiv < Nk: batch_xs = simut.average_dict( batch_xs_c, orig_Ndiv ) #(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) else: batch_xs = batch_xs_c pca_mtx = np.dot(np.matrix(batch_xs).getH(), batch_xs) U, s, V = scipy.sparse.linalg.svds(pca_mtx, npca) coeff = U[:, npca - 1::-1] sio.savemat(pathdat + 'MRF_pca_coeff.mat', { 'coeff': coeff, 'dict': batch_xs }) for i in range(1000000): batch_ys = np.random.uniform(0, 1, (batch_size, 4)).astype(np.float64) #batch_ys[:,0] = np.random.uniform(0.1,0.6,(batch_size)).astype(np.float64) #batch_ys[:,1] = np.random.uniform(0.1,0.3,(batch_size)).astype(np.float64) batch_ys[:, 2] = np.random.uniform(0, 1.0 / tr, (batch_size)).astype(np.float64) #batch_ys[:,3] = np.ones(batch_size)#np.random.uniform(0.1,1.0,(batch_size)).astype(np.float64)# # np.random.uniform(0.5,1,(batch_size)).astype(np.float64)# #batch_ys[:,2] = np.zeros(batch_size) #batch_ys[:,2] = np.random.uniform(0.19,0.21,(batch_size)).astype(np.float64)#0.2*np.ones(batch_size) # intial seq simulation with t1t2b0 values #seq_data = ssad.irssfp_arrayin_data( batch_size, Nk ).set( batch_ys ) T1r, T2r, dfr, PDr = ssmrf.set_par(batch_ys) batch_xs_c = ssmrf.bloch_sim_batch_cuda(batch_size, 100, Nk, PDr, T1r, T2r, dfr, M0, trr, far, ti) #ut.plot(np.absolute(batch_xs_c[0,:]),pause_close =1) if orig_Ndiv < Nk: batch_xs = simut.average_dict( batch_xs_c, orig_Ndiv ) #(np.dot(np.absolute(simut.average_dict(batch_xs_c, Ndiv)), coeff)) else: batch_xs = batch_xs_c batch_xs = batch_xs + np.random.ranf(1)[0] * np.random.uniform( -0.005, 0.005, (batch_xs.shape)) #batch_xs = batch_xs/np.ndarray.max(batch_xs.flatten()) if read_coeff_flag is 1: if abs_flag: batch_xs = np.dot(np.absolute(batch_xs), coeff) else: batch_xs = np.absolute(np.dot(batch_xs, coeff)) elif read_coeff_flag is 2: batch_xs = np.absolute(np.dot(batch_xs, coeff)) else: batch_xs = np.absolute(batch_xs) for dd in range(batch_xs.shape[0]): tc1 = batch_xs[dd, :] #- np.mean(imall[i,:]) normtc1 = np.linalg.norm(tc1) if normtc1 > 0.04 and batch_ys[dd, 0] * 5000 > 3 * 500 * batch_ys[ dd, 1]: batch_xs[dd, :] = tc1 #/normtc1 else: batch_ys[dd, :] = np.zeros([1, npar]) batch_xs = 1000 * batch_xs #ut.plot(np.absolute(batch_xs[0,:]),pause_close =1) #batch_ys[:,2] = np.zeros(batch_size) #batch_ys[:,3] = np.zeros(batch_size) model.train(batch_xs, batch_ys) model.test(batch_xs, batch_ys) if i % 100 == 0: prey = model.prediction(batch_xs, np.zeros(batch_ys.shape)) ut.plot(prey[..., 0], batch_ys[..., 0], line_type='.', pause_close=1) ut.plot(prey[..., 1], batch_ys[..., 1], line_type='.', pause_close=1) ut.plot(prey[..., 2], batch_ys[..., 2], line_type='.', pause_close=1) ut.plot(prey[..., 3], batch_ys[..., 3], line_type='.', pause_close=1) model.save(pathdat + 'test_model_savecnn')