Ejemplo n.º 1
0
    def fit(self):

        # Kill off some not as good terms
        # self.termwise_Rsquared()

        # Load up the residual Helmholtz term with parameters
        n = helmholtz.vectord(self.N0)
        d = helmholtz.vectord(self.D0)
        t = helmholtz.vectord(self.T0)
        l = helmholtz.vectord(self.L0)
        self.phir = helmholtz.phir_power(n, d, t, l, 1, len(self.N0) - 1)

        # Solve for the coefficients
        Nbounds = [(-10, 10) for _ in range(len(self.N0))]
        tbounds = [(-1, 30) for _ in range(len(self.T0))]
        print(self.OBJECTIVE(np.array(list(self.N0))))
        #self.N = self.N0
        #self.N = scipy.optimize.minimize(self.OBJECTIVE, np.array(list(self.N0)), bounds = Nbounds, options = dict(maxiter = 5)).x
        self.N = scipy.optimize.minimize(self.OBJECTIVE, np.array(list(self.N0)), method='L-BFGS-B', bounds=Nbounds, options=dict(maxiter=100)).x

        # Write the coefficients to HDF5 file
        h = h5py.File('fit_coeffs.h5', 'w')
        grp = h.create_group(self.Ref)
        grp.create_dataset("n", data=np.array(self.N), compression="gzip")
        print(self.N)
        #grp.create_dataset("t", data = np.array(self.N[len(self.N)//2::]), compression = "gzip")
        h.close()
Ejemplo n.º 2
0
    def fit(self):

        # Kill off some not as good terms
        # self.termwise_Rsquared()

        # Load up the residual Helmholtz term with parameters
        n = helmholtz.vectord(self.N0)
        d = helmholtz.vectord(self.D0)
        t = helmholtz.vectord(self.T0)
        l = helmholtz.vectord(self.L0)
        self.phir = helmholtz.phir_power(n, d, t, l, 1, len(self.N0) - 1)

        # Solve for the coefficients
        Nbounds = [(-10, 10) for _ in range(len(self.N0))]
        tbounds = [(-1, 30) for _ in range(len(self.T0))]
        print(self.OBJECTIVE(np.array(list(self.N0))))
        #self.N = self.N0
        #self.N = scipy.optimize.minimize(self.OBJECTIVE, np.array(list(self.N0)), bounds = Nbounds, options = dict(maxiter = 5)).x
        self.N = scipy.optimize.minimize(self.OBJECTIVE,
                                         np.array(list(self.N0)),
                                         method='L-BFGS-B',
                                         bounds=Nbounds,
                                         options=dict(maxiter=100)).x

        # Write the coefficients to HDF5 file
        h = h5py.File('fit_coeffs.h5', 'w')
        grp = h.create_group(self.Ref)
        grp.create_dataset("n", data=np.array(self.N), compression="gzip")
        print(self.N)
        #grp.create_dataset("t", data = np.array(self.N[len(self.N)//2::]), compression = "gzip")
        h.close()
Ejemplo n.º 3
0
    def termwise_Rsquared(self):

        keepers = []
        values = []
        print('%s terms at start' % len(self.N0))
        for i in range(len(self.N0)):

            n = helmholtz.vectord([float(1)])
            d = helmholtz.vectord([self.D0[i]])
            t = helmholtz.vectord([self.T0[i]])
            l = helmholtz.vectord([self.L0[i]])

            self.phir = helmholtz.phir_power(n, d, t, l, 0, 0)

            PPF = self.evaluate_EOS(np.array(list(n)))

            R2 = rsquared(PPF.p, self.phir.dDeltaV(self.tauV, self.deltaV))

            values.append((R2, i))
            if R2 > 0.9:
                keepers.append(i)

        values, indices = zip(*reversed(sorted(values)))

        keepers = list(indices[0:30])

        self.N0 = self.N0[keepers]
        self.T0 = self.T0[keepers]
        self.D0 = self.D0[keepers]
        self.L0 = self.L0[keepers]

        print('%s terms at end' % len(self.N0))
Ejemplo n.º 4
0
    def termwise_Rsquared(self):

        keepers = []
        values = []
        print('%s terms at start' % len(self.N0))
        for i in range(len(self.N0)):

            n = helmholtz.vectord([float(1)])
            d = helmholtz.vectord([self.D0[i]])
            t = helmholtz.vectord([self.T0[i]])
            l = helmholtz.vectord([self.L0[i]])

            self.phir = helmholtz.phir_power(n, d, t, l, 0, 0)

            PPF = self.evaluate_EOS(np.array(list(n)))

            R2 = rsquared(PPF.p, self.phir.dDeltaV(self.tauV, self.deltaV))

            values.append((R2, i))
            if R2 > 0.9:
                keepers.append(i)

        values, indices = zip(*reversed(sorted(values)))

        keepers = list(indices[0:30])

        self.N0 = self.N0[keepers]
        self.T0 = self.T0[keepers]
        self.D0 = self.D0[keepers]
        self.L0 = self.L0[keepers]

        print('%s terms at end' % len(self.N0))