def derivtest(self, deriv_fct): m0 = np.log(self.sigma) + np.random.rand(self.mesh.nC) self.prob.model = m0 return tests.checkDerivative(deriv_fct, np.log(self.sigma), num=3, plotIt=False)
def test_misfit(self): passed = tests.checkDerivative( lambda m: [self.p.dpred(m), lambda mx: self.p.Jvec(self.m0, mx)], self.m0, plotIt=False, num=3, ) self.assertTrue(passed)
def JvecTest(self): print("\nTesting Jvec") x0 = model def fun(x): return [ self.secondarySimulation.dpred(x), lambda x: self.secondarySimulation.Jvec( x0, x, f=self.fields_primsec), ] return tests.checkDerivative(fun, x0, num=2, plotIt=False)
def test_derivs(self): tests.checkDerivative(CasingMagDipoleDeriv_r, np.ones(n) * 10 + np.random.randn(n), plotIt=False) tests.checkDerivative(CasingMagDipoleDeriv_z, np.random.randn(n), plotIt=False) tests.checkDerivative( CasingMagDipole2Deriv_z_r, np.ones(n) * 10 + np.random.randn(n), plotIt=False, ) tests.checkDerivative(CasingMagDipole2Deriv_z_z, np.random.randn(n), plotIt=False)
def JvecTest(self, prbtype="ElectricField", sigmaInInversion=False, invertMui=False): self.setUpProb(prbtype, sigmaInInversion, invertMui) print("Testing Jvec {}".format(prbtype)) def fun(x): return ( self.simulation.dpred(x), lambda x: self.simulation.Jvec(self.m0, x), ) return tests.checkDerivative(fun, self.m0, num=3, plotIt=False)
def derivTest(fdemType, comp): prb = getFDEMProblem(fdemType, comp, SrcType, freq) # prb.solverOpts = dict(check_accuracy=True) print("{0!s} formulation - {1!s}".format(fdemType, comp)) x0 = np.log(np.ones(prb.sigmaMap.nP) * CONDUCTIVITY) # mu = np.log(np.ones(prb.mesh.nC)*MU) if addrandoms is True: x0 = x0 + np.random.randn(prb.sigmaMap.nP) * np.log(CONDUCTIVITY) * 1e-1 # mu = mu + np.random.randn(prb.sigmaMap.nP)*MU*1e-1 survey = prb.survey def fun(x): return prb.dpred(x), lambda x: prb.Jvec(x0, x) return tests.checkDerivative(fun, x0, num=2, plotIt=False, eps=FLR)
def DerivJvecTest(inputSetup, comp="All", freq=False, expMap=True): (M, freqs, sig, sigBG, rx_loc) = inputSetup survey, simulation = nsem.utils.test_utils.setupSimpegNSEM_ePrimSec( inputSetup, comp=comp, singleFreq=freq, expMap=expMap) print("Using {0} solver for the simulation".format(simulation.Solver)) print( "Derivative test of Jvec for eForm primary/secondary for {} comp at {}\n" .format(comp, survey.freqs)) # simulation.mapping = Maps.ExpMap(simulation.mesh) # simulation.sigmaPrimary = np.log(sigBG) x0 = np.log(sigBG) # cond = sig[0] # x0 = np.log(np.ones(simulation.mesh.nC)*cond) # simulation.sigmaPrimary = x0 # if True: # x0 = x0 + np.random.randn(simulation.mesh.nC)*cond*1e-1 survey = simulation.survey def fun(x): return simulation.dpred(x), lambda x: simulation.Jvec(x0, x) return tests.checkDerivative(fun, x0, num=3, plotIt=False, eps=FLR)
def test_dataObj(self): passed = tests.checkDerivative( lambda m: [self.dmis(m), self.dmis.deriv(m)], self.m0, plotIt=False, num=6 ) self.assertTrue(passed)