def analyze(self, adjust=False, plot=False, learn=False, adjustparams={}, learnparams={'feature_opt':'1storder', 'coeforder':1}):
        dataman = DataIO(self.case) 
        fu, gridvars, ICparams = dataman.loadSolution(self.loadnamenpy, array_opt='marginal')
        
        ##Make fu smaller (in time)
        if adjust:
            fu, gridvars = self.adjust(fu, gridvars, adjustparams)
        grid = PdfGrid(gridvars)

        if plot:
            V = Visualize(grid)
            V.plot_fu3D(fu)
            V.plot_fu(fu, dim='t', steps=5)
            V.plot_fu(fu, dim='x', steps=5)
            V.show()

        if learn:
            t0 = time.time()
            print('fu dimension: ', fu.shape)
            print('fu num elem.: ', np.prod(fu.shape))

            feature_opt = learnparams['feature_opt'] 
            coeforder = learnparams['coeforder'] 
            sindy_alpha = learnparams['sindy_alpha']
            RegCoef = learnparams['RegCoef']
            nzthresh = learnparams['nzthresh']
                
            # Learn     
            difflearn = PDElearn(grid=grid, fu=fu, ICparams=ICparams, scase=self.case, trainratio=0.8, debug=False, verbose=True)
            difflearn.fit_sparse(feature_opt=feature_opt, variableCoef=True, variableCoefBasis='simple_polynomial', \
                    variableCoefOrder=coeforder, use_sindy=True, sindy_alpha=sindy_alpha, RegCoef=RegCoef, nzthresh=nzthresh)
            
            print('learning took t = ', str(t0 - time.time()))
Esempio n. 2
0
def burgers():
    loadnamenpy = 'burgersMC_9601.npy'  # PDF - triangles
    loadnamenpy = 'burgersMC_6095.npy'  # CDF - triangles

    loadnamenpy = 'burgersMC_4147.npy'  # PDF - gaussians
    #loadnamenpy = 'burgersMC_5042.npy' # CDF - gaussians

    case = loadnamenpy.split('_')[0]

    dataman = DataIO(case)
    fu, gridvars, ICparams = dataman.loadSolution(loadnamenpy)
    grid = PdfGrid(gridvars)

    # Learn
    difflearn = PDElearn(grid=grid,
                         fu=fu,
                         ICparams=ICparams,
                         scase=case,
                         trainratio=0.7,
                         debug=False,
                         verbose=True)
    difflearn.fit_sparse(feature_opt='1storder',
                         variableCoef=True,
                         variableCoefBasis='simple_polynomial',
                         variableCoefOrder=1,
                         use_sindy=True,
                         sindy_alpha=0.01,
                         shuffle=False)
Esempio n. 3
0
def advection():
    #loadnamenpy = 'advection_marginal_7397.npy'
    loadnamenpy = 'advection_marginal_6328.npy'
    loadnamenpy = 'advection_marginal_8028.npy'
    loadnamenpy = 'advection_marginal_5765.npy'
    #loadnamenpy = 'advection_marginal_4527.npy'

    case = '_'.join(loadnamenpy.split('_')[:2])

    dataman = DataIO(case)
    fuk, fu, gridvars, ICparams = dataman.loadSolution(loadnamenpy)
    grid = PdfGrid(gridvars)

    V = Visualize(grid)
    V.plot_fuk3D(fuk)
    V.plot_fu3D(fu)
    V.plot_fu(fu, dim='t', steps=5)
    V.plot_fu(fu, dim='x', steps=5)
    V.show()

    # Learn
    difflearn = PDElearn(fuk,
                         grid,
                         fu=fu,
                         ICparams=ICparams,
                         scase=case,
                         trainratio=0.8,
                         debug=False,
                         verbose=True)
    difflearn.fit_sparse(feature_opt='2ndorder',
                         variableCoef=True,
                         variableCoefBasis='simple_polynomial',
                         variableCoefOrder=3,
                         use_sindy=True,
                         sindy_alpha=0.001)
Esempio n. 4
0
def advection_reaction():
    loadnamenpy = 'advection_reaction_9987.npy'  # PDF - gaussians
    #loadnamenpy = 'advection_reaction_5739.npy' # PDF - gaussians
    case = '_'.join(loadnamenpy.split('_')[:2])

    dataman = DataIO(case)
    fu, gridvars, ICparams = dataman.loadSolution(loadnamenpy)

    # Make fu smaller (in time)
    tt = np.linspace(
        gridvars['t'][0], gridvars['t'][1],
        round((gridvars['t'][1] - gridvars['t'][0]) / gridvars['t'][2]))
    period = 6
    indexes = np.array([i * period for i in range((len(tt)) // period)])
    ttnew = tt[indexes]
    fu = fu[:, :, indexes]
    gridvars['t'][1] = ttnew[-1]
    gridvars['t'][2] = (ttnew[-1] - ttnew[0]) / len(ttnew)

    grid = PdfGrid(gridvars)
    # Learn
    difflearn = PDElearn(grid=grid,
                         fu=fu,
                         ICparams=ICparams,
                         scase=case,
                         trainratio=0.8,
                         debug=False,
                         verbose=True)
    difflearn.fit_sparse(feature_opt='1storder',
                         variableCoef=True,
                         variableCoefBasis='simple_polynomial',
                         variableCoefOrder=2,
                         use_sindy=True,
                         sindy_alpha=0.005,
                         shuffle=False)
Esempio n. 5
0
def reaction():
    #loadnamenpy = 'reaction_linear_2204.npy'
    #loadnamenpy = 'reaction_linear_6632.npy'
    loadnamenpy = 'reaction_linear_5966.npy'

    case = '_'.join(loadnamenpy.split('_')[:2])

    dataman = DataIO(case)
    fu, gridvars, ICparams = dataman.loadSolution(loadnamenpy)
    grid = PdfGrid(gridvars)

    # Learn
    difflearn = PDElearn(grid=grid,
                         fu=fu,
                         ICparams=ICparams,
                         scase=case,
                         trainratio=0.8,
                         debug=False,
                         verbose=True)
    difflearn.fit_sparse(feature_opt='1storder',
                         variableCoef=True,
                         variableCoefBasis='simple_polynomial',
                         variableCoefOrder=2,
                         use_sindy=True,
                         sindy_alpha=0.1)
Esempio n. 6
0
    def learn(self):
        dataman = DataIO(self.case)
        fu, gridvars, ICparams = dataman.loadSolution(self.loadnamenpy,
                                                      array_opt='marginal')
        grid = PdfGrid(gridvars)

        feature_opt = '1storder'
        coeforder = 2

        # Learn
        difflearn = PDElearn(grid=grid,
                             fu=fu,
                             ICparams=ICparams,
                             scase=self.case,
                             trainratio=0.8,
                             debug=False,
                             verbose=True)
        difflearn.fit_sparse(feature_opt=feature_opt, variableCoef=True, variableCoefBasis='simple_polynomial', \
                variableCoefOrder=coeforder, use_sindy=True, sindy_alpha=0.001)
Esempio n. 7
0
	# BUILD PDF
	MCprocess = MCprocessing(savenameMC, case=case)
	savenamepdf = MCprocess.buildKDE(nu, distribution=distribution, MCcount=MCcount, save=save, u_margin=u_margin, bandwidth=bandwidth)

	# LEARN
	dataman = DataIO(case, directory=PDFDIR) 
	fu, gridvars, ICparams = dataman.loadSolution(savenamepdf, array_opt='marginal')

	adjustgrid = {'mu':mu, 'mx':mx, 'mt':mt, 'pu':pu, 'px':px, 'pt':pt}
	grid = PdfGrid(gridvars)
	fu = grid.adjust(fu, adjustgrid)

	difflearn = PDElearn(grid=grid, fu=fu, ICparams=ICparams, scase=case, trainratio=trainratio, verbose=printlearning)
	filename = difflearn.fit_sparse(feature_opt=feature_opt, variableCoef=variableCoef, variableCoefBasis=variableCoefBasis, \
	        variableCoefOrder=coeforder, use_rfe=use_rfe, rfe_alpha=rfe_alpha, nzthresh=nzthresh, maxiter=maxiter, \
	        LassoType=LassoType, RegCoef=RegCoef, cv=cv, criterion=criterion, print_rfeiter=print_rfeiter, shuffle=shuffle, \
	        basefile=savenamepdf, adjustgrid=adjustgrid, save=save, normalize=normalize, comments=comments)

	# Save Learning
	D = DataIO(case, directory=LEARNDIR)
	output, metadata = D.readLearningResults(filename)

	output_vec.append(output)	
	metadata_vec.append(metadata)
	filename_vec.append(filename)

print('files = [')
for f in filename_vec:
	print("\'"+f+"\',")
print(']')
Esempio n. 8
0
    RegCoef = 0.000004
    maxiter = 10000

    if "savenamepdf" not in locals():
        # Check if there is already a loadfile (if not load it)
        savenamepdf = 'advection_reaction_analytical_717_944.npy'
        dataman = DataIO(case)
        fu, gridvars, ICparams = dataman.loadSolution(savenamepdf,
                                                      array_opt='marginal')

    grid = PdfGrid(gridvars)
    fu = grid.adjust(fu, aparams)

    if plot:
        s = 10
        V = Visualize(grid)
        V.plot_fu3D(fu)
        V.plot_fu(fu, dim='t', steps=s)
        V.plot_fu(fu, dim='x', steps=s)
        V.show()

    difflearn = PDElearn(grid=grid,
                         fu=fu,
                         ICparams=ICparams,
                         scase=case,
                         trainratio=0.8,
                         debug=False,
                         verbose=True)
    difflearn.fit_sparse(feature_opt=feature_opt, variableCoef=True, variableCoefBasis='simple_polynomial', \
            variableCoefOrder=coeforder, use_sindy=True, sindy_alpha=sindy_alpha, RegCoef=RegCoef, nzthresh=nzthresh, maxiter=maxiter)
                                                partial_data=True,
                                                MCcount=MCcount,
                                                save=False,
                                                plot=False,
                                                distribution=distribution)

    grid = PdfGrid(gridvars)
    difflearn = PDElearn(grid=grid,
                         fu=fu,
                         ICparams=ICparams,
                         scase=case,
                         trainratio=0.8,
                         debug=False,
                         verbose=True)
    coef, featurenames, trainRMSE, testRMSE, trainScore, testScore = difflearn.fit_sparse(feature_opt='1storder', \
            variableCoef=True, variableCoefBasis='simple_polynomial', variableCoefOrder=1, \
            use_sindy=True, sindy_alpha=0.001, shuffle=False)

    coefvec.append(coef)
    featurenamesvec.append(featurenames)
    trainRMSEvec.append(trainRMSE)
    testRMSEvec.append(testRMSE)
    trainScorevec.append(trainScore)
    testScorevec.append(testScore)

savedata = {
    'coefvec': coefvec,
    'featurenamesvec': featurenamesvec,
    'trainRMSEvec': trainRMSEvec,
    'testRMSEvec': testRMSEvec,
    'trainScorevec': trainScorevec,