Exemple #1
0
    def minimize(self):
        nreps = self.nrep
        nbins = self.nebins
        visitsT = (self.visits1d)
        #print "min vis", np.min(visitsT)
        self.logP = np.where(visitsT != 0, np.log(visitsT), 0)
        #print "minlogp", np.min(self.logP)
        self.reduced_energy = self.binenergy[np.newaxis, :] / (
            self.Tlist[:, np.newaxis] * self.k_B)

        self.whampot = WhamPotential(self.logP, self.reduced_energy)

        X = np.random.rand(nreps + nbins)
        E = self.whampot.getEnergy(X)
        #print "energy", E

        #print "quenching"
        from wham_utils import lbfgs_scipy
        ret = lbfgs_scipy(X, self.whampot)
        #        try:
        #            from pele.optimize import mylbfgs as quench
        #            ret = quench(X, self.whampot, iprint=-1, maxstep=1e4)
        #        except ImportError:
        #            from pele.optimize import lbfgs_scipy as quench
        #            ret = quench(X, self.whampot)
        #print "quench energy", ret.energy
        X = ret.coords

        self.logn_E = X[nreps:]
        self.w_i_final = X[:nreps]
    def minimize(self):
        nreps = self.nrep
        nbins = self.nebins
        visitsT = (self.visits1d)
        #print "min vis", np.min(visitsT)
        self.logP = np.where( visitsT != 0, np.log( visitsT ), 0 )
        #print "minlogp", np.min(self.logP)
        self.reduced_energy = self.binenergy[np.newaxis,:] / (self.Tlist[:,np.newaxis] * self.k_B)
        
        self.whampot = WhamPotential(self.logP, self.reduced_energy)
        
        
        X = np.random.rand( nreps + nbins )
        E = self.whampot.getEnergy(X)
        #print "energy", E 
        
        #print "quenching"
        from wham_utils import lbfgs_scipy
        ret = lbfgs_scipy(X, self.whampot)
#        try: 
#            from pele.optimize import mylbfgs as quench
#            ret = quench(X, self.whampot, iprint=-1, maxstep=1e4)
#        except ImportError:
#            from pele.optimize import lbfgs_scipy as quench
#            ret = quench(X, self.whampot)            
        #print "quench energy", ret.energy
        X = ret.coords
        
        self.logn_E = X[nreps:]
        self.w_i_final = X[:nreps]
    def minimize(self):
        #shape(visits2d) is now (nqbins, nebins, nreps)
        #we need it to be (nreps, nqbins*nebins)
        #first reorder indices
        nreps = self.nrep
        nebins = self.nebins
        nqbins = self.nqbins
        nbins = self.nebins * self.nqbins

        reduced_energy = np.zeros([nreps, nebins, nqbins])
        for j in range(self.nqbins):
            reduced_energy[:, :, j] = self.binenergy[np.newaxis, :] / (
                self.Tlist[:, np.newaxis] * self.k_B)

        visits = self.visits2d
        visits = np.reshape(visits, [nreps, nbins])
        reduced_energy = np.reshape(reduced_energy, [nreps, nbins])
        self.logP = np.where(visits != 0, np.log(visits.astype(float)), 0)

        from wham_potential import WhamPotential
        whampot = WhamPotential(visits, reduced_energy)

        nvar = nbins + nreps
        if False:
            X = np.random.rand(nvar)
        else:
            # estimate an initial guess for the offsets and density of states
            # so the minimizer converges more rapidly
            offsets_estimate, log_dos_estimate = wham_utils.estimate_dos(
                visits, reduced_energy)
            X = np.concatenate((offsets_estimate, log_dos_estimate))
            assert X.size == nvar

        E0, grad = whampot.getEnergyGradient(X)
        rms0 = np.linalg.norm(grad) / np.sqrt(grad.size)

        from wham_utils import lbfgs_scipy
        ret = lbfgs_scipy(X, whampot)
        #        print "initial energy", whampot.getEnergy(X)
        #        try:
        #            from pele.optimize import mylbfgs as quench
        #            ret = quench(X, whampot, iprint=10, maxstep = 1e4)
        #        except ImportError:
        #            from pele.optimize import lbfgs_scipy as quench
        #            ret = quench(X, whampot)

        if self.verbose:
            print "chi^2 went from %g (rms %g) to %g (rms %g) in %d iterations" % (
                E0, rms0, ret.energy, ret.rms, ret.nfev)

        #self.logn_Eq = zeros([nebins,nqbins], float64)
        X = ret.coords
        self.logn_Eq = X[nreps:]
        self.w_i_final = X[:nreps]

        self.logn_Eq = np.reshape(self.logn_Eq, [nebins, nqbins])
        self.logn_Eq = np.where(
            self.visits2d.sum(0) == 0, self.LOGMIN, self.logn_Eq)
    def minimize(self):
        #shape(visits2d) is now (nqbins, nebins, nreps)
        #we need it to be (nreps, nqbins*nebins)
        #first reorder indices
        nreps = self.nrep
        nebins = self.nebins
        nqbins = self.nqbins
        nbins = self.nebins * self.nqbins
        #visits = np.zeros([nreps, nebins, nqbins], np.integer)
        reduced_energy = np.zeros([nreps, nebins, nqbins])
        #        for k in range(self.nrep):
        #            for j in range(self.nqbins):
        #                for i in range(self.nebins):
        #                    #visits[k,i,j] = self.visits2d[i,j,k]
        #                    reduced_energy[k,i,j] = self.binenergy[i] / (self.Tlist[k]*self.k_B)
        for j in range(self.nqbins):
            reduced_energy[:, :, j] = self.binenergy[np.newaxis, :] / (
                self.Tlist[:, np.newaxis] * self.k_B)

        visits = self.visits2d
        visits = np.reshape(visits, [nreps, nbins])
        reduced_energy = np.reshape(reduced_energy, [nreps, nbins])
        self.logP = np.where(visits != 0, np.log(visits.astype(float)), 0)

        from wham_potential import WhamPotential
        whampot = WhamPotential(self.logP, reduced_energy)

        nvar = nbins + nreps
        X = np.random.rand(nvar)
        from wham_utils import lbfgs_scipy
        ret = lbfgs_scipy(X, self.whampot)
        #        print "initial energy", whampot.getEnergy(X)
        #        try:
        #            from pele.optimize import mylbfgs as quench
        #            ret = quench(X, whampot, iprint=10, maxstep = 1e4)
        #        except ImportError:
        #            from pele.optimize import lbfgs_scipy as quench
        #            ret = quench(X, whampot)

        print "quenched energy", ret.energy

        #self.logn_Eq = zeros([nebins,nqbins], float64)
        X = ret.coords
        self.logn_Eq = X[nreps:]
        self.w_i_final = X[:nreps]

        self.logn_Eq = np.reshape(self.logn_Eq, [nebins, nqbins])
        self.logn_Eq = np.where(
            self.visits2d.sum(0) == 0, self.LOGMIN, self.logn_Eq)
    def minimize(self):
        """compute the best estimate for the density of states"""
        nreps = self.nrep
        nbins = self.nebins
        visitsT = (self.visits1d)
        #print "min vis", np.min(visitsT)
        #print "minlogp", np.min(self.logP)
        self.reduced_energy = self.binenergy[np.newaxis, :] / (
            self.Tlist[:, np.newaxis] * self.k_B)

        self.whampot = WhamPotential(visitsT, self.reduced_energy)

        if False:
            X = np.random.rand(nreps + nbins)
        else:
            # estimate an initial guess for the offsets and density of states
            # so the minimizer converges more rapidly
            offsets_estimate, log_dos_estimate = wham_utils.estimate_dos(
                self.visits1d, self.reduced_energy)
            X = np.concatenate((offsets_estimate, log_dos_estimate))

        E0, grad = self.whampot.getEnergyGradient(X)
        rms0 = np.linalg.norm(grad) / np.sqrt(grad.size)

        try:
            from pele.optimize import lbfgs_cpp as quench
            if self.verbose:
                print "minimizing with pele lbfgs"
            ret = quench(X, self.whampot, tol=1e-3, maxstep=1e4, nsteps=10000)
        except ImportError:
            from wham_utils import lbfgs_scipy
            if self.verbose:
                print "minimizing with scipy lbfgs"
            ret = lbfgs_scipy(X, self.whampot, tol=1e-3, nsteps=10000)
        #print "quench energy", ret.energy

        if self.verbose:
            print "chi^2 went from %g (rms %g) to %g (rms %g) in %d iterations" % (
                E0, rms0, ret.energy, ret.rms, ret.nfev)

        X = ret.coords
        self.logn_E = X[nreps:]
        self.w_i_final = X[:nreps]
    def minimize(self):
        """compute the best estimate for the density of states"""
        nreps = self.nrep
        nbins = self.nebins
        visitsT = (self.visits1d)
        #print "min vis", np.min(visitsT)
        #print "minlogp", np.min(self.logP)
        self.reduced_energy = self.binenergy[np.newaxis,:] / (self.Tlist[:,np.newaxis] * self.k_B)
        
        self.whampot = WhamPotential(visitsT, self.reduced_energy)
        
        if False:
            X = np.random.rand( nreps + nbins )
        else:
            # estimate an initial guess for the offsets and density of states
            # so the minimizer converges more rapidly
            offsets_estimate, log_dos_estimate = wham_utils.estimate_dos(self.visits1d,
                                                                         self.reduced_energy)
            X = np.concatenate((offsets_estimate, log_dos_estimate))

        E0, grad = self.whampot.getEnergyGradient(X)
        rms0 = np.linalg.norm(grad) / np.sqrt(grad.size)
        
        try:
            from pele.optimize import lbfgs_cpp as quench
            if self.verbose:
                print "minimizing with pele lbfgs"
            ret = quench(X, self.whampot, tol=1e-3, maxstep=1e4, nsteps=10000)
        except ImportError:
            from wham_utils import lbfgs_scipy
            if self.verbose:
                print "minimizing with scipy lbfgs"
            ret = lbfgs_scipy(X, self.whampot, tol=1e-3, nsteps=10000)
        #print "quench energy", ret.energy
        
        if self.verbose:
            print "chi^2 went from %g (rms %g) to %g (rms %g) in %d iterations" % (
                E0, rms0, ret.energy, ret.rms, ret.nfev)
        
        X = ret.coords
        self.logn_E = X[nreps:]
        self.w_i_final = X[:nreps]
    def minimize(self):
        # shape(visits2d) is now (nqbins, nebins, nreps)
        # we need it to be (nreps, nqbins*nebins)
        # first reorder indices
        nreps = self.nrep
        nebins = self.nebins
        nqbins = self.nqbins
        nbins = self.nebins * self.nqbins

        reduced_energy = np.zeros([nreps, nebins, nqbins])
        for j in range(self.nqbins):
            reduced_energy[:, :, j] = self.binenergy[np.newaxis, :] / (self.Tlist[:, np.newaxis] * self.k_B)

        visits = self.visits2d
        visits = np.reshape(visits, [nreps, nbins])
        reduced_energy = np.reshape(reduced_energy, [nreps, nbins])
        self.logP = np.where(visits != 0, np.log(visits.astype(float)), 0)

        from wham_potential import WhamPotential

        whampot = WhamPotential(visits, reduced_energy)

        nvar = nbins + nreps
        if False:
            X = np.random.rand(nvar)
        else:
            # estimate an initial guess for the offsets and density of states
            # so the minimizer converges more rapidly
            offsets_estimate, log_dos_estimate = wham_utils.estimate_dos(visits, reduced_energy)
            X = np.concatenate((offsets_estimate, log_dos_estimate))
            assert X.size == nvar

        E0, grad = whampot.getEnergyGradient(X)
        rms0 = np.linalg.norm(grad) / np.sqrt(grad.size)

        from wham_utils import lbfgs_scipy

        ret = lbfgs_scipy(X, whampot)
        #        print "initial energy", whampot.getEnergy(X)
        #        try:
        #            from pele.optimize import mylbfgs as quench
        #            ret = quench(X, whampot, iprint=10, maxstep = 1e4)
        #        except ImportError:
        #            from pele.optimize import lbfgs_scipy as quench
        #            ret = quench(X, whampot)

        if self.verbose:
            print "chi^2 went from %g (rms %g) to %g (rms %g) in %d iterations" % (
                E0,
                rms0,
                ret.energy,
                ret.rms,
                ret.nfev,
            )

        # self.logn_Eq = zeros([nebins,nqbins], float64)
        X = ret.coords
        self.logn_Eq = X[nreps:]
        self.w_i_final = X[:nreps]

        self.logn_Eq = np.reshape(self.logn_Eq, [nebins, nqbins])
        self.logn_Eq = np.where(self.visits2d.sum(0) == 0, self.LOGMIN, self.logn_Eq)