def finalize(cls): print '%14.7e %14.7e'%tuple(loadnpy('m_new')) m_new = loadnpy('m_new') m_old = loadnpy('m_old') d = np.linalg.norm(m_new-m_old)/np.linalg.norm(m_new) if d < 1.e-5: print 'Stopping criteria met.\n' sys.exit()
def finalize(cls): m_new = loadnpy('m_new') m_old = loadnpy('m_old') if PAR.VERBOSE > 0: print '%14.7e %14.7e'%tuple(m_new) if cls.status(m_new, m_old): print 'Test successful: stopping criteria met.\n' np.savetxt('niter', [cls.iter], '%d') sys.exit(0) elif cls.iter >= PAR.END: print 'Maximum number of iterations exceeded.\n' sys.exit(-1)
def write_model(self, path='', suffix=''): """ Writes model in format used by solver """ unix.mkdir(path) src = PATH.OPTIMIZE +'/'+ 'm_' + suffix dst = path +'/'+ 'model' parts = solver.split(loadnpy(src)) solver.save(dst, parts)
def write_model(self, path='', suffix=''): """ Writes model in format used by solver """ unix.mkdir(path) src = PATH.OPTIMIZE + '/' + 'm_' + suffix dst = path + '/' + 'model' parts = solver.split(loadnpy(src)) solver.save(dst, parts)
def compute_direction_newton(cls): optimize.initialize_newton() for ilcg in range(PAR.LCGMAX): m = loadnpy('m_lcg') g = problem.grad(m) savenpy('g_lcg', g) isdone = optimize.iterate_newton() if isdone: break
def evaluate_gradient(cls): m = loadnpy('m_new') f = problem.func(m) g = problem.grad(m) savetxt('f_new', f) savenpy('g_new', g) if PAR.OPTIMIZE in ['SRVM']: optimize.update_SRVM()
def save_model(self): src = PATH.OPTIMIZE +'/'+ 'm_new' dst = join(PATH.OUTPUT, 'model_%04d' % optimize.iter) parts = solver.split(loadnpy(src)) vp_min, vp_max = 300,3750 vs_min, vs_max = 50,2800 #for key in ['vp', 'vs']: # for iproc in range(PAR.NPROC): # if key == 'vp': # np.clip(parts[key][iproc], vp_min, vp_max) # if key == 'vs': # np.clip(parts[key][iproc], vs_min, vs_max) solver.save(dst, parts)
def Phase2_se(syn, nt, dt, ft_obs, freq_mask): # waveform difference in the frequency domain, considering orthogonal frequencies nstep = len(syn) wadj = 0.0 #np.zeros(nstep) ntpss = PAR.NTPSS #create a frequential mask m = loadnpy(PATH.ORTHO + '/freq_idx') ft_syn = fft(syn[-ntpss:])[m] obs = ft_syn / ft_obs phase = np.vectorize(cmath.phase) phase_obs = phase(obs) wadj = (freq_mask * phase_obs**2).sum() return wadj
def split(self, file, path, suffix): """ Split numpy arrays into separate vectors and save to binary files for solver. """ npar = len(self.parameters) ipar = 0 # load numpy file nv = loadnpy(file) n = int(len(nv) / npar) for par in self.parameters: v = nv[(ipar*n):(ipar*n) + n] v = extend_pml_velocities(v, p.nx, p.nz, p.ncpml, p.use_cpml_left, p.use_cpml_right, p.use_cpml_top, p.use_cpml_bottom) filename = join(path, par + suffix) self.save(filename, v) ipar += 1
def save_model(self): src = PATH.OPTIMIZE + '/' + 'm_new' dst = join(PATH.OUTPUT, 'model_%04d' % optimize.iter) solver.save(dst, solver.split(loadnpy(src)))
def load(self, filename): return loadnpy(PATH.OPTIMIZE + '/' + filename)
def save_model(self): src = PATH.OPTIMIZE +'/'+ 'm_new' dst = join(PATH.OUTPUT, 'model_%04d' % optimize.iter) solver.save(dst, solver.split(loadnpy(src)))
def load(self, filename): # reads vectors from disk return loadnpy(PATH.OPTIMIZE+'/'+filename)
def load(self, filename): # reads vectors from disk return loadnpy(PATH.OPTIMIZE + '/' + filename)
def evaluate_function(cls): m = loadnpy('m_try') f = problem.func(m) savetxt('f_try',f) print f
def evaluate_gradient(cls): m = loadnpy('m_new') f = problem.func(m) g = problem.grad(m) savetxt('f_new', f) savenpy('g_new', g)
def evaluate_function(cls): m = loadnpy('m_try') f = problem.func(m) savetxt('f_try', f)
def evaluate_gradient(cls): m = loadnpy('m_new') f = problem.func(m) g = problem.grad(m) savetxt('f_new',f) savenpy('g_new',g)