コード例 #1
0
ファイル: test_nonlin.py プロジェクト: mbentz80/jzigbeercp
 def test_broydengeneralized(self):
     x= nonlin.broyden_generalized(F,self.xin,iter=60,alpha=0.5,M=0)
     assert nonlin.norm(x)<1e-7
     assert nonlin.norm(F(x))<1e-7
     x= nonlin.broyden_generalized(F,self.xin,iter=61,alpha=0.1,M=1)
     assert nonlin.norm(x)<2e-4
     assert nonlin.norm(F(x))<2e-4
コード例 #2
0
ファイル: test_nonlin.py プロジェクト: AndreI11/SatStressGui
 def test_broydengeneralized(self):
     x = nonlin.broyden_generalized(F, self.xin, iter=60, alpha=0.5, M=0)
     assert nonlin.norm(x) < 1e-7
     assert nonlin.norm(F(x)) < 1e-7
     x = nonlin.broyden_generalized(F, self.xin, iter=61, alpha=0.1, M=1)
     assert nonlin.norm(x) < 2e-4
     assert nonlin.norm(F(x)) < 2e-4
コード例 #3
0
 def test_root_linearmixing(self):
     res = root(F,
                F.xin,
                method='linearmixing',
                options={
                    'nit': 60,
                    'jac_options': {
                        'alpha': 0.5
                    }
                })
     assert_(nonlin.norm(res.x) < 1e-7)
     assert_(nonlin.norm(res.fun) < 1e-7)
コード例 #4
0
 def test_root_excitingmixing(self):
     res = root(F,
                F.xin,
                method='excitingmixing',
                options={
                    'nit': 20,
                    'jac_options': {
                        'alpha': 0.5
                    }
                })
     assert_(nonlin.norm(res.x) < 1e-5)
     assert_(nonlin.norm(res.fun) < 1e-5)
コード例 #5
0
 def test_root_diagbroyden(self):
     res = root(F,
                F.xin,
                method='diagbroyden',
                options={
                    'nit': 11,
                    'jac_options': {
                        'alpha': 1
                    }
                })
     assert_(nonlin.norm(res.x) < 1e-8)
     assert_(nonlin.norm(res.fun) < 1e-8)
コード例 #6
0
 def test_root_broyden2(self):
     res = root(F,
                F.xin,
                method='broyden2',
                options={
                    'nit': 12,
                    'jac_options': {
                        'alpha': 1
                    }
                })
     assert_(nonlin.norm(res.x) < 1e-9)
     assert_(nonlin.norm(res.fun) < 1e-9)
コード例 #7
0
    def execute_broyden2(self):
        """From SciPy, Broyden's second method.

        Updates inverse Jacobian by an optimal formula.
        There is NxN matrix multiplication in every iteration.

        The best norm(F(x))=0.003 achieved in ~20 iterations.
        """ 
        
        xm = self.xin.T
        Fxm = numpy.matrix(self.F).T
        Gm = -self.alpha*numpy.matrix(numpy.identity(len(self.xin)))
        
        for n in range(self.itmax):
            
            if self._stop:
                self.raise_exception('Stop requested', RunStopped)

            deltaxm = -Gm*Fxm
            xm = xm + deltaxm.T
            
            # update the new independents in the model
            self.set_parameters(xm.flat)

            # run the model
            self.run_iteration()

            # get dependents
            for i, val in enumerate(self.get_eq_constraints().values()):
                term = val.evaluate(self.parent)
                self.F[i] = term[0] - term[1]
            
            # successful termination if independents are below tolerance
            if norm(self.F) < self.tol:
                return
 
            Fxm1 = numpy.matrix(self.F).T
            deltaFxm = Fxm1 - Fxm
            
            if norm(deltaFxm) == 0:
                msg = "Broyden iteration has stopped converging. Change in " + \
                      "input has produced no change in output. This could " + \
                      "indicate a problem with your component connections. " + \
                      "It could also mean that this solver method is " + \
                      "inadequate for your problem."
                raise RuntimeError(msg)
            
            Fxm = Fxm1.copy()
            Gm = Gm + (deltaxm-Gm*deltaFxm)*deltaFxm.T/norm(deltaFxm)**2
コード例 #8
0
 def test_root_anderson(self):
     res = root(F,
                F.xin,
                method='anderson',
                options={
                    'nit': 12,
                    'jac_options': {
                        'alpha': 0.03,
                        'M': 5
                    }
                })
     assert_(nonlin.norm(res.x) < 0.33)
コード例 #9
0
    def execute_excitingmixing(self):
        """from scipy, The excitingmixing method.

        J=-1/alpha

        The best norm(F(x))=0.005 achieved in ~140 iterations.
        
        Note: SciPy uses 0.1 as the default value for alpha for this algorithm.
        Ours is set at 0.4, which is appropriate for Broyden2 and Broyden3, so
        adjust it accordingly if there are problems.
        """
    
        xm = self.xin.copy()
        beta = numpy.array([self.alpha]*len(xm))
        Fxm = self.F.T.copy()
    
        for n in range(self.itmax):

            if self._stop:
                self.raise_exception('Stop requested', RunStopped)

            deltaxm = beta*Fxm
            xm = xm + deltaxm

            # update the new independents in the model
            self.set_parameters(xm.flat)

            # run the model
            self.run_iteration()

            # get dependents
            for i, val in enumerate(self.get_eq_constraints().values()):
                term = val.evaluate(self.parent)
                self.F[i] = term[0] - term[1]

            # successful termination if independents are below tolerance
            if norm(self.F) < self.tol:
                return
 
            Fxm1 = self.F.T
            
            for i in range(len(xm)):
                if Fxm1[i]*Fxm[i] > 0:
                    beta[i] = beta[i] + self.alpha
                    if beta[i] > self.alphamax:
                        beta[i] = self.alphamax
                else:
                    beta[i] = self.alpha
                
            Fxm = Fxm1.copy()
コード例 #10
0
ファイル: test_nonlin.py プロジェクト: AndreI11/SatStressGui
 def test_anderson2(self):
     x = nonlin.anderson2(F, self.xin, iter=12, alpha=0.6, M=5)
     assert nonlin.norm(x) < 0.2
コード例 #11
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_root_anderson(self):
     res = root(F, F.xin, method='anderson',
                options={'nit': 12,
                         'jac_options': {'alpha': 0.03, 'M': 5}})
     assert_(nonlin.norm(res.x) < 0.33)
コード例 #12
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_diagbroyden(self):
     x = nonlin.diagbroyden(F,F.xin,iter=11,alpha=1)
     assert_(nonlin.norm(x) < 1e-8)
     assert_(nonlin.norm(F(x)) < 1e-8)
コード例 #13
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_linearmixing(self):
     x = nonlin.linearmixing(F,F.xin,iter=60,alpha=0.5)
     assert_(nonlin.norm(x) < 1e-7)
     assert_(nonlin.norm(F(x)) < 1e-7)
コード例 #14
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_broyden2(self):
     x = nonlin.broyden2(F,F.xin,iter=12,alpha=1)
     assert_(nonlin.norm(x) < 1e-9)
     assert_(nonlin.norm(F(x)) < 1e-9)
コード例 #15
0
ファイル: test_nonlin.py プロジェクト: mbentz80/jzigbeercp
 def test_broyden1modified(self):
     x= nonlin.broyden1_modified(F,self.xin,iter=35,alpha=1)
     assert nonlin.norm(x)<1e-9
     assert nonlin.norm(F(x))<1e-9
コード例 #16
0
ファイル: test_nonlin.py プロジェクト: wangdayoux/OpenSignals
 def test_root_linearmixing(self):
     res = root(F, F.xin, method="linearmixing", options={"nit": 60, "jac_options": {"alpha": 0.5}})
     assert_(nonlin.norm(res.x) < 1e-7)
     assert_(nonlin.norm(res.fun) < 1e-7)
コード例 #17
0
 def test_linearmixing(self):
     x = nonlin.linearmixing(F, F.xin, iter=60, alpha=0.5)
     assert_(nonlin.norm(x) < 1e-7)
     assert_(nonlin.norm(F(x)) < 1e-7)
コード例 #18
0
 def test_anderson(self):
     x = nonlin.anderson(F, F.xin, iter=12, alpha=0.03, M=5)
     assert_(nonlin.norm(x) < 0.33)
コード例 #19
0
 def test_broyden2(self):
     x = nonlin.broyden2(F, F.xin, iter=12, alpha=1)
     assert_(nonlin.norm(x) < 1e-9)
     assert_(nonlin.norm(F(x)) < 1e-9)
コード例 #20
0
ファイル: test_nonlin.py プロジェクト: AndreI11/SatStressGui
 def test_vackar(self):
     x = nonlin.vackar(F, self.xin, iter=11, alpha=1)
     assert nonlin.norm(x) < 1e-9
     assert nonlin.norm(F(x)) < 1e-9
コード例 #21
0
ファイル: test_nonlin.py プロジェクト: AndreI11/SatStressGui
 def test_broyden1modified(self):
     x = nonlin.broyden1_modified(F, self.xin, iter=35, alpha=1)
     assert nonlin.norm(x) < 1e-9
     assert nonlin.norm(F(x)) < 1e-9
コード例 #22
0
ファイル: test_nonlin.py プロジェクト: AndreI11/SatStressGui
 def xtest_broydenmodified(self):
     x = nonlin.broyden_modified(F, self.xin, iter=12, alpha=1)
     assert nonlin.norm(x) < 1e-9
     assert nonlin.norm(F(x)) < 1e-9
コード例 #23
0
ファイル: test_nonlin.py プロジェクト: mbentz80/jzigbeercp
 def test_broyden3(self):
     x= nonlin.broyden3(F,self.xin,iter=12,alpha=1)
     assert nonlin.norm(x)<1e-9
     assert nonlin.norm(F(x))<1e-9
コード例 #24
0
 def test_exciting(self):
     x = nonlin.excitingmixing(F, F.xin, iter=20, alpha=0.5)
     assert_(nonlin.norm(x) < 1e-5)
     assert_(nonlin.norm(F(x)) < 1e-5)
コード例 #25
0
ファイル: test_nonlin.py プロジェクト: mbentz80/jzigbeercp
 def test_anderson2(self):
     x= nonlin.anderson2(F,self.xin,iter=12,alpha=0.6,M=5)
     assert nonlin.norm(x)<0.2
コード例 #26
0
 def test_diagbroyden(self):
     x = nonlin.diagbroyden(F, F.xin, iter=11, alpha=1)
     assert_(nonlin.norm(x) < 1e-8)
     assert_(nonlin.norm(F(x)) < 1e-8)
コード例 #27
0
ファイル: test_nonlin.py プロジェクト: mbentz80/jzigbeercp
 def xtest_broydenmodified(self):
     x= nonlin.broyden_modified(F,self.xin,iter=12,alpha=1)
     assert nonlin.norm(x)<1e-9
     assert nonlin.norm(F(x))<1e-9
コード例 #28
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_root_excitingmixing(self):
     res = root(F, F.xin, method='excitingmixing',
                options={'nit': 20,
                         'jac_options': {'alpha': 0.5}})
     assert_(nonlin.norm(res.x) < 1e-5)
     assert_(nonlin.norm(res.fun) < 1e-5)
コード例 #29
0
ファイル: test_nonlin.py プロジェクト: mbentz80/jzigbeercp
 def test_vackar(self):
     x= nonlin.vackar(F,self.xin,iter=11,alpha=1)
     assert nonlin.norm(x)<1e-9
     assert nonlin.norm(F(x))<1e-9
コード例 #30
0
ファイル: test_nonlin.py プロジェクト: wangdayoux/OpenSignals
 def test_root_anderson(self):
     res = root(F, F.xin, method="anderson", options={"nit": 12, "jac_options": {"alpha": 0.03, "M": 5}})
     assert_(nonlin.norm(res.x) < 0.33)
コード例 #31
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_anderson(self):
     x = nonlin.anderson(F,F.xin,iter=12,alpha=0.03,M=5)
     assert_(nonlin.norm(x) < 0.33)
コード例 #32
0
    def execute_broyden3(self):
        """from scipy, Broyden's second (sic) method.

        Updates inverse Jacobian by an optimal formula.
        The NxN matrix multiplication is avoided.

        The best norm(F(x))=0.003 achieved in ~20 iterations.
        """
        
        zy = []
        
        def updateG(z, y):
            """G:=G+z*y.T'"""
            zy.append((z, y))
            
        def Gmul(f):
            """G=-alpha*1+z*y.T+z*y.T ..."""
            s = -self.alpha*f
            for z, y in zy:
                s = s + z*(y.T*f)
            return s

        xm = self.xin.T
        Fxm = numpy.matrix(self.F).T

        for n in range(self.itmax):
            
            if self._stop:
                self.raise_exception('Stop requested', RunStopped)

            deltaxm = Gmul(-Fxm)
            xm = xm + deltaxm.T

            # update the new independents in the model
            self.set_parameters(xm.flat)

            # run the model
            self.run_iteration()

            # get dependents
            for i, val in enumerate(self.get_eq_constraints().values()):
                term = val.evaluate(self.parent)
                self.F[i] = term[0] - term[1]

            # successful termination if independents are below tolerance
            if norm(self.F) < self.tol:
                return
 
            Fxm1 = numpy.matrix(self.F).T
            deltaFxm = Fxm1 - Fxm
            
            if norm(deltaFxm) == 0:
                msg = "Broyden iteration has stopped converging. Change in " + \
                      "input has produced no change in output. This could " + \
                      "indicate a problem with your component connections. " + \
                      "It could also mean that this solver method is " + \
                      "inadequate for your problem."
                raise RuntimeError(msg)
            
            Fxm = Fxm1.copy()
            updateG(deltaxm - Gmul(deltaFxm), deltaFxm/norm(deltaFxm)**2)
コード例 #33
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_exciting(self):
     x = nonlin.excitingmixing(F,F.xin,iter=20,alpha=0.5)
     assert_(nonlin.norm(x) < 1e-5)
     assert_(nonlin.norm(F(x)) < 1e-5)
コード例 #34
0
ファイル: test_nonlin.py プロジェクト: wangdayoux/OpenSignals
 def test_root_diagbroyden(self):
     res = root(F, F.xin, method="diagbroyden", options={"nit": 11, "jac_options": {"alpha": 1}})
     assert_(nonlin.norm(res.x) < 1e-8)
     assert_(nonlin.norm(res.fun) < 1e-8)
コード例 #35
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_root_broyden2(self):
     res = root(F, F.xin, method='broyden2',
                options={'nit': 12, 'jac_options': {'alpha': 1}})
     assert_(nonlin.norm(res.x) < 1e-9)
     assert_(nonlin.norm(res.fun) < 1e-9)
コード例 #36
0
ファイル: test_nonlin.py プロジェクト: wangdayoux/OpenSignals
 def test_root_excitingmixing(self):
     res = root(F, F.xin, method="excitingmixing", options={"nit": 20, "jac_options": {"alpha": 0.5}})
     assert_(nonlin.norm(res.x) < 1e-5)
     assert_(nonlin.norm(res.fun) < 1e-5)
コード例 #37
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_root_linearmixing(self):
     res = root(F, F.xin, method='linearmixing',
                options={'nit': 60,
                         'jac_options': {'alpha': 0.5}})
     assert_(nonlin.norm(res.x) < 1e-7)
     assert_(nonlin.norm(res.fun) < 1e-7)
コード例 #38
0
ファイル: test_nonlin.py プロジェクト: AndreI11/SatStressGui
 def test_broyden3(self):
     x = nonlin.broyden3(F, self.xin, iter=12, alpha=1)
     assert nonlin.norm(x) < 1e-9
     assert nonlin.norm(F(x)) < 1e-9
コード例 #39
0
ファイル: test_nonlin.py プロジェクト: 7924102/scipy
 def test_root_diagbroyden(self):
     res = root(F, F.xin, method='diagbroyden',
                options={'nit': 11,
                         'jac_options': {'alpha': 1}})
     assert_(nonlin.norm(res.x) < 1e-8)
     assert_(nonlin.norm(res.fun) < 1e-8)
コード例 #40
0
ファイル: test_nonlin.py プロジェクト: wangdayoux/OpenSignals
 def test_root_broyden2(self):
     res = root(F, F.xin, method="broyden2", options={"nit": 12, "jac_options": {"alpha": 1}})
     assert_(nonlin.norm(res.x) < 1e-9)
     assert_(nonlin.norm(res.fun) < 1e-9)