**
**

Warning

You're reading an old version (v5.0) of this documentation. If you want up-to-date information, please have a look at master.

# Penalty File (.penalty)

The penalty file is only needed for inversion and contains the
Model Roughness penalty matrix used to regularize (aka stabilize)
the non-linear inversion of the EM data. This file is automatically
generated by `Mamba2D.m`

and here is documented for completeness.

Note

In a future update, the penalty file will be removed as the penalty matrix can be coded to be directly computed within MARE2DEM in the same way as done in MARE3DEM.

The penalty matrix is \({p \times q}\) penalty matrix
\({\mathbf{R}}\), where *p* is the number of penalty rows and *q* is
the number of model parameters, that is applied to the model vector with
the matrix-vector product \({\mathbf{R}} \mathbf{m}\) ,as described
in Nonlinear EM Inversion. The file uses this format:

```
Format: CSR_penalty_1.0
<# non-zeros> <p>
# non-zeros following lines: <column_index> <value>
p following lines: <row_pointer>
last line: <# non-zeros+1>
```

This is the usual compressed-sparse row (CSR) format where

```
k = row_pointer(i):row_pointer(i+1)-1
j = column_index(k)
R(i,j) = value(k)
```

The *value* parameters are used to store weights applied to the
penalties, but the specific values depend on the structure of the matrix
and the kind of penalty being applied. For example, a second difference
penalty can be applied for parameter *i* by setting, for a given row,
the value in the *i*th column to -1 and then using the value *1/n* for
the columns of all *n* surrounding model parameters, thereby making that
row’s contribution to the penalty be the difference of the *i*th
parameter from the average of all its neighbors (which is equivalent to
the numerical 2nd difference).