def errorInterpreter(self, errCode): header = "HomotopySolver::" if errCode & 0b001: print header, "Max number of iteration reached" if errCode >> 1 & 0b010: y = self.yeq y[self.ndimA - 1] = 1 print header, "Not valid equilibrium::H(x,1)=", linalg.norm( self._PC_F(y), 2)
def _correctorSteps(self,y0,b): err = 10 count = 0 while err>self.epsCorr and count<1e2: F = self._PC_F(y0) dF = self._PC_DF(y0) A = np.append(dF,b,axis=0) B = A.dot(y0) - np.append(F,[[0]],axis=0) ynew = linalg.solve(A,B) err = linalg.norm(F,2) y0 = ynew count = count + 1 print "Correction err:", err return (y0,err)
def _predictorSteps(self,y0): err = 0.0 d = y0 count = 0 y00 = y0 h = self.hStep while err<self.epsPred: F = self._PC_F(y0) dF = self._PC_DF(y0) d = linalg.null_space(dF) #kernel of the Jacobian #d = d/linalg.norm(d,2) #Normalization of the kernel if d[-1,0]<0: d = -d ynext = y0 + h * d err = linalg.norm(F,2) y0 = ynext print h,self.epsPred,err return (y0,np.transpose(d)) # return the prediction step and a vector orthogonal to the kernel
epsPred = 9e-3 #Prediction error epsCorr = 1e-9 #Correction error maxSteps = 5e2 #Max number of steps thrPrune = .01 lstm = LSTMNN(None) weights = readFromPickle(data_input_file) weights, pPrune = pruneW(weights, thrPrune) lstm.updateWeigths(weights) ndim = 2 * lstm.dimOfOutput() x0 = np.zeros([ndim, 1]) lstm.setInitStat(x0) print("dim = ", str(ndim)) (t, x, eCode) = lstm.findEquilibria(epsPred, epsCorr, maxSteps) xeq = lstm.refineTheEquilibria(x) xeq = np.array([xeq]).T lstm.errorInterpreter(eCode) print("||F(xeq)-xeq|| = ", linalg.norm(xeq - lstm.F(xeq), 2)) tmp_out = {'xeq': xeq, 'prTh': thrPrune} scipyio.savemat(output_eq_file, tmp_out)
def isValidEquilibrium(self, ErrTol): y = self.yeq y[self.ndimA - 1] = 1. return linalg.norm(self._PC_F(y), 2) < ErrTol
[x[0, 0], x[1, 0]**2]]) x0 = np.array([[0], [0]]) hStep = 1e-3 epsPred = 1e-5 epsCorr = 1e-9 ndim = 2 maxSteps = 1e4 PT = PolyTest(x0, ndim, epsPred, epsCorr, hStep, maxSteps) (y, errCode) = PT.runSolver() print errCode print y PT.errorInterpreter(errCode) if ~(errCode >> 1 & 0b010): y[-1] = 1 print "Valid equilibrium::H(x,1)=", linalg.norm(PT._PC_F(y), 2) if test == 2: data_input_file = 'demo/data/PTB_0/save_10v2.pkl' epsPred = 1e-3 epsCorr = 1e-9 maxSteps = 1e5 lstm = LSTMNN(data_input_file) #lstm.makeOutputsAsInputs() ndim = 2 * lstm.dimOfOutput() #x0 = np.random.uniform(-1,1,[ndim,1]) x0 = np.zeros([ndim, 1]) lstm.setInitStat(x0) (t, x, eCode) = lstm.findEquilibria(epsPred, epsCorr, maxSteps)