mirror of
https://github.com/wassname/simpeg.git
synced 2026-06-28 03:19:21 +08:00
b8fe0cfdbf
Build in a matrix?
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import numpy as np
|
|
import unittest
|
|
from SimPEG import *
|
|
from scipy.sparse.linalg import dsolve
|
|
import inspect
|
|
|
|
|
|
class RegularizationTests(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.mesh2 = Mesh.TensorMesh([3, 2])
|
|
|
|
def test_regularization(self):
|
|
for R in dir(Regularization):
|
|
r = getattr(Regularization, R)
|
|
if not inspect.isclass(r): continue
|
|
if not issubclass(r, Regularization.BaseRegularization):
|
|
continue
|
|
# if 'Regularization' not in R: continue
|
|
mapping = r.mapPair(self.mesh2)
|
|
reg = r(self.mesh2, mapping=mapping)
|
|
m = np.random.rand(mapping.nP)
|
|
reg.mref = m[:]*np.mean(m)
|
|
|
|
print 'Check:', R
|
|
passed = Tests.checkDerivative(lambda m : [reg.eval(m), reg.evalDeriv(m)], m, plotIt=False)
|
|
self.assertTrue(passed)
|
|
print 'Check 2 Deriv:', R
|
|
passed = Tests.checkDerivative(lambda m : [reg.evalDeriv(m), reg.eval2Deriv(m)], m, plotIt=False)
|
|
self.assertTrue(passed)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|