# Overview of running MARE2DEM

Overview of the typical MARE2DEM workflow for forward and inverse modeling.

The diagram above gives an overview of the typical MARE2DEM workflow.  Here's a brief summary step-by-step run through:

1. Inputs include any EM data, a topography profile and any other a priori geologic information you wish to incorporate into the forward or inverse model.
2. Create the model and data files. On your laptop or desktop, you create the model domain using the MATLAB code Mamba2D.m, which outputs a few files describing the model geometry, resistivity parameters and the inversion penalty matrix. Real data can be written to the MARE2DEM data format using the routine writeEMData2DFile.m. For forward modeling, you can use this routine to create a dummy data file that lists the desired sources, receivers and frequencies.
3. Run MARE2DEM on your laptop, desktop or cluster. If running on a cluster, you will first need to upload the model and data files created in step 2.  MARE2DEM will output a bunch of text to the screen informing you of its progress. For inversions, there will also be an output .logfile detailing Occam's performance; at the end of each successful iteration, the new inversion model and its response will be written to a files.
4. View the results on your laptop or desktop. The inversion model files can be viewed using the MATLAB routine plotMARE2DEM.m.  Model responses (as well as data) can be viewed and interacted with using plotMARE2DEM_MT.m and plotMARE2DEM_CSEM.m.   At this point you may decide you want to change the forward model and recompute results, or you may want to eliminate some noisy data from an inversion; if so, carry our some quality control inspections and head back to step 2.

#### Summary of the main MATLAB routines

• Mamba2D.m - creates forward and inverse models
• plotMARE2DEM.m - for viewing for forward and inverse models
• plotMARE2DEM_MT.m - for viewing and interacting with MT data and model responses
• plotMARE2DEM_CSEM.m  - for viewing and interacting with CSEM data and model responses
• writeEMData2DFile.m  - routine that will write a MARE2DEM format data file. If you can already import your data into MATLAB, then interfacing with this routine is all you need to get your data ready for MARE2DEM inversion.
• readEMData2DFile.m  - routine that will read a MARE2DEM format data file. This may be useful if you want to write your own custom plotting utility.
• There are a bunch of other helper functions in the MATLAB folder that these routines rely upon.

# Brief overview of Occam's inversion

This section is a brief overview of the Occam's inversion approach used by MARE2DEM. It may be helpful for understanding the various parameters in the input files. More detailed descriptions of Occam can be found in Constable et al. (1987) and deGroot-Hedlin and Constable (1990), and a specific application to 1D marine CSEM is described in Key (2009).

Occam's inversion seeks to minimize the following unconstrained regularized functional:

The first term is a norm of the model roughness and is computed by applying a differencing operator $\mathbf{R}$ to the elements of the model vector $\mathbf{m}$. The model vector $\mathbf{m}$ contains the $\log_{10}\rho$ values for all the free model parameters. $\mathbf{R}$ is chosen to be a matrix of first-differencing operators so that $\mathbf{R}$ approximates the spatial gradient of $\log_{10}\rho$ integrated over the parameter. The parameterization with respect to $\log_{10} \rho$ ensures that resistivity remains positive during the inversion. If jumps in resistivity are desired at certain boundaries, the corresponding elements of $\mathbf{R}$ can be relaxed or  set to zero. The second term is a measure of the difference of $\mathbf{m}$ from an a priori preference model $\mathbf{m_{*}}$. The diagonal matrix $\mathbf{P}$ contains scaling parameters that determine the relative weighting between the preference and the model roughness. Preference model values, if used at all, are typically desired for a only few model layers and the corresponding diagonal elements of $\mathbf{P}$ will be nonzero. This can be useful for constraining the anisotropy ratio for anisotropic inversion. The roughness and preference terms in the above equation are regularizers that serve to stabilize the inversion and keep it from producing wildly oscillating resistivity structure (see the regularized/unregularized comparisons in Constable et al. (1987).

Finally, the third term is a measure of the misfit of the model's forward response $F(\mathbf{m})$ (i.e., the electric and magnetic fields or MT impedances for model $\mathbf{m}$) to the data $\mathbf{d}$. There is no restriction on the data vector $\mathbf{d}$. For example, it can contain data from multiple transmitters, receivers and frequencies, and can include magnetotelluric (MT) data. $\mathbf{W}$ is a data covariance weighting function and is here selected to be a diagonal matrix with elements corresponding to inverse data standard errors. In other words, $\mathbf{W}$ weights the relative contribution of each datum to the misfit based on its uncertainty. Thus, data with large errors are scaled to limit their influence, while data with small errors will have a bigger impact on the misfit budget.

$\chi_{*}^{2}$ is the target misfit and its inclusion illustrates that minimizing $U$ does not necessarily find the best fitting model, but rather a smooth model that is within the specified target misfit. The target misfit $\chi_{*}^{2}$ is usually chosen so that the root mean square (RMS) misfit $x_{rms}$ is equal to unity:

where $n$ is the number of data and $s_{i}$ is the standard error of the $i$th datum.

The Lagrange multiplier $\mu$ serves to balance the trade-off between the data fit and the model roughness and model preference. The nonlinear minimization of equation ${U}$ is described in Constable et al. (1987).  One of the main innovations of the Occam method is the automatic selection of $\mu$. So that's Occam described in a single page of text.

##### References

Constable, S. C., R. L. Parker, and C. G. Constable (1987), Occam's inversion - A practical algorithm for generating smooth models from electromagnetic sounding data, Geophysics, 52(03), 289–300.

deGroot-Hedlin, C., and S. Constable (1990), Occam's inversion to generate smooth two-dimensional models from magnetotelluric data, Geophysics, 55(12), 1613–1624.

Key, K. (2009). 1D inversion of multicomponent, multifrequency marine CSEM data: Methodology and synthetic studies for resolving thin resistive layers. Geophysics, 74(2), F9–F20. doi:10.1190/1.3058434