示例#1
0
b2 = b2.reshape((1, ))

h1 = np.tanh(np.matmul(x_mat, W1) + b1)
y_mat = np.matmul(h1, W2) + b2

np.random.seed(NOISE_SEED)
y_mat_noise = y_mat + np.random.normal(0, NOISE_LEVEL, y_mat.shape)
log_seed = LOG_NAME + '_' + str(NOISE_SEED)

prada(x_mat=x_mat,
      y_mat=y_mat_noise,
      NP_SEED=OPT_SEED,
      TF_SEED=OPT_SEED,
      BATCH_DIV=5,
      LOAD_APDX=None,
      DIM_H1=dim_h1,
      EPOCHS=epochs1,
      LBDAS=[0, 0],
      GAMMAS=[0, 0],
      STEP_SIZE=0,
      PRINT=False,
      LOG_NAME=log_seed,
      SAVE_XY=False)
os.system('bash ../copy_params.sh phase1_' + log_seed + ' ' + log_seed)

mse, _, fcts, n_nodes, n_links = prada(x_mat=x_mat,
                                       y_mat=y_mat_noise,
                                       NP_SEED=OPT_SEED,
                                       TF_SEED=OPT_SEED,
                                       BATCH_DIV=5,
                                       LOAD_APDX='phase1_' + log_seed,
                                       DIM_H1=dim_h1,
示例#2
0
from prada_net import prada

#Simulate data
np.random.seed(0)
x_mat = np.random.uniform(-1, 1, (1000, 5))
y_mat = x_mat[:,0] \
      + 0.5*(3*np.square(x_mat[:,1])-1) \
      + 0.5*(5*np.power(x_mat[:,2],3)-3*x_mat[:,2]) \
      + 0.125*(35*np.power(x_mat[:,3],4)-30*np.square(x_mat[:,3])+3)
y_mat = y_mat.reshape((len(y_mat), 1))

#use optimal seeds for plot and graph
np.random.seed(24)
y_mat += np.random.normal(0, .1, y_mat.shape)  #add noise

prada(x_mat=x_mat,
      y_mat=y_mat,
      TF_SEED=4,
      NP_SEED=4,
      BATCH_DIV=5,
      LOAD_APDX=None,
      DIM_H1=50,
      EPOCHS=[5000, 5000, 1000, 0],
      LBDAS=[1.1, 1e-5],
      GAMMAS=[2., 2.],
      STEP_SIZE=1e-5,
      SIGMA_MAX=1e-2,
      PRINT=True)
os.system('bash ../copy_params.sh l1')
os.system('Rscript ../make_graph.R l1')
示例#3
0
else:
  PHASE=1

if 'SLURM_SUBMIT_DIR' in os.environ:
  slurm_root=os.environ['SLURM_SUBMIT_DIR']+'/'
else:
  slurm_root=''

#Simulate data
NOISE_LEVEL=0.1
np.random.seed(0)
x_mat = np.random.uniform(-1,1,(1000,5))
y_mat = x_mat[:,0] \
      + 0.5*(3*np.square(x_mat[:,1])-1) \
      + 0.5*(5*np.power(x_mat[:,2],3)-3*x_mat[:,2]) \
      + 0.125*(35*np.power(x_mat[:,3],4)-30*np.square(x_mat[:,3])+3)
y_mat = y_mat.reshape((len(y_mat),1))

y_mat_noise = y_mat + np.random.normal(0,NOISE_LEVEL,y_mat.shape)
log_seed = LOG_NAME+'_'+str(BOOT_SEED)

if PHASE==1:
  #first phase 
  prada(x_mat=x_mat, y_mat=y_mat_noise, NP_SEED=BOOT_SEED, TF_SEED=OPT_SEED, BATCH_DIV=5, LOAD_APDX=None, DIM_H1=50, EPOCHS=[5000,0,0,0], LBDAS=[0, 1e-5],GAMMAS=[2,2], STEP_SIZE=1e-5, PRINT=False, RETURN=False, LOG_NAME=log_seed)
  os.system('bash ../copy_params.sh phase1_'+log_seed+' '+log_seed)
else:
  #rest
  mse,_,_,_,_=prada(x_mat=x_mat, y_mat=y_mat_noise, NP_SEED=BOOT_SEED, TF_SEED=OPT_SEED, BATCH_DIV=5, LOAD_APDX='phase1_'+log_seed, DIM_H1=50, EPOCHS=[00,2000,300,0], LBDAS=[LBDA, 1e-5],GAMMAS=[2,2], STEP_SIZE=1e-5, PRINT=False, RETURN=True, LOG_NAME=log_seed)
  with open(slurm_root+'logs/'+LOG_NAME+'.txt', 'a+') as f:
    f.write(';'.join(map(str,(BOOT_SEED, OPT_SEED, LBDA, mse))) + '\n')