示例#1
0
    def test_broyden1_update(self):
        # Check that BroydenFirst update works as for a dense matrix
        jac = nonlin.BroydenFirst(alpha=0.1)
        jac.setup(self.xs[0], self.fs[0], None)

        B = np.identity(5) * (-1 / 0.1)

        for last_j, (x, f) in enumerate(zip(self.xs[1:], self.fs[1:])):
            df = f - self.fs[last_j]
            dx = x - self.xs[last_j]
            B += (df - dot(B, dx))[:, None] * dx[None, :] / dot(dx, dx)
            jac.update(x, f)
            assert_(np.allclose(jac.todense(), B, rtol=1e-10, atol=1e-13))
示例#2
0
 def test_broyden1(self):
     # Broyden methods solve linear systems exactly in 2*N steps
     self._check(nonlin.BroydenFirst(alpha=1.0), 20, 41, False)
     self._check(nonlin.BroydenFirst(alpha=1.0), 20, 41, True)