def __init__ (self, nnupar='',nnvpar='',nnhdyn='', f0=3.5e-5, beta=2.11e-11, gamma=2e-7, gstar=0.02,rho0=1000, H=500, taux0=0.15, tauy0=0, nu=0.72, dt=1800, dx=20e3, dy=20e3, alpha=0.025, nx=80, ny=80 ): SWmodel.__init__(self,f0, beta, gamma, gstar,rho0, H, taux0, tauy0, nu, dt, dx, dy, alpha, nx, ny ) if isinstance(nnupar, str): self._nnupar = loadmymodel(nnupar) self._nnuparname = nnupar else: self._nnupar = nnupar self._nnuparname = '' if isinstance(nnvpar, str): self._nnvpar = loadmymodel(nnvpar) self._nnvparname = nnvpar else: self._nnvpar = nnvpar self._nnvparname = '' if isinstance(nnhdyn, str): self._nnhdyn = loadmymodel(nnhdyn) self._nnhdynname = nnhdyn else: self._nnhdyn = nnhdyn self._nnhdynname = ''
def __init__ (self, nnupar,nnvpar,nout=(1,1),delta=(1,1), f0=3.5e-5, beta=2.11e-11, gamma=2e-7, gstar=0.02,rho0=1000, H=500, taux0=0.15, tauy0=0, nu=0.72, dt=1800, dx=20e3, dy=20e3, alpha=0.025, nx=80, ny=80 ): SWmodel.__init__(self,f0, beta, gamma, gstar,rho0, H, taux0, tauy0, nu, dt, dx, dy, alpha, nx, ny ) if isinstance(nnupar, str): self._nnupar = loadmymodel(nnupar) else: self._nnupar = nnupar if isinstance(nnvpar, str): self._nnvpar = loadmymodel(nnvpar) else: self._nnvpar = nnvpar self._nout = nout self._delta = delta self._nin = tuple(n+2*d for (n,d) in zip(self._nout,self._delta)) #Calculate index of the ouptput image self._indout = MakeSmallImages_ind((self.ny,self.nx), n=self._nout)
Xp = np.empty(shape=(X.shape[:-1]) + (nprod, )) k = 0 for i in range(npar): for j in range(i + 1, npar): Xp[:, :, :, k] = X[:, :, :, i] * X[:, :, :, j] k = k + 1 if 'prod' in netname: X = np.concatenate((X, Xp), axis=3) nt, ny, nx, npar = X.shape #add a extension to the name ext = '' if param in {'u', 'v'}: ext = 'par' nn = loadmymodel(join(outdir, netname, 'model_' + param + ext + '-im.pkl')) y_predict = nn.predict(X) corr = np.corrcoef(y.ravel(), y_predict.ravel())[0, 1] mse = np.mean(np.square(y.ravel() - y_predict.ravel())) title = 'corr=' + '{:3.4f}'.format(corr) + ', mse=' + '{:3.2e}'.format(mse) print(netname, ':', title) if PLOT: plt.plot(y.ravel(), y_predict.ravel(), '.') plt.plot(np.array(y.ravel()), y.ravel(), '-r') plt.title(title) plt.savefig(join(outdir, netname, 'scatter-all.png')) plt.show() plt.semilogy(nn._history['loss'], color='gray') plt.semilogy(nn._history['val_loss'], color='black') plt.savefig(join(outdir, netname, 'history-all.png'))
for i in range(npar): for j in range(i+1,npar): Xp[:,:,:,k] = X[:,:,:,i]*X[:,:,:,j] k=k+1 if 'prod' in netname: X = np.concatenate((X,Xp),axis=3) X_train, X_test, y_train, y_test = \ train_test_split(X, y, test_size=0.1) nt,ny,nx,npar = X.shape if 'fgnet' in locals(): nn = loadmymodel(join(outdir,fgnet,'model_'+param+'-im.pkl')) perturb = 0 else: #Model definition model = Sequential() model.add(Conv2D(64, (3, 3), activation='relu', padding='same',input_shape=(ny,nx,npar))) #model.add(Dropout(0.1)) # model.add(Conv2D(64, (3, 3), activation='relu', # padding='same')) #kernel_regularizer=regularizers.l1(0.001), #) # model.add(Dropout(0.1)) model.add(Conv2D(64, (1, 1), activation='relu')) model.add(Conv2D(32, (1, 1), activation='relu'))