Пример #1
0
    def test_saveloadtxt(self):
        tmp_file = NamedTemporaryFile(mode='wb', delete=False)
        tmp_file.close()

        x = 3.14159265359
        tools.savetxt(tmp_file.name, x)
        self.assertAlmostEqual(x, tools.loadtxt(tmp_file.name), 6)
Пример #2
0
    def test_saveloadtxt(self):
        tmp_file = NamedTemporaryFile(mode='wb', delete=False)
        tmp_file.close()

        x = 3.14159265359
        tools.savetxt(tmp_file.name, x)
        self.assertAlmostEqual(x, tools.loadtxt(tmp_file.name), 6)
Пример #3
0
    def __init__(self, path='.', load=loadnpy, save=savenpy, thresh=1., maxiter=np.inf, precond=None):
        self.path = path
        self.load = load
        self.save = save
        self.maxiter = maxiter
        self.thresh = thresh
        self.precond = precond

        try:
            self.iter = loadtxt(self.path+'/'+'NLCG/iter')
        except IOError:
            unix.mkdir(self.path+'/'+'NLCG')
            self.iter = 0
Пример #4
0
    def __init__(self, path='.', load=loadnpy, save=savenpy, thresh=1.,
                 maxiter=np.inf, precond=None):
        self.path = path
        self.load = load
        self.save = save
        self.maxiter = maxiter
        self.thresh = thresh
        self.precond = precond

        try:
            self.iter = loadtxt(self.path+'/'+'NLCG/iter')
        except IOError:
            unix.mkdir(self.path+'/'+'NLCG')
            self.iter = 0
Пример #5
0
    def update(self, ap):
        unix.cd(self.path)

        self.ilcg += 1

        x = self.load('LCG/x')
        r = self.load('LCG/r')
        y = self.load('LCG/y')
        p = self.load('LCG/p')
        ry = loadtxt('LCG/ry')

        pap = np.dot(p, ap)
        if pap < 0:
            print ' Stopping LCG [negative curvature]'
            isdone = True
            return isdone

        alpha = ry / pap
        x += alpha * p
        r += alpha * ap
        self.save('LCG/x', x)
        self.save('LCG/r', r)

        # check status
        if self.check_status(ap) == 0:
            isdone = True
        elif self.ilcg >= self.maxiter:
            isdone = True
        else:
            isdone = False

        if not isdone:
            y = self.apply_precond(r)
            ry_old = ry
            ry = np.dot(r, y)
            beta = ry / ry_old
            p = -y + beta * p

            self.save('LCG/y', y)
            self.save('LCG/p', p)
            savetxt('LCG/ry', np.dot(r, y))

        return isdone
Пример #6
0
    def update(self, ap):
        unix.cd(self.path)

        self.ilcg += 1

        x = self.load('LCG/x')
        r = self.load('LCG/r')
        y = self.load('LCG/y')
        p = self.load('LCG/p')
        ry = loadtxt('LCG/ry')

        pap = np.dot(p, ap)
        if pap < 0:
            print ' Stopping LCG [negative curvature]'
            isdone = True
            return isdone
                       
        alpha = ry/pap
        x += alpha*p
        r += alpha*ap
        self.save('LCG/x', x)
        self.save('LCG/r', r)

        # check status
        if self.check_status(ap) == 0:
            isdone = True
        elif self.ilcg >= self.maxiter:
            isdone = True
        else:
            isdone = False

        if not isdone:
            y = self.apply_precond(r)
            ry_old = ry
            ry = np.dot(r, y)
            beta = ry/ry_old
            p = -y + beta*p

            self.save('LCG/y', y)
            self.save('LCG/p', p)
            savetxt('LCG/ry', np.dot(r, y))

        return isdone
Пример #7
0
 def loadtxt(self, filename):
     return loadtxt(PATH.OPTIMIZE + '/' + filename)