How to use the discretize.Tests.checkDerivative function in discretize

To help you get started, we’ve selected a few discretize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simpeg / simpeg / tests / flow / test_Richards_empirical.py View on Github external
]

        u = np.random.randn(mesh.nC)

        for name, opt, nM in opts:
            van = Richards.Empirical.Vangenuchten_theta(mesh, **opt)

            x0 = np.concatenate([seeds[n] for n in name.split('-')])

            def fun(m):
                van.model = m
                return van(u), van.derivM(u)

            print('Vangenuchten_theta test m deriv:  ', name)

            passed = checkDerivative(
                fun,
                x0,
                plotIt=False
            )
            self.assertTrue(passed, True)
github simpeg / simpeg / tests / flow / test_Richards_empirical.py View on Github external
]

        u = np.random.randn(mesh.nC)

        for name, opt, nM in opts:
            van = Richards.Empirical.Vangenuchten_k(mesh, **opt)

            x0 = np.concatenate([seeds[n] for n in name.split('-')])

            def fun(m):
                van.model = m
                return van(u), van.derivM(u)

            print('Vangenuchten_k test m deriv:  ', name)

            passed = checkDerivative(
                fun,
                x0,
                plotIt=False
            )
            self.assertTrue(passed, True)
github simpeg / simpeg / tests / flow / test_Richards_empirical.py View on Github external
gammaMap=expmap*wires3.three), 3),
        ]

        u = np.random.randn(mesh.nC)

        for name, opt, nM in opts:
            np.random.seed(2)
            hav = Richards.Empirical.Haverkamp_k(mesh, **opt)

            def fun(m):
                hav.model = m
                return hav(u), hav.derivM(u)

            print('Haverkamp_k test m deriv:  ', name)

            passed = checkDerivative(
                fun,
                np.random.randn(mesh.nC * nM),
                plotIt=False
            )
            self.assertTrue(passed, True)
github simpeg / simpeg / tests / flow / test_Richards_empirical.py View on Github external
def test_vangenuchten_theta_u(self):
        mesh = Mesh.TensorMesh([50])
        van = Richards.Empirical.Vangenuchten_theta(mesh)
        passed = checkDerivative(
            lambda u: (van(u), van.derivU(u)),
            np.random.randn(50),
            plotIt=False
        )
        self.assertTrue(passed, True)
github simpeg / simpeg / tests / flow / test_Richards_empirical.py View on Github external
def test_haverkamp_theta_u(self):
        mesh = Mesh.TensorMesh([50])
        hav = Richards.Empirical.Haverkamp_theta(mesh)
        passed = checkDerivative(
            lambda u: (hav(u), hav.derivU(u)),
            np.random.randn(50),
            plotIt=False
        )
        self.assertTrue(passed, True)
github simpeg / simpeg / tests / flow / test_Richards_empirical.py View on Github external
def test_haverkamp_k_u(self):

        mesh = Mesh.TensorMesh([5])

        hav = Richards.Empirical.Haverkamp_k(mesh)
        print('Haverkamp_k test u deriv')
        passed = checkDerivative(
            lambda u: (hav(u), hav.derivU(u)),
            np.random.randn(mesh.nC),
            plotIt=False
        )
        self.assertTrue(passed, True)
github simpeg / simpeg / tests / base / test_utils.py View on Github external
def test_simplePass(self):
        def simplePass(x):
            return np.sin(x), sdiag(np.cos(x))
        passed = checkDerivative(simplePass, np.random.randn(5), plotIt=False)
        self.assertTrue(passed, True)
github simpeg / simpeg / tests / flow / test_Richards.py View on Github external
def _dotest_sensitivity_full(self):
        print('Testing Richards Derivative FULL dim={}'.format(
            self.mesh.dim
        ))
        J = self.prob.Jfull(self.mtrue)
        passed = checkDerivative(
            lambda m: [self.survey.dpred(m), J],
            self.mtrue,
            num=4,
            plotIt=False
        )
        self.assertTrue(passed, True)
github simpeg / simpeg / SimPEG / Maps.py View on Github external
def testVec(self, m=None, **kwargs):
        """Test the derivative of the mapping times a vector.

            :param numpy.ndarray m: model
            :param kwargs: key word arguments of
                           :meth:`discretize.Tests.checkDerivative`
            :rtype: bool
            :return: passed the test?

        """
        print('Testing {0!s}'.format(self))
        if m is None:
            m = abs(np.random.rand(self.nP))
        if 'plotIt' not in kwargs:
            kwargs['plotIt'] = False
        return checkDerivative(
            lambda m: [self*m, lambda x: self.deriv(m, x)], m, num=4, **kwargs
        )
github simpeg / simpeg / SimPEG / ObjectiveFunction.py View on Github external
def _test_deriv(self, x=None, num=4, plotIt=False, **kwargs):
        print('Testing {0!s} Deriv'.format(self.__class__.__name__))
        if x is None:
            if self.nP == '*':
                x = np.random.randn(np.random.randint(1e2, high=1e3))
            else:
                x = np.random.randn(self.nP)

        return checkDerivative(
            lambda m: [self(m), self.deriv(m)], x, num=num, plotIt=plotIt,
            **kwargs
        )