# Stokes inversion techniques with neural networks: analysis of uncertainty in
parameter estimation

Lukia Mistryukova  Andrey Plotnikov  Aleksandr Khizhik  Irina Knyazeva
Mikhail Hushchyn  Denis Derkach  HSE University, Moscow, Russia  Pulkovo
Observatory, Saint-Petersburg, Russia  Crimean Astrophysical Observatory,
Crimea  Saint-Petersburg State University, Saint-Petersburg, Russia

###### keywords:

Magnetic ﬁelds, Inverse problem, Spectral lines, Deep learning

iint iiint TXFiint TXFiiint

##  1 Introduction

Modern solar physics relies, to a great extent, on the spectropolarimetric
observations of the Sun (Ramos et al., 2016; Gafeira et al., 2021; Li et al.,
2022; Leka et al., 2022). The data on spectral and polarization state of the
solar light, in conjunction with an appropriate atmosphere model allows one to
derive the thermodynamic, dynamic, and magnetic properties of the solar plasma
(Viticchié and Almeida, 2011). Over the past two decades, many approaches
aimed at deriving the solar atmosphere parameters have been developed. Despite
great capabilities provided by these techniques, in many cases, the derivation
of the atmospheric parameters from the observed spectra – the inverse problem
– requires huge computing resources.

The formation of the spectral line in the solar atmosphere is described by the
radiation transfer equation (RTE, Landi Degl’Innocenti and Landolfi, 2004). In
turn, the polarization of light, which appears due to Zeeman splitting of the
spectral line in an external magnetic field, can be described by four
components I, Q, U, and V of the observed Stokes vector (Kuckein et al.,
2021).

In the general case, the complexity of the RTE makes it impossible to solve
the inverse problem analytically, that is, to obtain the solar atmosphere
parameters from the observed Stokes profiles. Certain simplifications and
approximations are often used to solve the RTE, for instance, the Milne-
Eddington (ME) model of the atmosphere (Unno, 1956; Landi Degl’Innocenti and
Landolfi, 2004; del Toro Iniesta and Ruiz Cobo, 2016). The model assumes a
local thermal equilibrium and independence of the atmosphere parameters with
height. Nevertheless, in such a case, the solution of the RTE is still non-
linear and transcendent.

To fill the gap between theoretical models and complex simulations, special
tools called inversion codes are developed. These codes are classified
according to the optimization strategies used to find the optimal set of
atmospheric parameters that generate spectra closest to the observed ones
(Lites et al., 2007). In most cases the procedure is based on non-linear least
squares optimization with the simplified atmospheric model. More complicated
models exist, that take into account height-dependent distribution of
atmospheric parameters (non-local thermal equilibrium).

Data for training, validation and testing contain spectropolarimetric images
where each pixel of the image corresponds to an area on the Sun’s surface with
its spectral profile. These images are converted into a three-dimensional data
set $(x,y,\lambda)$, in which $\lambda$ is the width of the pixel spectral
line with coordinates $(x,y)$. In this context, a data dimensionality problem
arises: each pixel of an image is equal to one independent inversion problem.
This makes the methods based on optimization techniques computationally
expensive. As an example, to analyze data from the Helioseismic and Magnetic
Imager (HMI) on-board of the Solar Dynamics Observatory (SDO) using Very Fast
Inversion of the Stokes Vector (VFISV, Borrero et al., 2011), 50 CPUs were
used in parallel to reach a 10-minute cadence, including specific limitations,
such as additional assumptions for the atmospheric model and low spectral
resolution. Also, the result depends on the closeness of the initial
approximation to the true value of the parameters. Furthermore, the
atmospheric model itself is a multi-dimensional problem. In the simple basic
ME model, there is a set of 11 atmospheric parameters which form a manifold in
the parameters space. As a result, the inversion task became ill-conditioned
and it may lead to instability of estimations or even multiple solutions. That
is why a proper estimation of the uncertainty becomes an important issue.

As a possible solution to overcome the computational problems, a neural-
network based solution was proposed (Carroll and Staude, 2001). The main idea
of this approach is to use neural networks for direct inversion by studying
the mapping between Stokes profiles and atmospheric parameters. In the
multiple studies this approach has shown to be effective, however in most
cases the uncertainty estimation problem still need to be solved. This is
connected to a large number of parameters the neural solutions operate, which
requires a lot of computing power to scan (Ghahramani, 2015; Krzywinski and
Altman, 2013). In the following text, we provide a review of main studies
connected with a neural network application to Stocks inversion problems and
current state of uncertainties estimation. The list with a short description
and links to the paper known to us related to the Stokes inversion problem is
summarized in Tab. (3).

In one of the first papers (Carroll and Staude, 2001), several neural networks
were used for parameters recovering from the atmosphere model with temperature
stratification. DIAMAG synthesis codes (Grossmann-Doerth, Knölker, and
Schuessler, 1994), on the basis of the nine semi-empirical model atmospheres,
with temperature and pressure stratification, were used to generate an input
database consisting of I, Q, U and V profiles. As a result, for each observed
profile, the probability that this particular model has been responsible for
producing it was calculated. Next, the MLP network was trained for each of the
nine models to recover several atmospheric parameters, including three
components of magnetic field vector, velocities and turbulence.

Ramos and Baso (2019) developed inversion codes of atmospheric physical
properties, based on a fully convolutional neural network, trained on
synthetic Stocks profiles generated with the state-of-the-art MPS/University
of Chicago Radiative (MURaM) MHD codes, which are three-dimensional magneto-
hydrodynamic numerical simulations of different structures of the solar
atmosphere. The authors have shown that this approach gives results comparable
to those of standard inversion techniques. Gafeira et al. (2021) pointed out
that neural network based methods failed to take into account the physical
connections between the parameters and physical model and suggested using
neural networks, not as a tool to assist inversion, but precisely as an
initial guess for further Stokes profile inversions.

Another approach, based on real data, was described in (Guo et al., 2021) or
(Liu et al., 2020). The authors of the latter used real data taken from the
Near InfraRed Imaging Spectropolarimeter at the Big Bear Solar Observatory.
Standard ME inversion codes were used for data labeling; after that, the
convolution neural networks were trained to match the input spectrum and
inverted with the ME codes parameters. The authors show that neural networks
learn to approximate ME inversion results very closely. The main result of
this paper was in computational efficiency compared to ME codes. Two-
dimensional convolutions can increase the potential of a model by taking into
account spatial correlations in Stokes parameters and correlations along the
optical beam. As a result, the model can provide a three-dimensional cube of
parameters of the studied region, taking into account the geometric height,
and the ability to recover parameters that cannot be recovered using the
classic approaches.

The decline in the performance of neural network models trained on synthetic
spectra is demonstrated in the article (Socas-Navarro, 2005) for the task of
restoring magnetic field strength. Two approaches are proposed in this article
to address this deficiency. Preprocessing of the observed profiles in order to
project them onto ME hyperspace allows the efficient finding of ME profiles
closest to the observed ones, which are the input of the neural network model.
As such, the article uses Auto-associative Neural Networks (AANNs) – models
that have at least one intermediate layer with fewer neurons than the input
and output layers. The description of other methods of preprocessing, such as
PCA and Expansion in Hermitian Functions (EHF) and their comparison with AANN
can be found in (Socas-Navarro, 2005). The second approach is to regularize
the model, in order to weaken its attention to small deviations from the ideal
form, which have unprocessed synthetic profiles. To do this, artificial
perturbations can be added to the profiles to violate their symmetry.

Several architectures containing multi-layer perceptron (MLP) blocks were
compared in the paper (Knyazeva et al., 2022) using data with synthetic
spectra. Three models were considered: one with individual MLP blocks to
recover each parameter separately, one with a common MLP model for all
parameters and a partly sharing model consisting of a common MLP block and
independent MLP blocks, each of which corresponded to a certain parameter. It
was found that the partly sharing model shows the best performance.

Within the last several years, various approaches have been developed to
estimate the prediction uncertainty. These methods can be split into four
groups, based on the number and the nature of the used neural networks
(Lakshminarayanan, Pritzel, and Blundell, 2017): single deterministic methods,
where the uncertainty on a prediction is computed based on one single forward
pass within a deterministic network (Malinin and Gales, ), Bayesian methods
that contain uncertainty in their networks, assuming that parameters are
defined as some probability distributions (Blundell et al., 2015),
augmentation methods, which are based on the modification of the training data
set, so a model learns on the extended data (Shorten and Khoshgoftaar, 2019),
and ensembles, which derive a final prediction based on other predictions
received from multiple ensemble members (Lakshminarayanan, Pritzel, and
Blundell, 2017).

Figure 1.: Two-dimensional color maps of Stokes profiles inversion by Milne-
Eddington codes HAO ”MERLIN” (reference values).

One of the probabilistic approaches to solving the inverse problem is to use
algorithms based on the Bayesian inference, such as the Markov Chain Monte
Carlo (MCMC) and Nested Sampling (NS). Despite limitations in their
applicability, even for relatively simple atmospheric models and requirements
of detailed knowledge of the parameter space, Bayesian approaches have long
been used in solar physics analysis (Li et al., 2019; Ramos, González, and
Rubiño-Martín, 2007). An alternative to these may be variational inference
methods, for example, normalizing flows, where the true distribution of the
solution is approximated by a simpler analytical one (Baso, Ramos, and de la
Cruz Rodríguez, 2022; Ramos et al., 2017). However, the disadvantage of such
models is that their optimization is not always stable, so one has to consider
the more simple, posterior distribution.

Recently, it has been proposed to use a single deterministic network to
quantify uncertainties in the prediction of atmospheric parameters (Higgins et
al., 2021, 2022). The authors of these papers suggest to obtain confidence
intervals treating the problem as a regression by classification, so the model
predicts for each pixel of the parameter image the distribution of its
possible values by applying the softmax function.

In this paper, we focus on the uncertainty estimation using a combination of
several convolutional neural networks, modified in such a way that they can
quantify the uncertainty of predictions (treating the observed value as a
sample from a Gaussian distribution) and trained as an ensemble. To the best
of our knowledge, this is the first systematic study of these approaches
within the framework of the inverse solar problem.

##  2 Uncertainty Quantification and Metrics

Experimental measurement uncertainty plays a central role in physical
sciences. The assigned uncertainties can point to the reliability of the
measurement. That is why, currently, the interpretation of uncertainty plays a
crucial role in the analysis of the experiment. In this paper, we follow the
most frequent interpretation, which leads to an important consequence: the
methods proposed should estimate interval with a given confidence, that is
provide experimental coverage probability for a given confidence level. This
in turn means obtaining the rate at which the true value is contained in the
confidence interval of an individual measurement (Pawitan, 2001).

Figure 2.: Network architecture used in atmospheric parameters inferring. The
model has 22 independent MLP blocks, corresponding to the mean and the
variance of 11 atmospheric parameters, one common MLP block and 6 common
convolutional blocks of two types. Blocks of the second type contain the
following layers: one-dimensional convolution, batch normalization, ELU
activation function and dropout. In blocks of the first type the max pooling
layer is added.

We check the correctness of the procedure using a graphical representation as
shown later in Figs. (5) and (6). We also use integral metrics to estimate how
accurately we evaluate the confidence of our model: the normalized Mean
Squared Error (nMSE) (Quinonero-Candela et al., 2005), the Negative Log
Predictive Density (NLPD) (Quinonero-Candela et al., 2005) and the Prediction
Interval Coverage Probability (PICP) (Shrestha and Solomatine, 2006) with two
different fractions of the distribution inside the confidence interval. The
nMSE is defined as

$\text{nMSE}=\sqrt{\frac{1}{N}\sum_{i=1}^{N}\frac{\left(t_{i}-m_{i}\right)^{2}}{\sigma_{i}^{2}}},$
(1)

where $m_{i}$, $\sigma_{i}^{2}$ are the mean and variance of the predictive
distribution, respectively, $N$ denotes the total number of pixels (the size
of a test data set) and $t_{i}$ is a true sample. The NLPD is defined as

$\text{NLPD}=\frac{1}{N}\sum_{i=1}^{N}\left(\frac{\left(t_{i}-m_{i}\right)^{2}}{2\sigma_{i}^{2}}+\log{\sigma_{i}}+c\right),$
(2)

where $c$ is a constant independent of $m_{i}$ and $\sigma_{i}$. Specifying
the upper $\text{PL}_{i}^{U}$ and lower $\text{PL}_{i}^{L}$ bounds on a
prediction $i$ (the uncertainty on a single observation) one can calculate the
prediction interval coverage probability metric (PICP). The PICP is defined as
the probability that the real value lies within the predicted confidence
interval and estimated as a following frequency:

$\text{PICP}=\frac{1}{N}\sum_{i=1}^{N}m_{i},~{}~{}m_{i}=\begin{cases}1,&\text{PL}_{i}^{L}\leq
t_{i}\leq\text{PL}_{i}^{U}\\\ 0,&\text{otherwise}\end{cases},$ (3)

where $t_{i}$ is the $i$-th element of the reference data set. Both the nMSE
and PICP metrics most penalize the cases of incorrect forecasts made with
uncertainty close to zero. However, PICP is sensitive both when the prognosis
is not sufficiently certain and when it is over-confident. The PICP value
should be close to the $\alpha$, however over-confident predictions are worse
for the model.

These metrics show the overall performance of the algorithm, while the local
performance might vary depending on the point in the parameter space.

Figure 3.: Two-dimensional color maps of parameters predicted by the model.

##  3 Data and methods

The solution of the inverse problem requires, at the first stage, the initial
approximation of the Stokes profiles. These profiles can be generated
synthetically using atmospheric models, and this method has been shown to be
highly effective (Knyazeva et al., 2022). ME codes obtained from the
Hinode/SOT/SP database were used to collect 5.3 million synthetic records of
the state of the solar atmosphere. Generated spectra were made more similar to
real samples by adding Gaussian noise, and then were used for training.

In the following study, we consider 11 parameters of the solar atmosphere: the
magnetic field vector, consisting of field strength component, inclination
angle and azimuth angle; line parameters, consisting of Doppler width, line
damping and line strength; two intensity parameters, consisting of source
function (SF) and its height gradient; Doppler shift (DS) of the line; stray
light Doppler shift and magnetic filling factor. Before training, true samples
of parameter values were transformed by applying logarithmic transformation to
magnetic field vector and trigonometric to magnetic field inclination and
azimuth angles and were brought to one scale with min-max normalization. The
example of color maps is shown in Fig. (1).

Parameter | R2 | MSE | MAE | NLPD | nRMSE | PICP68 | PICP95
---|---|---|---|---|---|---|---
Field Strength | 0.914 | 0.0015 | 0.019 | -2.735 | 0.977 | 0.792 | 0.959
Field Inclination | 0.952 | 0.0034 | 0.025 | -2.356 | 1.079 | 0.808 | 0.959
Field Azimuth | 0.735 | 0.0313 | 0.093 | -1.356 | 0.721 | 0.866 | 0.982
Doppler Width | 0.970 | 0.0005 | 0.015 | -2.676 | 0.874 | 0.756 | 0.977
Damping | 0.934 | 0.0015 | 0.019 | -2.658 | 0.869 | 0.770 | 0.974
Line Strength | 0.821 | 0.0025 | 0.019 | -2.790 | 0.913 | 0.795 | 0.968
SF | 0.903 | 0.0005 | 0.013 | -2.769 | 0.848 | 0.781 | 0.978
Cont. SF Grad. | 0.981 | 0.0002 | 0.009 | -3.195 | 0.819 | 0.797 | 0.982
DS | 0.956 | 0.0001 | 0.004 | -4.220 | 0.779 | 0.820 | 0.984
Filling Factor | 0.859 | 0.0096 | 0.062 | -1.345 | 0.963 | 0.754 | 0.954
Stray Light DS | 0.639 | 0.0023 | 0.014 | -1.875 | 1.773 | 0.858 | 0.973
Table 1.: Performance metrics of the convolutional model.

We used a single deterministic method to evaluate the predictive uncertainty
and modified architecture of the partial sharing model (Knyazeva et al., 2022)
in such way that it predicted two values in the final layer for each pixel,
corresponding to the mean $\mu(\mathbf{x})$ and the variance
$\sigma^{2}(\mathbf{x})>0$. The proposed model consists of 22 independent MLP
blocks, corresponding to the mean value and the standard deviation of each
pixel in case of 11 atmospheric parameters. Independent blocks took on the
input the result of one common MLP block, which in turn was after 6 common
convolutional blocks of two types. Blocks of the first type contain the
following layers: one-dimensional convolution with kernel size 3, max pooling
with kernel size 2, batch normalization, ELU activation function and dropout.
In blocks of the second type the max pooling layer is excluded. It was
reasonable to add convolutional blocks to the model, since Stokes profiles are
usually interconnected. The schematic representation of the architecture is
shown in Fig. (2).

Treating the observed value as a sample from a Gaussian distribution the model
was trained by minimizing the negative logarithm loss function (Gawlikowski et
al., 2021):

$L(\theta,y,\mathbf{x})=-\frac{1}{MK}\sum_{i=1}^{M}\sum_{j=1}^{K}\log\left(\frac{1}{\sqrt{2\pi}\sigma_{\theta
ij}(\mathbf{x})}\exp\left[-\frac{(y_{ij}-\mu_{\theta
ij}(\mathbf{x}))^{2}}{2\sigma_{\theta ij}^{2}(\mathbf{x})}\right]\right),$ (4)

where $\mu_{\theta}(\mathbf{x})$ and $\sigma_{\theta}(\mathbf{x})$ – predicted
average value and standard deviation, respectively, $K=11$ and $M=128$ are the
number of parameters that were considered and the batch size, respectively.
The Adam optimizer was used for the iterative update of the model weights. The
model was found to achieve the required result in 5 epochs.

Figure 4.: Dependence of predictions on the true values. Each figure
corresponds to one of the atmospheric parameters. Red dashed lines represent
pixels whose predictions are equal to the true values. Color intensity
indicates the frequency of the values encountered.

While other methods exist (Gawlikowski et al., 2021), in order to obtain an
estimate a scan of the loss-function can be used. This requires a lot of
computing resources, is why approximate methods are implemented. These methods
allows for the estimate of the minimum width, however, their performance
depends on the problem. We test the ensemble-based model (Lakshminarayanan,
Pritzel, and Blundell, 2017), which is shown to perform well in open datasets.
The model described above was used to build an ensemble of several models,
that were trained independently on different training sub-samples. The final
prediction was treated as a uniformly weighted mixture of Gaussian
distributions, and the combination of results was determined as follows:

$\displaystyle\mu_{*}(\mathbf{x})$
$\displaystyle=\frac{1}{N}\sum_{i=1}^{N}\mu_{\theta i}(\mathbf{x}),$ (5)
$\displaystyle\sigma_{*}^{2}(\mathbf{x})$
$\displaystyle=\frac{1}{N}\sum_{i=1}^{N}\left(\sigma_{\theta
i}^{2}(\mathbf{x})+\mu_{\theta
i}^{2}(\mathbf{x})\right)-\mu_{*}^{2}(\mathbf{x}),$

where $\mu_{\theta i}(\mathbf{x})$, $\sigma_{\theta i}(\mathbf{x})$ are the
mean and the standard deviation of the $i$-th model, respectively, and $N=6$
is the number of models used. Predicted values were scaled back into their
physical ranges after training to correctly interpret the results.

##  4 Results

For each parameter, we compared its ME-calculated values with our network
inferred values and computed performance metrics. Three quality metrics are
the following: coefficient of determination R2, the mean squared error (MSE)
and the mean absolute error (MAE). Additionally, we show the metrics that
characterize the uncertainty region, as defined in Sec. 2.

Parameter | R2 | MSE | MAE | NLPD | nRMSE | PICP68 | PICP95
---|---|---|---|---|---|---|---
Field Strength | 0.957 | 0.0007 | 0.015 | -2.953 | 1.005 | 0.692 | 0.957
Field Inclination | 0.986 | 0.0010 | 0.017 | -2.740 | 1.002 | 0.706 | 0.959
Field Azimuth | 0.832 | 0.0188 | 0.064 | -2.013 | 0.925 | 0.752 | 0.965
Doppler Width | 0.976 | 0.0004 | 0.014 | -2.764 | 1.009 | 0.683 | 0.953
Damping | 0.967 | 0.0005 | 0.014 | -2.820 | 1.010 | 0.687 | 0.951
Line Strength | 0.874 | 0.0009 | 0.014 | -3.003 | 1.038 | 0.708 | 0.948
SF | 0.911 | 0.0004 | 0.013 | -2.834 | 0.965 | 0.706 | 0.962
Cont. SF Grad. | 0.983 | 0.0001 | 0.008 | -3.265 | 0.953 | 0.710 | 0.964
DS | 0.970 | 0.0001 | 0.004 | -4.305 | 0.959 | 0.710 | 0.962
Filling Factor | 0.882 | 0.0068 | 0.054 | -1.564 | 0.989 | 0.692 | 0.958
Stray Light DS | 0.907 | 0.0005 | 0.009 | -3.414 | 1.022 | 0.750 | 0.960
Table 2.: Performance metrics of the convolutional model ensemble.

The data for training and validation were collected in such a way that they
contained both the quiet and active areas of the Sun. The reference values
$x_{true}$ refer to the result of Stokes profiles inversion by the ME codes
HAO ”MERLIN” (Community Spectropolarimetric Analysis Center (CSAC), 2006b)
(see Fig. (1)). The metrics are represented in Tab.(1). It can be seen that
all the prediction parameters are covered by confidence intervals. The two-
dimensional color maps of the 11 reconstructed parameters are visualized in
Fig. (3) and comparison of these with the reference values can be seen in Fig.
(4).

To estimate the performance of the method we also suggest plotting several
dependencies. The scatter plots of the the standard deviation $\sigma_{pred}$
on the difference $x_{true}-x_{pred}$ are presented in Fig. (5). Color
intensity indicates the frequency of the values encountered. As one can see,
the areas with the highest concentration of points are located near the zero
error line. However, in the edges of the parameters, there are significant
deviations of predictions from the reference values. The reason for this
behavior could be the small number or complete absence of samples with such
parameter values in training data.

Figure 5.: Dependence of standard deviations on the difference between
predictions and true values. Each figure corresponds to one of the atmospheric
parameters. Color intensity indicates the frequency of the values encountered.

For further analysis, dependencies of the ratio
$(x_{true}-x_{pred})/\sigma_{pred}$ on the true values $x_{true}$ in case of
each parameter were divided into approximately $500$ segments, and then each
segment was fitted by a normal distribution. These fitting curves can be seen
in Fig. (6). In the ideal case, the mean values have to be close to $0$, while
the standard deviations have to be in the range $\\{-1;1\\}$. It can be seen
that for some parameters there are deviations from the ideal scenario. Regions
known as the most difficult to reconstruct (such as low Field Strength) have
some over- or under-estimation of uncertainty, but not more than 30%.

Figure 6.: Analysis of the difference between predictions and true values
divided by standard deviation as a function of true values. Being segmented,
these data were fitted by a normal distribution, then the dependence of the
parameters of this approximation on the true data was constructed. Each figure
corresponds to one of the atmospheric parameters. In case of one single model,
mean values are marked by solid orange lines and the confidence intervals are
by translucent orange areas. The average curves obtained from an ensemble are
marked by solid green lines, the corresponding confidence intervals by
translucent green areas. Figure 7.: Two-dimensional color maps of the results
of Stokes profiles inversion by the ME codes HAO ”MERLIN”, model predictions
made on real data of Stokes profiles and results of uncertainty estimation in
these predictions. Each column corresponds to one of the first 10 atmospheric
parameters. For each parameter, the true values are shown in the first line,
predictions in the second line and results of uncertainty estimation in the
third line.

In addition, an ensemble was created in order to improve the quality of
predictions based on single convolutional models and using bagging. The
performance metrics of the ensemble can be seen in Tab. (2). A comparison of
the results obtained by one model and the ensemble of models is in Fig. (6).
As can be seen, the use of ensembles leads to a reduction of prediction
variance and smoothing of the results.

##  5 Testing on the real Hinode observations

The model was also tested on the real data, Hinode/SOT/SP observations
(Community Spectropolarimetric Analysis Center (CSAC), 2006a) collected on 26
September 2014 for NOAA 12172 active region, that is 12 times smaller than the
size of our train data set. Comparison between the predictions made from the
real Stokes parameters and the test data is on the Fig. (7). It can be seen
that the new approach infers atmospheric parameters with an accuracy
comparable to the ME inversion technique.

It could also be noted that the model provides physically adequate
uncertainties. For example, regions of weak magnetic field (where Stokes Q, U
and V parameters have low amplitudes, and, thus, bad signal-to-noise ratio)
correspond to predictions with larger uncertainties for the magnetic field
vector. At the same time, pixels with strong magnetic field (where all 4
Stokes parameters suffer from low signal-to-noise ratio cause lack of light
intensity) match predictions with big uncertainties for almost all of the
parameters.

In some of the more noisy regions of the Sun, the model predicts less accurate
and over confident results, thus leaving space for improvement of the model as
well as the method of generating synthetic spectra. We assume that performance
quality and robustness to out-of-distribution samples can be improved if the
synthetic generation algorithm is upgraded, since synthetic profiles are
usually symmetrical, while distribution of the real data could be uneven and
asymmetrical.

##  6 Conclusion and discussion

Machine learning, in particular the neural network approach to Stokes profile
inversion, is gaining popularity due to computational efficiency, but physical
models often require not only point estimates, but also errors. In this paper
we provide a novel neural network architecture for inferring solar atmospheric
parameters, together with their predictive uncertainties by modifying model
architecture and loss function. The method was tested on the 11 atmospheric
parameters: three components of the magnetic field vector, three line
parameters, two intensity parameters, Doppler shift of the line, stray light
Doppler shift and magnetic filling factor. The several performance metrics
were calculated (R2, MSE, MAE, NLPD, nRMSE, PICP68, and PICP95) in case of
synthetic data, as well as real Hinode observations collected on 26 September
2014 for NOAA 12172 active region. The maps of Stokes profiles inversion by
Milne-Eddington codes HAO ”MERLIN” were taken as a ground truth, and about a
minute was required for the model to make predictions of one map of
512$\times$873 pixels. Analysis showed that the proposed model represents a
reliable method compared with classical methods for solving the inverse
problem. In addition, it has been shown that the smoothness and the accuracy
of results, and the width of the uncertainty intervals can be improved by
ensembles. On a reduced set of observations, we show that the proposed method
provides reasonable results and thus, can be used to improve theoretical
calculations and provide a starting point for more precise methods, thus
making it possible to reduce the total computation time. Although synthetic
spectra are symmetric, which is unusual for the real data, the model trained
on synthetic spectra showed the ability to generalize even in the case of real
observations.

The method proposed can be used for analysis in various fields of astrophysics
(Podladchikova et al., 2022; Okamoto et al., 2009): in the analysis of the
solar cycle and prediction of coronal mass ejection, in the analysis of the
solar atmosphere itself, for example, to study the spatial distribution of
parameters or of the processes in the solar atmosphere such plasma convection,
and open prospects for future studies. Further analysis raises the question of
the credibility of the results obtained by the network. The model described is
a simple and scalable method for quantifying uncertainty. Since it
necessitates only a modification of architecture (doubling the number of
output layers and changing the loss function), it requires as much learning
time as a network that is not modified.

Reference | Network architecture | Input data | Output data
---|---|---|---
Carroll and Staude, 2001 | MLP blocks | Synthetic |  | MF, V, FF
---
and other
| Socas-Navarro, 2005
---
| MLP blocks
---
| Synthetic and real
---
from High Altitude
Observatory (HAO)
| MF, DW,
---
SF, FF, LD
and other
Ramos et al., 2007 |  | Bayesian
---
inference
Synthetic | MF
Ramos et al., 2017 |  | Variational
---
inference
| Real from
---
Swedish Solar
Telescope (SST)
| MF
---
Ramos and Baso, 2019 |  | CNN with 2D
---
convolutions
Synthetic |  | MF, V, T
---
and other
Sainz Dalda et al., 2019 |  | MLP blocks
---
Synthetic |  | V, T and other
---
Li et al., 2019 |  | Bayesian
---
inference
Synthetic |  | MF, V, DW,
---
SF + SFG,
LD and other
Liu et al., 2020 |  | CNN with 1D
---
convolutions
| Real from
---
Goode Solar
Telescope (GST)
| MF
---
Milić and Gafeira, 2020 |  | CNN with 1D
---
convolutions
Synthetic |  | MF, V, T
---
Gafeira, 2021 |  | Ensemble of
---
CNNs with 1D
convolutions
| Synthetic and
---
real from Gregor
telescope
| MF, V, T
---
Guo et al., 2021 |  | CNN with 2D
---
convolutions
| Real from
---
Hinode telescope
| MF
---
Higgins et al., 2021 |  | CNN (U-Net),
---
treating the problem
as a regression
by classification
| Real from Solar
---
Dynamics
Observatory (SDO)
| MF, DW,
---
SF + SFG,
and other
Baso et al., 2022 |  | Variational
---
inference
| Synthetic and real
---
from Swedish Solar
Telescope (SST)
| V, T, DW,
---
SF + SFG
and other
Knyazeva et al., 2022 | MLP blocks | Synthetic |  | MF, DW, FF,
---
SF + SFG,
LD and other
Higgins et al., 2022 |  | CNN (U-Net),
---
treating the problem
as a regression
by classification
Synthetic |  | MF, FF
---
and other
Present work |  | Ensemble of CNNs
---
with 1D convolutions
and uncertainty
quantification
| Synthetic and
---
real from Hinode
telescope
| MF, DW, FF,
---
SF + SFG,
LD and other
Table 3.: Overview of neural network studies in Stocks inversion problem. The
following abbreviations have been used in this table: Magnetic Field (MF),
Velocity (V), Temperature (T), Source Function and its Gradient (SF and SFG),
Doppler Width (DW), Filling Factor (FF) and Line Damping (LD).

## Data Availability

In the current study, we used a collection of the Level 1 calibrated Stokes
spectra (comprised by images stored in FITS format) and collection of the
Level 2 data sets (obtained from the MERLIN spectral line inversion of the
Level 1 calibrated spectra) produced by the Spectropolarimeter (SP) on board
the Hinode, since its launch in 2006. Hinode is a Japanese mission, developed
and launched by ISAS/JAXA, with NAOJ as a domestic partner and NASA and STFC
(UK) as international partners. It is operated by these agencies in co-
operation with ESA and NSC (Norway). The Hinode has an open data policy,
allowing anyone access to the data and data products. Level 1 and 2 data are
available by following the data link.

## Acknowledgements

Denis Derkach, Lukia Mistryukova, Aleksandr Khizhik and Mikhail Hushchyn are
grateful to the HSE basic research program. This research was supported in
part through computational resources of HPC facilities at HSE University
(Kostenetskiy, Chulkevich, and Kozyrev, 2021).

## References

  * Baso, Ramos, and de la Cruz Rodríguez (2022) Baso, C.J.D., Ramos, A.A., de la Cruz Rodríguez, J.: 2022, Bayesian stokes inversion with normalizing flows. A&A.
  * Blundell et al. (2015) Blundell, C., Cornebise, J., Kavukcuoglu, K., Wierstra, D.: 2015, Weight uncertainty in neural networks, arXiv.
  * Borrero et al. (2011) Borrero, J.M., Tomczyk, S., Kubo, M., Socas-Navarro, H., Schou, J., et al.: 2011, VFISV: Very Fast Inversion of the Stokes Vector for the Helioseismic and Magnetic Imager. Sol. Phys. 273(1), 267\.
  * Carroll and Staude (2001) Carroll, T.A., Staude, J.: 2001, The inversion of Stokes profiles with artificial neural networks. A&A 378, 316\.
  * Community Spectropolarimetric Analysis Center (CSAC) (2006a) Community Spectropolarimetric Analysis Center (CSAC): 2006a, Hinode-spectropolarimeter (sp) level 1 (calibrated) full stokes data, UCAR/NCAR - HAO/Community Spectropolarimetric Analysis Center.
  * Community Spectropolarimetric Analysis Center (CSAC) (2006b) Community Spectropolarimetric Analysis Center (CSAC): 2006b, Hinode-spectropolarimeter (sp) level 2 (vector magnetic field) spectral line inversions, UCAR/NCAR - HAO/Community Spectropolarimetric Analysis Center.
  * Dalda et al. (2019) Dalda, A.S., , de la Cruz Rodríguez, J., Pontieu, B.D., Gošić, M.: 2019, Recovering thermodynamics from spectral profiles observed by IRIS: A machine and deep learning approach. Astrophys. J. Lett. 875(2), L18.
  * del Toro Iniesta and Ruiz Cobo (2016) del Toro Iniesta, J.C., Ruiz Cobo, B.: 2016, Inversion of the radiative transfer equation for polarized light. Liv. Rev. Sol. Phys. 13(1).
  * Gafeira et al. (2021) Gafeira, R., Suárez, D.O., Milić, I., Noda, C.Q., Cobo, B.R., et al.: 2021, Machine learning initialization to accelerate stokes profile inversions. A&A 651, A31.
  * Gawlikowski et al. (2021) Gawlikowski, J., Tassi, C.R.N., Ali, M., Lee, J., Humt, M., et al.: 2021, A survey of uncertainty in deep neural networks. arXiv preprint arXiv:2107.03342.
  * Ghahramani (2015) Ghahramani, Z.: 2015, Probabilistic machine learning and artificial intelligence. Nature 521(7553), 452\.
  * Grossmann-Doerth, Knölker, and Schuessler (1994) Grossmann-Doerth, U., Knölker, M., Schuessler, M.: 1994, The deep layers of solar magnetic elements. Astronomy and Astrophysics 285, 648\.
  * Guo et al. (2021) Guo, J., Bai, X., Liu, H., Yang, X., Deng, Y., et al.: 2021, A nonlinear solar magnetic field calibration method for the filter-based magnetograph by the residual network. A&A 646, A41.
  * Higgins et al. (2021) Higgins, R.E.L., Fouhey, D.F., Zhang, D., Antiochos, S.K., Barnes, G., et al.: 2021, Fast and accurate emulation of the SDO/HMI stokes inversion with uncertainty quantification. The Astrophysical Journal 911(2), 130\.
  * Higgins et al. (2022) Higgins, R.E.L., Fouhey, D.F., Antiochos, S.K., Barnes, G., Cheung, M.C.M., et al.: 2022, SynthIA: A synthetic inversion approximation for the stokes vector fusing SDO and hinode into a virtual observatory. The Astrophysical Journal Supplement Series 259(1), 24\.
  * Knyazeva et al. (2022) Knyazeva, I., Plotnikov, A., Medvedeva, T., Makarenko, N.: 2022, Multi-output deep learning framework for solar atmospheric parameters inferring from stokes profiles.
  * Kostenetskiy, Chulkevich, and Kozyrev (2021) Kostenetskiy, P.S., Chulkevich, R.A., Kozyrev, V.I.: 2021, HPC resources of the higher school of economics. Journal of Physics: Conference Series 1740(1), 012050\.
  * Krzywinski and Altman (2013) Krzywinski, M., Altman, N.: 2013, Power and sample size. Nature Methods 10(12), 1139\.
  * Kuckein et al. (2021) Kuckein, C., Balthasar, H., Noda, C.Q., Diercke, A., Arjona, J.C.T., et al.: 2021, Multiple stokes i inversions for inferring magnetic fields in the spectral range around cr 782 $\&$. A&A 653, A165.
  * Lakshminarayanan, Pritzel, and Blundell (2017) Lakshminarayanan, B., Pritzel, A., Blundell, C.: 2017, Simple and scalable predictive uncertainty estimation using deep ensembles. In: Advances in Neural Information Processing Systems, Nips’17.
  * Landi Degl’Innocenti and Landolfi (2004) Landi Degl’Innocenti, E., Landolfi, M.: 2004, Polarization in Spectral Lines, Springer Dordrecht.
  * Leka et al. (2022) Leka, K.D., Wagner, E.L., Griñón-Marín, A.B., Bommier, V., Higgins, R.: 2022, On identifying and mitigating bias in inferred measurements for solar vector magnetic field data, arXiv.
  * Li et al. (2019) Li, H., Xu, Z., Qu, Z., Sun, L.: 2019, MCMC inversion of stokes profiles. The Astrophysical Journal 875(2), 127\.
  * Li et al. (2022) Li, H., del Pino Alemán, T., Bueno, J.T., Casini, R.: 2022, TIC: A stokes inversion code for scattering polarization with partial frequency redistribution and arbitrary magnetic fields. The Astrophysical Journal 933(2), 145\.
  * Lites et al. (2007) Lites, B., Casini, R., Garcia, J., Socas-Navarro, H.: 2007, A suite of community tools for spectro-polarimetric analysis. MemSAIt 78, 148\.
  * Liu et al. (2020) Liu, H., Xu, Y., Wang, J., Jing, J., Liu, C., et al.: 2020, Inferring vector magnetic fields from stokes profiles of GST/NIRIS using a convolutional neural network. ApJ 894(1), 70\.
  * (27) Malinin, A., Gales, M.: Predictive uncertainty estimation via prior networks. In: Advances in Neural Information Processing Systems, Curran Associates, Inc..
  * Milić and Gafeira (2020) Milić, I., Gafeira, R.: 2020, Mimicking spectropolarimetric inversions using convolutional neural networks. A&A 644, A129.
  * Okamoto et al. (2009) Okamoto, T., Tsuneta, S., Lites, B., Kubo, M., Yokoyama, T., et al.: 2009, Prominence formation associated with an emerging helical flux rope. The Astrophysical Journal 697.
  * Pawitan (2001) Pawitan, Y.: 2001, In all likelihood: Statistical modelling and inference using likelihood, OUP Oxford.
  * Podladchikova et al. (2022) Podladchikova, T., Jain, S., Veronig, A., Sutyrina, O., Dumbovic, M., et al.: 2022, Maximal growth rate of the ascending phase of a sunspot cycle for predicting its amplitude. A&A.
  * Quinonero-Candela et al. (2005) Quinonero-Candela, J., Rasmussen, C.E., Sinz, F., Bousquet, O., Schölkopf, B.: 2005, Evaluating predictive uncertainty challenge. In: Machine Learning Challenges Workshop, 1\. Springer.
  * Ramos and Baso (2019) Ramos, A.A., Baso, C.D.: 2019, Stokes inversion based on convolutional neural networks. A&A 626(August).
  * Ramos, González, and Rubiño-Martín (2007) Ramos, A.A., González, M.J.M., Rubiño-Martín, J.A.: 2007, Bayesian inversion of stokes profiles. A&A 476(2), 959\.
  * Ramos et al. (2016) Ramos, A.A., de la Cruz Rodríguez, J., Gonzalez, M.J.M., Yabar, A.P.: 2016, Inversion of stokes profiles with systematic effects. A&A 590, A 87.
  * Ramos et al. (2017) Ramos, A.A., de la Cruz Rodríguez, J., González, M.J.M., Socas-Navarro, H.: 2017, Inference of the chromospheric magnetic field orientation in the ca ii 8542 a line fibrils. A&A 599, A133.
  * Shorten and Khoshgoftaar (2019) Shorten, C., Khoshgoftaar, T.M.: 2019, A survey on image data augmentation for deep learning. Journal of Big Data 6(1).
  * Shrestha and Solomatine (2006) Shrestha, D.L., Solomatine, D.P.: 2006, Machine learning approaches for estimation of prediction interval for the model output. Neural Networks 19(2), 225\.
  * Socas-Navarro (2005) Socas-Navarro, H.: 2005, Strategies for spectral profile inversion using artificial neural networks. ApJ 621(1), 545\.
  * Unno (1956) Unno, W.: 1956, Line formation of a normal zeeman triplet. Publications of the Astronomical Society of Japan 8, 108\.
  * Viticchié and Almeida (2011) Viticchié, B., Almeida, J.S.: 2011, Asymmetries of the stokes v profiles observed by hinode sot/sp in the quiet sun. A&A 530, A14.