def __init__(self, fop, data, error, startmodel, lam=20, beta=10000, maxIter=50, fwmin=0, fwmax=1, fimin=0, fimax=1, famin=0, famax=1, frmin=0, frmax=1): LSQRInversion.__init__(self, data, fop, verbose=True, dosave=True) self._error = pg.RVector(error) # Set data transformations self.logtrans = pg.RTransLog() self.trans = pg.RTrans() self.dcumtrans = pg.RTransCumulative() self.dcumtrans.add(self.trans, self.forwardOperator().RST.dataContainer.size()) self.dcumtrans.add(self.logtrans, self.forwardOperator().ERT.data.size()) self.setTransData(self.dcumtrans) # Set model transformation n = self.forwardOperator().cellCount self.mcumtrans = pg.TransCumulative() self.transforms = [] phase_limits = [[fwmin, fwmax], [fimin, fimax], [famin, famax], [frmin, frmax]] for i, (lower, upper) in enumerate(phase_limits): if lower == 0: lower = 0.001 self.transforms.append(pg.RTransLogLU(lower, upper)) self.mcumtrans.add(self.transforms[i], n) self.setTransModel(self.mcumtrans) # Set error self.setRelativeError(self._error) # Set some defaults # Set maximum number of iterations (default is 20) self.setMaxIter(maxIter) # Regularization strength self.setLambda(lam) self.setDeltaPhiAbortPercent(0.25) fop = self.forwardOperator() fop.createConstraints() # Important! ones = pg.RVector(fop._I.rows(), 1.0) phiVec = pg.cat(ones, startmodel) self.setParameterConstraints(fop._G, phiVec, beta) self.setModel(startmodel)
def createInv(self, nlay, lam=100., errVES=3, verbose=True): """Create Marquardt type inversion instance with data transformatio""" self.createFOP(nlay) self.tMod = pg.RTransLog() self.tMRS = pg.RTrans() self.tVES = pg.RTransLog() self.transData = pg.RTransCumulative() self.transData.push_back(self.tMRS, len(self.data)) self.transData.push_back(self.tVES, len(self.rhoa)) data = pg.cat(self.data, self.rhoa) self.INV = pg.RInversion(data, self.f, self.transData, verbose) self.INV.setLambda(lam) self.INV.setMarquardtScheme(0.8) self.INV.stopAtChi1(False) # now in MarquardtScheme self.INV.setDeltaPhiAbortPercent(0.5) # self.INV.setMaxIter(1) error = pg.cat(self.error, self.rhoa * errVES / 100.) self.INV.setAbsoluteError(error)
def __init__(self, managers, trans, verbose=False, debug=False, **kwargs): """TODO.""" MethodManager.__init__(self, verbose=verbose, debug=debug, **kwargs) self.managers = managers self.trans = trans self.fops = [] self.dataVals = pg.RVector(0) self.dataErrs = pg.RVector(0) self.mod = pg.RVector(0) # resulting model self.data = None self.tD = pg.RTransCumulative() self.tM = managers[0].tM for mgr in self.managers: fop = mgr.createFOP(verbose) fop.setVerbose(verbose=verbose) self.fops.append(fop) self.fop.setFopsAndTrans(self.fops, self.trans)
#fop = pb.DCMultiElectrodeModelling(mesh, data) fop.regionManager().region(1).setBackground(True) fop.createRefinedForwardMesh(refine=True, pRefine=False) cData = pb.getComplexData(data) mag = pg.abs(cData) phi = -pg.phase(cData) print(pg.norm(mag - data('rhoa'))) print(pg.norm(phi - data('ip') / 1000)) inv = pg.RInversion(pg.cat(mag, phi), fop, verbose=True, dosave=True) dataTrans = pg.RTransCumulative() datRe = pg.RTransLog() datIm = pg.RTrans() dataTrans.add(datRe, data.size()) dataTrans.add(datIm, data.size()) modRe = pg.RTransLog() modIm = pg.RTransLog() modelTrans = pg.RTransCumulative() modelTrans.add(modRe, fop.regionManager().parameterCount()) modelTrans.add(modIm, fop.regionManager().parameterCount()) inv.setTransData(dataTrans) inv.setTransModel(modelTrans) inv.setAbsoluteError(pg.cat(data("err") * mag, mag * phi * 10.01)) inv.setLambda(5)
invDC.setLambda(lamDC) invDC.setMarquardtScheme(0.9) modelDC = invDC.run() respDC = invDC.response() ############################################################################### # Next we create a the joint forward operator (see class above). fDCEM = DCEM1dModelling(nlay, ab2, mn2, freq, coilspacing) fDCEM.region(0).setTransModel(transThk) fDCEM.region(1).setTransModel(transRes) ############################################################################### # We setup the joint inversion combining, transformations, data and errors. transData = pg.RTransCumulative() transData.add(transRhoa, na) transData.add(transEM, nf * 2) invDCEM = pg.RInversion(pg.cat(dataDC, dataEM), fDCEM, transData, verbose) modelDCEM = pg.RVector(nlay * 2 - 1, 20.) invDCEM.setModel(modelDCEM) err = pg.cat(dataDC * noiseDC / 100., pg.RVector(len(dataEM), noiseEM)) invDCEM.setAbsoluteError(err) invDCEM.setLambda(lamDCEM) invDCEM.setMarquardtScheme(0.9) modelDCEM = invDCEM.run() respDCEM = invDCEM.response() ############################################################################### # The results of the inversion are plotted for comparison.