\section{Introduction}

  Optical imaging is without any doubt one of the main tools to
  investigate galaxies and dark matter through weak and strong
  gravitational lensing. Because of the large available data sets, it
  is crucial to extract all information available in noisy data and to
  simulate images precisely to calibrate the various methods
  and properly deal with possible biases. There is thus a pressing
  need to extract clean galaxy images from data.

  In particular, several studies have shown how all methods used to
  measure the ellipticity of galaxies require realistic simulations
  for their calibration
  \citep{viola11,bartelmann12,refrejer12,2012arXiv1204.5147M,massey13,gorvich16,bruderer16}.
  This issue is becoming pressing because of the stringent
  requirements posed by upcoming wide-field surveys such as the ESA
  Euclid space mission \citep{laureijs09} and the Large Synoptic
  Survey Telescope \citep{kaiser02}, among others. Galaxy models
  based on simple analytical recipes, for example based on the Sersic
  profile \cite{1968adga.book.....S}, have been widely used at this
  end \citep{heymans06,great08,kitching12}. These models have proven
  to well suffice for ground-based observations, but more accurate
  simulations are now necessary to include complex morphologies to
  account for spiral, irregular and cuspy galaxies.  Also in the
  strong gravitational lensing regime, accurate galaxy models are now
  needed to investigate the use of substructures of strongly magnified
  galaxies to better constrain the mass distribution of lenses such as
  for example galaxy clusters \citep{meneghetti08,zitrin15}.

  For these reasons, galaxies observed with HST have been modelled
  with shapelets \citep{refregier03,refregier03b,massey03,massey07}
  to achieve noise-free images. Even if this approach deals with complex
  morphologies, artifacts may arise because of the oscillatory
  behavior of shapelets. Moreover, also smooth galaxies such as for example
  ellipticals are not very well reconstructed by this approach because
  of their slope, which is not well compatible with a Gaussian,
  which the Hermite polynomials in the shapelets are derived from. Also, image
  cut-outs have been extracted from HST data
  \citep{rowe14,mandelbaum15}, but these stamps are affected by the
  instrumental noise limiting their applicability.

  In this paper, we present a method to retrieve and reconstruct clean galaxy
  images in a model-independent way, which also preserves the
  statistical properties of the reconstructed sample. We do this using
  Expectation Maximization Principal Components Analysis
  \cite{bailey12}, which we use to derive a set of orthonormal basis functions
  optimized for the specific data set to be processed. Other
  studies used standard PCA \citep{Jolliffe86} to model elliptical
  galaxies \citep{joseph14J}. However, these are galaxies with smooth
  morphology, and this method cannot deal with weights and missing
  data. In contrast, the procedure discussed in this work allows us to
  process astronomical images with masked areas and pixel-dependent
  variance, and it allows us to introduce regularization terms to be used
  when deriving the principal components and impose smoothness on the
  basis.

\begin{figure}
  \centering
  \includegraphics[width=1.0\hsize]{./fig/image-galaxy-split}
  \caption{This schematic representation shows how a postage-stamp of
    a galaxy image is rearranged in form of a vector, $\vec{d}_i$. All
    rows of pixels in the matrix composing the image are simply
    concatenated.}
  \label {fig:subaru-train-cov}
\end{figure}

\begin{figure*}
  \centering
  \includegraphics[width=0.33\hsize]{./fig/magDistribution_str-gal_clash}
  \hfill
  \includegraphics[width=0.33\hsize]{./fig/magError_str-gal_clash}
  \hfill
  \includegraphics[width=0.33\hsize]{./fig/mag-size_str-gal_clash}
  \caption {Statistical properties of the sources detected in the
    simulation and reproducing a Subaru image with 20 minutes of
    exposure time. A comparison with the real data is provided. From
    left to right, the panels show the magnitude distribution of the
    objects, their photometric error as a function of magnitude, and
    their size versus magnitude relation.
  }
  \label{fig:sim-stat}
\end{figure*}

As a test case, we analyzed $7038$ galaxies extracted from the
\cite{rafelski15} catalog with redshift up to $z<4.0$ and maximum
magnitude up to $m_{F775W}<30$. The catalog contains all photometric
information including the photometric redshifts of the objects. We
modeled these galaxies in all 5 optical bands extracted from the
Hubble eXtreme Deep Field \citep[XDF hereafter,][]{illingworth13}. We
tested the quality of the models by comparing their moment of
brightness against those measured with the weak-lensing Shapelens
library \citep{2011MNRAS.412.1552M}. Moreover we showed how to use
these models to construct realistic simulations of astronomical
images.

The structure of this paper is a follows: in Sec.~(\ref{sec:empca}), we
derive the EMPCA which are then used in Sec.~(\ref{sec:models}) to
create the models of the galaxy images. The description of the
analysis of the XDF data set in Sec.~(\ref{sec:models}), a simple sky
simulation based on our models is presented in
Sec.~(\ref{sec:simulations}), and the conclusions are given in
Sec.~(\ref{sec:conclusions}).

\section{A linear model for galaxy images}\label{sec:empca}

In this section, we discuss how to model the images of individual
galaxies to obtain a noise-free reconstruction. Let us now consider
the case in which we have one single object placed in the center of a
postage-stamp. This cut-out can be modeled as
\begin{equation} \label{eqn:datamodel}
  d(\vec{x})=g(\vec{x})+n(\vec{x})  \;,
\end{equation}
where $g(\vec{x})$ is the object contribution we are interested in,
$n(\vec{x})$ the one of the noise (e.g. photon noise, read-out noise,
dark current), and $\vec{x}\in\mathbb{R}^{2}$ denotes the position in
the image. For simplicity, we assume the noise to be uncorrelated with
standard deviation $\sigma$, defined by $\langle n_i\,n_j \rangle
=\sigma^2\,\delta(i-j)$. This 2-dimensional image $d(\vec{x})$,
consisting of $n=n_x \times n_y$ pixels, can be represented as a data
vector $\vec{d} \in \mathbb{R}^{n}$ whose elements $d(x_i)=d_i$ are
the intensities of the $i_{th}$ pixels. A visual impression of how
pixels are rearranged in a vector is shown in
Figure~(\ref{fig:subaru-train-cov}).

The most general linear model to describe this data element is
\begin{equation} \label{eqn:model}
  \tilde{d}(\vec{x})=\sum_{k=1}^M a_k \phi_k(\vec{x}) \;,
\end{equation}
where $\vec{\phi}_k\;$ is a collection of $M$ vectors,
$\left\{\vec{\phi}_k \;\in\; \mathbb{R}^{n} \;\mid\; k=1,...,M\right\}$. The
goal now is to define an optimal set of vectors $\phi_k$ capturing the
relevant signal and sort them depending on their information content
(power) such that each vector contains more information than the
following one.

Once this is achieved, the sm can be split into two terms
\begin{equation}\label{eq:model-split}
  d(\vec{x})=\sum_{k=1}^M a_k \phi_k(\vec{x}) + \sum_{M+1}^{n} a_k \phi_k(\vec{x}) = \tilde{g}(\vec{x}) + \tilde{n}(\vec{x}) \;,
\end{equation}
where now $\tilde{g}(\vec{x})$ is the model of the object we are
interested in, and $\tilde{n}(\vec{x})$ a term containing most of the
noise and a small, and hopefully negligible, amount of information.
The number of components, $M$, fixes the amount of information which
is going to be kept in the model and the amount of noise which is
going to be suppressed. Some information loss is inevitable, otherwise
one could fully recover the real image of the object which is
obviously an impossible task. A common way to achieve this
decomposition is provided by the Principal Component Analysis
\cite[PCA hereafter,][]{Jolliffe86} which takes advantage of the
entire data set, i.e. the postage-stamps of all galaxies in the
sample, $\left\{\vec{d}_j \;\in\; \mathbb{R}^n \;\mid\;
j=1,...,s\right\}$, and consists in finding the set of vectors,
$\vec{\phi}_k\; \in\;\mathbb{R}^{n}$, minimizing the quantity
\begin{equation}\label{eq:chisq}
  \chi^2 = \sum_{ij}^{n,s} \left(d_{ij}-\sum^n_{k=1}a_{kj}\phi_{ki}\right)^2 \;.
\end{equation}
In other words, we are looking for the model based on all coefficients,
$a_{jk}$, and vectors, $\vec{\phi}_k$, which best fit all images at
once. Here and throughout the paper, the index $i$ runs over the
number of pixels, $j$ over the number of galaxies, and $k$ over the
number of components which, in the case of the PCA, is equal to the
number of pixels. The coefficients of the $j_{th}$ galaxy are derived
with the scalar product $a_{kj}=\sum_id_{ji}\phi_{ki}$ or by linear
fitting if needed. Equation~(\ref{eq:chisq}) can be easily generalized
to account for correlated noise.

\begin{figure}
  \centering
  \includegraphics[width=0.98\hsize]{./fig/simulation-subru-basis_gal_no_lab}
  \caption{First six principal components, $\vec{\phi}_i$, derived
    from the noisy simulated image. The components are rearranged as
    images. From the data emerge the main features related to dipolar
    and quadrupolar structures as well as radially symmetric ones.}
  \label{fig:subaru-basis}
\end{figure}

\begin{figure}
  \centering
  \includegraphics[width=0.95\hsize]{./fig/simulation-subru-object_gal_neg_cut}
  \caption{One of the galaxies randomly extracted from the simulation
    for which we show the signal and noise splitting: in the left
    panel the original postage-stamps, $\vec{d}_j$, the model,
    $\vec{\tilde{g}_j}$ in the center and the residuals,
    $\vec{\tilde{n}_j}$ on the right.
}
  \label{fig:subaru-object}
\end{figure}

Usually, the principal components are found by diagonalizing the
centered covariance matrix of the data and ordering its eigenvectors
by decreasing eigenvalues, $\lambda_k$. Another way to find
the solution for the minimum of Equation~(\ref{eq:chisq}) is through
the Expectation Maximization Principal Components Analysis (EMPCA
hereafter). This is an iterative algorithm which consists in finding
one basis component at a time. To find the first component $\vec{\phi}_1$, we
start with a random vector (all its $n$ components have a random
value) with which we compute the first coefficient of all objects
through the scalar product previously defined,
$a_{1j}=\sum_id_{ji}\phi_{1i}$. These coefficients are then used to
update $\vec{\phi}_1$,
\begin{equation}
  \phi_1^{new}(\vec{x}) = \frac{\sum_j^s a_{1j} d_j(\vec{x})}{\sum_j^s
    a_{1j}^2} \;,
\end{equation}
which is renormalized for convenience and which now will fit the data
set better. The refined $\vec{\phi}_1^{new}$ vector is subsequently
used to compute a new set of $a_{1j}$ coefficients necessary for the
next iteration, and so on. This procedure is converging toward the
only absolute minimum of the $\chi^2$ function, as demonstrated by
\cite{srebro03}. In our case, this iterative process is stopped when
the variation in the principal component, $\vec{\phi}_1$, is smaller
that a certain value, $|\Delta\phi_1|<\epsilon$, which we set to
$\epsilon = 10^{-6}$. The next principal component,
$\vec{\phi}_{k+1}$, is found by applying the same procedure to that
part of the signal which has not been captured by the previous $k$
components,
\begin{equation}
  \phi_{k+1}^{new}(\vec{x}) = \frac{\sum_j^s a_{k+1 j}\, \tilde{n}_{j}(\vec{x})}{\sum_j^s a_{k+1 j}^2} \;.
\end{equation}
Here, $\tilde{n}_{j}(\vec{x}) = d_j(\vec{x})-\tilde{g}_{j}(\vec{x})$
is the residual part of the signal for which this component is
evaluated, and $\tilde{g}_{j}(\vec{x})=\sum_{l=1}^k a_{lj}
\phi_l(\vec{x})$ is the updated model of the $j-th$ galaxy. In analogy
to the derivation of the first component, the coefficients of the
$j-th$ galaxy, $a_{k+1\,j}=\sum_id_{ji}\phi_{k+1\,i}$, are based on
the previous iteration, and $\vec{\phi}_{k+1}^{new}$ is renormalized
each time. With this procedure we compute at the same time the
principal components, $\vec{\phi}_k$, the noise, $\tilde{\vec{n}}_j$,
and the signal estimate, $\tilde{\vec{g}}_j$, we are aiming at (see
Equation~\ref{eq:model-split}). The procedure ensures the
orthogonality of the principal components. The further advantages of
this method with respect to a geometrical interpretation of the
principal components are that it allows to take advantage of weights,
masks and the noise covariance by including them in the $\chi^2$ function,
and to impose further conditions on the basis such as for example a
regularization term to obtain smooth basis components \citep{bailey12}.

\begin{figure}
  \centering
  \includegraphics[width=0.98\hsize]{./fig/simulation-subru-eigenvalues_gal}
  \caption{Power of the principal components resulting for the
    simulation with Sersic galaxies (continuous line) and for the real
    Subaru image mimicked by the simulation (dashed line). The power
    has been normalized with respect to the total variance,
    $\sigma^2=\sum_k^n\lambda_k$. In both cases, their amplitude drops
    rapidly with the order. }
  \label{fig:subaru-eigenvalues}
\end{figure}

Here, we have derived smooth principal components by
bilateral smoothing during their construction. This is an edge-preserving
algorithm with an adaptive smoothing scale which allows to
leave those regions of the basis unaffected which show steep gradients that
would be blurred otherwise. The bilateral
smoothing implemented is based on the product of two Gaussians, one acting on
angular scales as it would do a normal convolution and another based on
the local luminosity gradient such that areas with ``sharp'' features
do not get smoothed (if the gradient is small the angular convolution
takes the lead, while it is made ineffective otherwise).

Alternatively, we used
a different regularization scheme base on a Savitzky–Golay filter
and obtained similar results. It is important to introduce this
regularization during the basis construction and not thereafter (by
smoothing the final basis or the models) to preserve the
orthonormality of the basis, the information present in the data, and
to make the basis more stable against noise
fluctuations.

Additionally, we reduced the scatter in the galaxy
morphologies by rotating the input images by multiples of $\pi/2$ such
as to have their position angle range between 0 and $90$ degrees. We
chose such discrete rotations instead of aligning the galaxies
along their major axes to avoid the introduction of any pixel
correlations.

\begin{figure*}
  \centering
  \includegraphics[width=0.48\hsize]{./fig/photo-distribution}
  \includegraphics[width=0.48\hsize]{./fig/redshift-distribution}
  \caption{Magnitude (left panel) and redshift
    distributions (right panel) of the sources with a maximum
    $\chi^2_{mod}$ of 4 for the BPZ redshift. The right panel shows
    the number of galaxies in the bins split according to their F775W
    magnitude.}
  \label {fig:cat-photo-z}
\end{figure*}

In the following, we focus on the caveats of this approach which one
should keep in mind to properly use it. First of all, the basis is
derived from noisy data, and this will of course impact on
them. This is relevant at higher orders where the EMPCA have to deal
with smaller and less prominent features approaching the noise regime,
as is clear from the discussion of Eq.~(\ref{eq:model-split}). Second,
the number of galaxies to produce the basis is limited, and a
small sample will not be representative of the entire
population. On the other hand, wide field surveys provide us with large data
sets which even allow to split the sample into subsets of galaxies with
similar properties (such as for example size or ellipticity) and
further reduce the data scatter for a better optimization of the
basis.

It is also preferable to compute the basis for the sample which has to
be processed and not on another independent set of images even if with
compatible size and quality. After all, the basis components are evaluated by
finding the optimal model of the specific data at hand. Third, the
regularization used to impose smoothness on the basis
might decrease the level of high frequency features
present in the data, if one wants to
use it at all. In any case, one can always decide and adapt the
regularization which better suits the case at hands.

One final remark about the point spread function (PSF): The PSF is not
an issue for this approach because it aims at the image as it
is. However, some care has to be taken if the models are going to be
used for weak-lensing purposes because the PSF ellipticity and
distortions may leave an imprint on the derived basis and thus on the
models based on them. It is easy to cope with this issue with the
procedure adopted in this work. In fact, the rotation applied to the
postage-stamps prevents any isotropy which my be induced by the PSF.

\section {Defining the number of components}\label{sec:sn-separation}

As discussed in Section~(\ref{sec:empca}), the number of basis components,
$M$, defines the amount of noise which is going to be suppressed and
the amount of information which is going to be kept in the model. Its
value depends on the specific task we have at hands. Various schemes
for the definition of $M$ have been proposed in the literature, for
instance through the analysis of the scree graph
\citep{cattell66,cattell77} or the log-eigenvalue diagram (LEV)
\citep{Farmer71,maryon79,beltrando90}. These approaches are not very
stable because they largely depend on specific features of these
diagrams which may not be well defined in certain cases. Other
approaches rely on a $\chi^2$ approach,
\begin{equation}\label{eq:chisq_new}
  \chi_j^2 = \sum_{i=1}^n (d_{ij}-\tilde{g}_{ij})^2 \,
\end{equation}
applied to each individual galaxy (not the overall set!) and which
better suits our needs \citep{ferre90}. Below, we discuss two criteria
aiming at different goals.
\begin{enumerate}

\item {\it Defining $M$ to minimize the model variance}: if we search
  for the model $\tilde{g}$ with the minimum variance, it is necessary
  to minimize the number of basis components. Here we seek for the
  smallest $M$, which will be specific for each individual object, by
  including one component at a time until a certain convergence
  criteria is reached, for instance until we obtain a reduced $\chi^2$
  close to unity or until the $\chi^2$ is not changing by more than a
  certain threshold. Formally this criterion reads $\left\{\,
  \mbox{min}\{k\} \in \mathbb{N} : \chi^2_k -\chi^2_{k+1}\le t
  \,\right\}$, where $t$ is the threshold to be set. A note of caution
  is in order here: by construction, the $\chi^2$ is monotonically
  decreasing with the order (at the order $n$ the $\chi^2$ will be
  zero) and under- or over-fitting might be an issue.  Moreover, the
  basis components are sorted by their information content (the higher
  the order, the less relevant is the component), but this sorting is
  based on the statistics of all objects in the sample and may not be
  proper for a specific object. It may happen that for a specific
  object, one of the higher-order components is more relevant than
  lower-order components, and the convergence process may stop before
  this component is reached.

\item {\it Defining $M$ to maximize model fidelity}: for ensuring not
  to miss any valuable signal, it is necessary to include all
  components, for instance by visually inspecting the basis or by
  finding the $M$ for which the expectation value of the global
  $\chi^2$ is the minimum. This $M$ can not be evaluated directly but
  it can be approximated by
  \begin{equation}\label{eq:expectationval}
    \hat{f}_q=\sum_{k=q+1}^n \hat\lambda_k + \sigma^2
    \left[ 2nq-n^2+2(n-q)+4\sum_{l=1}^q\sum_{k=q+1}^n\frac{\hat\lambda_l}{\hat{\lambda}_l-\hat{\lambda}_k} \right] \;,
  \end{equation}
  under the assumption of uncorrelated noise. Here, $\lambda_k$ is the
  power related to the $k-th$ component. The variance can be estimated
  as $\sigma^2_q=1/(n-q)\sum_{k=q+1}^n\lambda_k$ and
  $\hat{\lambda}_k=\frac{n-1}{n}\lambda_k$ \citep{ferre90}. With these
  criteria, $M$ is the same for all objects because it is based on the
  statistics of the entire data sample, in contrast to what we
  discussed in point (i) where the $\chi^2$ was evaluated for each
  individual object. This approach returns the highest ``fidelity''
  because the largest number of sensible components is used.
\end{enumerate}

\section {Simulation of ground base observations}\label{sec:simulation_ground}

To test the quality of the model reconstruction, we produced a set of
simulations with {\it EasySky}. {\it EasySky} allows to use any object
contained in a postage-stamp image, Sersic galaxies, galaxies with a
single or double Sersic components (bulge plus disc) in the same
fashion as the Great08 \citep{great08,kitching12} simulations, and stars
with a Moffat profile and arbitrary ellipticity (if stars are
to be included). The objects can be displaced in various ways: randomly across
the whole field-of-view, on a regular grid with stars on one side and
galaxies on the other, or on a regular grid but with the stars located
equidistantly from the other galaxies. The galaxies
can be (1) randomly rotated, (2) kept with their semi-major axes aligned
with one direction, (3) within the same quadrant, or (4) produced in
pairs with angles rotated by 90 degrees with respect to each
other. The latter configuration is a useful feature for weak-lensing
calibrations. The fluxes and sizes of both galaxies and stars can be
kept fixed or randomly distributed following a given luminosity
function to better re-sample the data to be simulated. The image can be
convolved with an arbitrary kernel, and a simple shear distortion can
be applied to the galaxies.

\begin{figure}
  \centering
  \includegraphics[width=1.0\hsize]{./fig/basis_4scales}
  \caption {The first four principal components for three different
    sets of galaxies. The upper, middle and bottom rows refer to
    galaxies with semi-major axis, $A$, within the range $5<A<7$,
    $18<A<20$, $50<A<60$, and $70<A<80$ pixels, respectively. The
    larger the galaxies are, the larger is the typical size of the principal
    component and the larger is their morphological complexity.}
  \label{fig:basis}
\end{figure}

Here, we describe a simple but quite realistic synthetic image which
we used to show the signal-to-noise splitting of
Eq.~(\ref{eq:model-split}). We included $10\,000$ galaxies located on
a $100\times100$ regular grid but with the centroid displaced by a
random shift within $1.5$ pixels. The galaxies are characterized by a
Sersic profile \citep{1968adga.book.....S} with a fixed index
$n=2$. They are convolved with a PSF described by a Moffat function
with $\beta=4.8$, $\mbox{FWHM}=4.45$ pixels \citep{moffat69}, and a
complex ellipticity $g_{PSF}=-0.019-i\,0.007$, adapted to the fiducial
values adopted in Great08 \citep{great08}. The noise variance, the
source fluxes, scale radii and ellipticities have been randomly
distributed such as to resemble those of a stacked image obtained with
the OmegaCam mounted on the Subaru telescope and 20 minutes of total
exposure time in the $i^\prime$ filter. A comparison of the magnitude
distribution, the photometric errors and the size-magnitude relation
between the simulated images and a real Subaru image is shown in
Fig.~(\ref{fig:sim-stat}).

The simulation has been processed as it would be with a real
image, i.e. detecting the sources, separating galaxies from stars
with SExtractor \citep{1996A&AS..117..393B}, and creating
postage-stamps sized $60\times60$ pixels for each object based on
the measured astrometry. In this case, we did not apply any rotation
to the galaxy images for simplicity. This will be done in the more
sophisticated simulation discussed in
Sec.~(\ref{sec:simulations}) below. The principal components,
$\vec{\phi}_i$, obtained for this sample are shown in
Fig.~(\ref{fig:subaru-basis}), where for visualization purposes only
we inverted the process sketched in
Fig.~(\ref{fig:subaru-train-cov}) to rearrange the vectors in form
of an image.

It is interesting to note how the data deliver principal components
with radially symmetric profiles ($w_1$ and $w_4$), dipolar
($w_2$ and $w_3$), and quadrupolar ($w_5$ and $w_6$) structures as
well. Higher modes show hexapoles and more complex structures. It is
easy to interpret these shapes: for instance the circularly symmetric
components take care for the average brightness profile, while the dipolar ones
account for a large fraction of the object's ellipticity.

In Fig.~(\ref{fig:subaru-eigenvalues}), we show the power of the
principal components normalized by the total variance,
$\sigma^2=\sum_k^n\lambda_k$. The continuous line represents the
simulation, and the dashed line the real SUBARU image mocked by the
simulation. In both cases, the power of the components drops rapidly
with their order, and the same kinks are visible in the curves.
The drop in power is
less dramatic for real data because of the more complex
morphology of the galaxies. At orders higher than $15$, there is
a clear plateau for the simulated images because here we enter
the regime of uncorrelated random noise containing no more features.
The real image lacks such a plateau because in this case the
noise is correlated because the image results from stacking.

\begin{figure}
  \centering
  \includegraphics[width=1.0\hsize]{./fig/models_neg2c}
  \caption {Four galaxies extracted from the XDF sample. From left to right, the columns
    show: the original image (with other
    objects present in the postage-stamp already removed),
    the model generated with the EMPCA, the model residuals, and the
    segmentation of the image we derived from the model. The image of
    the smaller galaxies has been enlarged for visualization
    purposes.}
  \label{fig:models}
\end{figure}

An example for the signal-to-noise splitting, $d(\vec{x})=
\tilde{g}(\vec{x}) + \tilde{n}(\vec{x})$, discussed in
Sec.~(\ref{sec:empca}), is displayed in
Fig.~(\ref{fig:subaru-object}) where, from left to right, we show
the original data $\tilde{d}(\vec{x})$, the model
$\tilde{g}(\vec{x})$, and the residuals $\tilde{n}(\vec{x})$. The
maximum order $M$ has been determined with the criterion $\left\{\,
\mbox{min}\{k\} \in \mathbb{N} : \chi^2_k -\chi^2_{k+1}\le t
\,\right\}$, setting $t=0.005$. As expected, the galaxy model is
compact, i.e. it vanishes at a certain distance form the center of the
galaxy, most of the noise is removed from the image, and the residuals
are fully uncorrelated.

A more quantitative assessment of the reconstruction quality, based on
the brightness moments of the images, is discussed in
Sect.~(\ref{sec:simulations}) where we deal with galaxies with
complex morphologies.

\section{Modeling the XDF galaxies}\label{sec:models}

We now come to the full analysis of real data. Here, we processed the
ACS/WFC stacked images of the Hubble eXtreme Deep Field \citep[XDF,
  hereafter, see][]{illingworth13} which covers an area of $10.8$
arcmin$^2$ down to the $\sim30$ AB magnitude ($5\sigma$). The images
are drizzled with a scale of $0''.03$ pixel$^{-1}$ and have been
obtained with the F435W, F606W, F775W, F814W, and F850LP filters for a
total exposure time of $1177$ks. We used all objects listed in the
UVUDF catalog which are classified as galaxies \citep{rafelski15}. To
avoid artifacts and truncated objects, we discarded those objects in
the areas affected by the ghosts and halos of stars or close to the
edges of the survey. In this way, we selected 8543 galaxies from an
effective area of $9.20$ arcmin$^2$. We further cut the sample by
rejecting all galaxies with an F775W magnitude larger than $30$,
ending up with 7038 objects. The redshift and magnitude distributions
of the sources with a maximum $\chi^2_{mod}$ of 4 for the BPZ redshift
are shown in Fig.~(\ref{fig:cat-photo-z}).

\begin{figure}
  \centering
  \includegraphics[width=1.0\hsize]{./fig/xdf_empca_stamps_color_v2}
  \caption {A collection of galaxy models obtained with the EMPCA and
    based on the F435W, F606W, and F775W filters. The first and second
    top panels show the same objects displayed in
    Fig.~(\ref{fig:models}). The size of each box is of $5.4$
    arcsec.}
  \label{fig:color-stamps}
\end{figure}

\begin{figure}
  \centering
  \includegraphics[width=1.0\hsize]{./fig/XDF_acsfwfc_compare_noisless-xdf-96min-cfhtlens2_wide_neg}
  \caption {Four simulations realized with {\it EasySky} displaying a
    field of $0.65\times0.65$ arcmin$^2$ observed with the F775W
    filter without noise (upper left panel), with a XDF like noise
    (upper right panel), a noise equivalent to one HST orbit (bottom
    left), and a CFHTLens-quality image for a seeing of $0.7$ arcsec
    (bottom right panel). }
  \label {fig:comparison-clean-dirty}
\end{figure}

When computing the principal components, we split the sample in groups
of galaxies with similar size, and evaluate the basis for each of
these subsamples separately. This is to obtain a collection of basis
sets, one per sub-sample, which is optimized for galaxies with that
specific size. If we used all galaxies at once, the features
captured by the EMPCAs will be distributed on a larger number of
components because then the range of sizes they have
to reproduce will be larger.

To further reduce the amount of scatter in the data, we
rotated the galaxies by $90$ deg, whenever necessary, to align them
within the same quadrant. We did not align the galaxies' major axes
along the same direction to avoid the introduction of additional
correlation among the pixels for a marginal
improvement that could barely be justified.

We finally take advantage of all bands by including all
of them in the training sets. This further reduces the noise and
enriches the number of features which can be reproduce with the same
basis set. In Fig.~(\ref{fig:basis}), we plot the first four
principal components computed for three different sub-sets of galaxies
with semi-major axis, $A$, within the ranges $5<A<7$, $18<A<20$,
$50<A<60$, and $70<A<80$ pixels for the first, second, third and forth
rows, respectively. The semi-major axes, $A=\sqrt{I (1-e) / \pi}$, was
derived from the isophotal area, $I$, and the object
ellipticity, $e$, which turned out to be a suitable choice for our
pourpose. As expected, the larger the galaxies in the training sample are,
the larger is the typical scale of the EMPCA. Additionally, one can see
that larger galaxies show principal components with more complex
features because of their larger variety in morphology and
substructure.

Having computed the basis for each sub-sample, we use them to create
the galaxy models as discussed in Sec.~(\ref{sec:empca}).  Since some
of the variance due to the noise is still present in the model, which
is unavoidable in general, we set all pixels to zero with amplitude
less than $t=\sigma/5$, where $\sigma$ is the pixel variance of the
original image.  This is to avoid such areas of the image which, in
fact, do not show any evidence of signal. The code to perform the
overall analysis is called {\it EasyEMPCA}.

\begin{figure*}
  \centering
  \includegraphics[width=0.48\hsize]{./fig/moments_F435W_nocut_2data_order16.png}
  \includegraphics[width=0.48\hsize]{./fig/moments_F606W_nocut_2data_order16.png}
  \includegraphics[width=0.48\hsize]{./fig/moments_F775W_nocut_2data_order16.png}
  \includegraphics[width=0.48\hsize]{./fig/moments_F850LP_nocut_2data_order16.png}
  \caption {Dispersion around the true value of the brightness moments of
    the models reconstructed with EMPCA (blue) and
    as measured with Shapelens (red).}
  \label {fig:moments}
\end{figure*}

Figure~(\ref{fig:models}) displays four galaxies belonging to the same
four samples used to create the basis shown in
Fig.~(\ref{fig:basis}). The images have been rescaled to better
visualize their details. For each object we show, from left to right,
the original image, the model, the residuals, and the segmentation
used to remove nearby objects. The color images of the same galaxies
are shown in the top left and central panels of
Fig.~(\ref{fig:color-stamps}) together with additional examples. The
color stamps have a field size of $5.4$ arcsec, are based on the
F435W, F606W, and F775W filters and show once more the range of sizes
and morphologies which can be modeled. In this case, the galaxies are
visualized without any rescaling. The residuals are compatible with
the image noise except for very concentrated features which are
slightly missed because of the regularization scheme we adopted when
constructing the basis functions which the models are based on (see
Fig.~\ref{fig:models}).

\section {Testing the brightness moments}\label{sec:simulations}

In this section, we ``feed'' {\it EasySky} with the postage-stamps of
the galaxy models created in Sec.~(\ref{sec:models}) and extracted
from the XDF Survey with {\it EasyEMPCA}. In this case, the galaxies
have been arranged on a regular grid, randomly flipped, and rotated by
multiples of $90$ degrees. Their flux has not been changed to
produce an image as close as possible to the original data. Such image
permutations do not affect the original quality of the stamps because
no interpolation is involved in this process, as it would happen
when applying arbitrary rotations.

In Fig.~(\ref{fig:comparison-clean-dirty}), we show a realization of a
portion of $0.65 \times 0.65$ arcmin$^2$ field-of-view in the F755W
band. The noise-free image is shown in the top left panel, while the
other panels show three images with different levels of noise and
resolution to resemble the XDF survey (upper right panel), one orbit
exposure with HST (bottom left), and a CFHTLens stacked image with a
seeing of $0.7$ arcsec (bottom right panel). We can now process these
simulations like real images to verify and quantify the accuracy of
the galaxy reconstructions. Do do so, we first detect the objects with
SExtractor and then apply EasyPCA with the complete procedure to
derive the basis and the models (see Sec.~\ref{sec:empca}). It is
important to note that even if the mock galaxies used in the
simulations have been produced with the EMPCA, we took care to create
a sample of galaxies which is as independent as possible from the
original sample. This is why the galaxy images have been randomly
flipped, rotated and split into training sets differing, in number and
components, from the training set used to create the simulations in
first place. Further more, the noise in the simulated images is not
the same as that in the real data.

To have a quantitative assessment of the reconstruction quality, we
measured the brightness moments,
\begin{equation}
  G_{ij} = \int_{-\infty}^\infty d(\vec{x}) x_1^i x_2^j \d x \;,
\end{equation}
of all galaxies in the simulation with noise to quantify the
deviations with respect to those expected in the noise-free images. In
Fig.~(\ref{fig:moments}), we plot the scatter in the brightness
moments, $\Delta G_{ij}=G_{ij}^{measured}-G_{ij}^{true}$, up to the
second order (as required for weak-lensing measurements). The moments
except $G_{00}$ have been normalized by flux.

We finally processed the same images with a well-established
weak-lensing method to have a direct comparison. At this end, we used the
Shapelens library which allows to measure the brightness moments by
iteratively matching the data to an elliptical weight function to
maximize the signal-to-noise ratio \citep{2011MNRAS.412.1552M}. The
brightness moments of the models based on the EMPCA (blue contours)
are reproduced with an accuracy comparable to that achieved by
Shapelens (red contours), proving the quality of the models.

\section{Conclusions}\label{sec:conclusions}

We have described how optical images of galaxies can be fitted with an
optimized linear model based on the Expectation Maximization Principal
Components Analysis (EMPCA). This method relies on the data alone,
avoiding any assumptions regarding the morphology of the objects to be
modeled even if they have complex or irregular shapes. As a test case,
we have analyzed the galaxies listed in the \cite{rafelski15} catalog
which covers the Hubble eXtreme Deep Field (XDF). We selected those
objects with magnitude $m_{W755}<30$, far from the field edges and
without overlapping artifacts caused by the few stars present across
the field. We collected 7038 postage-stamps of noise-free galaxy
images with redshift up to $z=4.0$.

We have shown how the modeled galaxies well represent the entire
collection of galaxies, from small to large and from regular to
irregular. Two codes have been implemented to this end: {\it EasySky}
to create the simulations and {\it EasyEMPCA} to model the
galaxies. The residuals appear uncorrelated except at very sharp
features because of the regularization scheme we adopted during the
basis construction. To further verify the quality of the
reconstructions, we simulated a set of galaxy images, with and without
noise, covering the entire spectrum of shapes and luminosities of the
objects present in the XDF. We processed the simulations with the same
procedure applied to a real data set: we detected the objects with
SExtractor, derived the EMPCA basis and fitted the data with the
linear model based on this basis. We then measured the brightness
moments up to the second order of the model reconstructions and
compared them to those of the noise-free simulations. The quality of
the reconstructions very well competes with a well-established method
to measure galaxy brightness moments such as the iterative adaptive
scheme implemented in Shapelens.

The procedure discussed in this paper can be used to derive the
properties of galaxies such as their fluxes and shapes, or to create
reliable simulations of optical images. In this respect, the accuracy
of such simulations is gaining importance for the lensing
community. For instance, in the strong-lensing regime, they are
necessary to understand how substructures in strongly magnified
galaxies can be used to access additional information on the lensing
mass distribution, such as galaxy clusters. In the weak-lensing
regime, all methods to measure the ellipticites of galaxies require
precise simulations for their calibration, on which depends the bias
of such measurements and all quantities derived from them. The method
we discussed in this work appears as a promising solution to create
such simulations.

\section*{Acknowledgments}

We would like to thank Marc A. Rafelski and Anton M. Koekemoer for
kindly provide us the segmentation map of the UVUDF data, and Massimo
Meneghetti for the useful discussion. This work was supported by the
Transregional Collaborative Research Centre TRR 33.


\section{Introduction and main results}
Spaces with a rich family of retractions often occur both in topology and functional analysis.
For example, systems of retractions were used by  Amir and Lindenstrauss to characterize Eberlein compact spaces \cite{amirLind} or by Gul$'$ko \cite{gul} to prove that a compact space $K$ is Corson whenever $\C_p(K)$ has the Lindel\"of $\Sigma$-property. This line of research
continued for a long time (for a survey see e.g. \cite{kalendaSurvey} and Chapter 19 of \cite{kubisKniha}). The optimal notion of an indexed system
of retractions in this area was defined in \cite{kubisSmall}. We slightly generalize this notion to a more general situation -- we consider countably compact spaces, not only compact ones.

\begin{definition}A \textit{retractional skeleton} in a countably compact space $X$ is a family of continuous retractions $\mathfrak{s} = \{r_s\}_{s\in\Gamma}$, indexed by an up-directed partially ordered set $\Gamma$, such that
\begin{enumerate}[\upshape (i)]
	\item $r_s[X]$ is a metrizable compact for each $s\in\Gamma$,
	\item $s,t\in\Gamma$, $s\leq t \Rightarrow r_s = r_s\circ r_t = r_t\circ r_s$,
	\item given $s_0 < s_1 < \cdots$ in $\Gamma$, $t = \sup_{n\in\omega}s_n$ exists and $r_t(x) = \lim_{n\to\infty}r_{s_n}(x)$ for every $x\in X$,
	\item for every $x\in X$, $x = \lim_{s\in\Gamma}r_s(x)$.
\end{enumerate}
We say that $D(\mathfrak{s}) = \bigcup_{s\in\Gamma}r_s[X]$ is the \textit{set induced by the retractional skeleton} $\mathfrak{s}$ in $X$.\\
If $D(\mathfrak{s}) = X$ then we say that $\mathfrak{s}$ is a \textit{full retractional skeleton}.
\end{definition}

Let us point out that the condition (i) in the definition of a retractional skeleton is equivalent to
\begin{itemize}
	\item[(i')] $r_s[X]$ has a countable network for each $s\in\Gamma$.
\end{itemize}
Indeed, any metrizable compact has a countable network. Conversely, if $r$ is any retraction on $X$, then $r[X]$ is a closed subset of $X$, hence it is countably compact. If it has countable network, it is Lindel\"of  and hence compact. Finally, a compact with countable network is metrizable.

Another type of a structured system of retractions was recently introduced in \cite{roj14}.

\begin{definition}
A space $X$ is \emph{monotonically retractable} if we can assign to any countable set $A\subset X$ a retraction $r_A$ and a countable set $\N(A)$
such that the following conditions are fulfilled:
\begin{itemize}
	\item $A\subset r_A[X]$.
	\item The assignment $A\mapsto \N(A)$ is $\omega$-monotone, i.e.,
	\begin{itemize}
  	\item[(i)] if $A\subset B$ are countable subsets of $X$, then $\N(A)\subset\N(B)$;
  	\item[(ii)] if $(A_n)$ is an increasing sequence of countable subsets of $X$, then $\N(\bigcup_{n=1}^\infty A_n)=\bigcup_{n=1}^\infty \N(A_n)$.
 \end{itemize}
  \item $\N(A)$ is a network of $r_A$, i.e. $r_A^{-1}(U)$ is the union of a subfamily of $\N(A)$ for any open set $U\subset X$.
\end{itemize}
\end{definition}

Our main result is the following characterization of monotonically retractable countably compact spaces using the notion of a retractional skeleton.

\begin{theorem}\label{t:charactFullSkeleton}
A countably compact space is monotonically retractable if and only if it has a full retractional skeleton.
\end{theorem}

Since a compact space has a full retractional skeleton if and only if it is Corson \cite[Theorem 3.11]{cuthCMUC}, we get
the following positive answer to Question 6.1 of \cite{tkaRoj}.

\begin{corollary}\label{t:charactCorson}
A compact space is monotonically retractable if and only if it is Corson.
\end{corollary}

As another corollary we obtain the following result from \cite{roj14}.

\begin{corollary}\label{c:roj14}
Any first countable countably compact subspace of an ordinal is monotonically retractable.
\end{corollary}

Indeed, it is enough to observe that any first countable countably compact subspace of an ordinal admits a full retractional skeleton.
To do that one can use the formula from \cite[Example 6.4]{kubisSmall}.

Theorem~\ref{t:charactFullSkeleton} will be proved in Section 4, it is an immediate consequence of Theorem~\ref{t:main}. Corollary~\ref{t:charactCorson}
is in fact easier, it follows already from Proposition~\ref{p:charactCorson}.

Further, we apply our results to prove the following `noncommutative' analogues of the results of \cite{kalendaCharact}. These theorems provide answers to Problem 1 of \cite{cuthCMUC} and Problem 1 of \cite{kubisSkeleton}. The topological property sought in the quoted problems is `to be monotonically Sokolov'. This class of spaces was introduced and studied in \cite{tkaRoj}, we recall the definition in the next section.

\begin{theorem}\label{t:answerCuth}Let $K$ be a compact space and $D$ be a dense subset of $K$. Then the following two conditions are equivalent:
	\begin{enumerate}[\upshape (i)]
		\item $D$ is induced by a retractional skeleton in $K$.
		\item $D$ is countably compact and $(\C(K),\tau_p(D))$ is monotonically Sokolov.
	\end{enumerate}
\end{theorem}

This theorem will be proved in the last section. The next one is its Banach-space counterpart. Projectional skeleton is Banach-space analogue of retractional skeleton, these notions are dual in a sense. For exact definitions and details see \cite{kubisSkeleton} or \cite{cuthSimul}.

\begin{theorem}\label{t:answerKubis}Let $E$ be a Banach space and $D\subset E^*$ a norming subspace. Then the following two conditions are equivalent:
	\begin{enumerate}[\upshape (i)]
		\item $D$ is induced by a projectional skeleton.
		\item $D$ is weak$^*$ countably closed and $(E,\sigma(E,D))$ is monotonically Sokolov.
	\end{enumerate}
\end{theorem}

This theorem will proved in the last section, using its more precise version, Theorem~\ref{t:skeletonIffXSokolov}.

\section{Preliminaries}

In this section we collect basic notation, terminology and some known facts which will be used in the sequel.

We denote by $\omega$ the set of all natural numbers (including $0$), by $\en$ the set $\omega\setminus\{0\}$. If $X$ is a set then $\exp(X) = \{Y\setsep Y\subset X\}$. We denote by $[X]^{\leq\omega}$ all countable subsets of $X$.

All topological spaces are assumed to be Tychonoff. Let $T$ be a topological space.
\begin{itemize}
	\item  $\tau(T)$ denotes the topology of $T$ and $\tau(x,T) = \{U\in\tau(T)\setsep x\in U\}$ for any $x\in T$.
	\item  A subset $S\subset T$ is said to be countably closed if $\ov{C}\subset S$ for every countable subset $C\subset S$. It is easy to check that a countably closed subset of a countably compact space is countably compact.
  \item   A family $\N$ of subsets of $T$ is said to be a \emph{network} of $T$ if any open set in $T$ is the union of a subfamily of $\N$
	\item If $A\subset T$, then a family $\N$ of subsets of $T$ is said to be an \emph{external network} of $A$ in $T$ if for any $a\in A$ and $U\in\tau(a,T)$ there exists $N\in\N$ such that $a\in N\subset U$.
	\item If $Y$ is a topological space and $f:T\to Y$ is a continuous map, then a family $\N$ of subsets of $T$ is said to be a \emph{network of $f$} if for any $x\in T$ and $U\in\tau(f(x),Y)$ there exists $N\in\N$ such that $x\in N$ and $f[N]\subset U$.
	\item $\beta T$ denotes the \v{C}ech-Stone compactification of $T$.
\end{itemize}

For any topological spaces $X$ and $Y$ the set of continuous functions from $X$ to $Y$ is denoted by $\C(X,Y)$. We write $\C(X)$ instead of $\C(X,\er)$ and $\C_b(X)$ for the set of all bounded functions from $\C(X)$. By $C_p(X)$ we denote the space $\C(X)$ equipped with the the topology of pointwise convergence (i.e., the topology inherited from $\er^X$). Moreover, if $D\subset X$ is dense, we denote by $\tau_p(D)$ the topology of the pointwise convergence on $D$ (i.e. the weakest topology on $\C(X)$ such that $f\mapsto f(d)$ is continuous for every $d\in D$).

We shall consider Banach spaces over the field of real numbers. If $E$ is a Banach space and $A\subset E$, we denote by $\sspan{A}$ the linear hull of $A$. $B_E$ is the closed unit ball of $E$; i.e., the set $\{x\in E:\; \|x\| \leq 1\}$. $E^*$ stands for the (continuous) dual space of $E$. For a set $A\subset E^*$ we denote by $\ov{A}^{w^*}$ the weak$^*$ closure of $A$. Given a set $D\subset E^*$ we denote by $\sigma(E,D)$ the weakest topology on $E$ such that each functional from $D$ is continuous. A set $D\subset E^*$ is \textit{r-norming} if $\|x\| \leq r. \sup\{|x^*(x)|:\;x^*\in D\cap B_{E^*}\}$. We say that a set $D\subset E^*$ is norming if it is $r$-norming for some $r\geq 1$.

The following definitions come from \cite{tkaRoj}.

\begin{definition}Let $X, Y$ be sets, $\O\subset\exp(X)$ closed under countable increasing unions, $\N\subset\exp(Y)$ and $f:\O\to\N$. We say that $f$ is \emph{$\omega$-monotone} if
\begin{enumerate}[\upshape (i)]
	\item $f(A)$ is countable for every countable $A\in\O$;
	\item if $A\subset B$ and $A,B\in\O$ then $f(A)\subset f(B)$;
	\item if $\{A_n\setsep n\in\omega\}\subset \O$ and $A_n\subset A_{n+1}$ for every $n\in\omega$ then $f(\bigcup_{n\in\omega}A_n) = \bigcup_{n\in\omega}f(A_n)$.
\end{enumerate}
\end{definition}

\begin{definition}A space $T$ is \emph{monotonically Sokolov} if we can assign to any countable family $\F$ of closed subsets of $T$ a continuous retraction $r_\F:T\to T$ and a countable external network $\N(\F)$ for $r_\F(T)$ in $T$ such that $r_\F(F)\subset F$ for every $F\in\F$ and the assignment $\N$ is $\omega$-monotone.
\end{definition}

In the following statement we sum up some properties of monotonically retractable and monotonically Sokolov spaces which we will use later.
They follow from results of \cite{tkaRoj}.

\begin{fact}\label{f:mrs}
Let $X$ be a topological space. Then:
	\begin{enumerate}[\upshape (a)]
		\item $X$ is monotonically retractable if and only if $\C_p(X)$ is monotonically Sokolov.
		\item $X$ is monotonically Sokolov if and only if $\C_p(X)$ is monotonically retractable.
		\item Any closed subspace of a monotonically retractable (resp. monotonically Sokolov) space is monotonically retractable (resp. monotonically Sokolov).
		\item A countable product of monotonically Sokolov spaces is monotonically Sokolov.
		\item Any monotonically Sokolov space is Lindel\"of.
		\item Any monotonically retractable space is normal and $\omega$-monolithic (i.e., any separable subset has countable network).
		\item Any monotonically retractable space has countable tightness.
		\item Any countably compact subset of a monotonically retractable space is closed (and hence monotonically retractable).
	\end{enumerate}
\end{fact}

\begin{proof}
The assertions (a) and (b) are proved in \cite[Theorem 3.5]{tkaRoj}, the assertions (c)--(f) follow from \cite[Theorems 3.4 and 3.6]{tkaRoj}.

Let us show (g). Let $X$ be a monotonically retractable space. Consequently, $Y = \C_p(X)$ is monotonically Sokolov by (a) and by (d) $Y^n$ is monotonically Sokolov for every $n\in\en$. It follows by (e) that $Y^n$ is Lindel\"of for every $n\in\en$ and, by \cite[Theorem II.1.1]{archangelskii}, $\C_p(Y) = \C_p(\C_p(X))$ has a countable tightness. Since $X$ embeds in $\C_p(\C_p(X))$, it must have a countable tightness.

Finally, let us prove (h). Let $X$ be a monotonically retractable space and $A\subset X$ countably compact. Fix $a\in \ov{A}$. Since $X$ has a countable tightness (by (g)), there is a countable set $S\subset A$ with $a\in \ov{S}$. By (f) $\ov{S}\cap A$ has a countable network, hence it is Lindel\"of. Since $A$ is countably compact, $\ov{S}\cap A$ is countably compact and Lindel\"of; hence, compact. It follows that $\ov{S}\cap A$ is closed in $X$ and $a\in A$.
\end{proof}

In the following we summarize some easy facts concerning sets induced by a retractional skeleton.

\begin{fact}\label{f:basics}Let $X$ be a countably compact space and let $D$ be a set induced by
a retractional skeleton in $X$. Then:
\begin{enumerate}[\upshape (i)]
	\item $D$ is countably closed in $X$.
	\item $D$ is sequentially compact.
	\item If $X$ is compact, then $X=\beta D$.
\end{enumerate}
\end{fact}
\begin{proof}Let $\mathfrak{s} = \{r_s\}_{s\in\Gamma}$ be a retractional skeleton in $X$ with $D = D(\mathfrak{s})$. Whenever $A\subset D$ is countable, there is $s\in\Gamma$ with $A\subset r_s[X]$; hence, $\ov{A}\subset r_s[X]$ is metrizable compact and (i) and (ii) follows.
The assertion (iii) is proved in \cite[Theorem 32]{kubisSkeleton}.
\end{proof}

\section{The method of elementary models}

The purpose of this section is to briefly recall the reader of some basic facts concerning the method of elementary models. This is a set-theoretical method which can be used in various branches of mathematics. A. Dow in \cite{dow} illustrated the use of this method in topology, P. Koszmider in \cite{kos05} used it in functional analysis. Later, inspired by \cite{kos05}, W. Kubi\'s in \cite{kubisSkeleton} used it to construct retractional (resp. projectional) skeleton in certain compact (resp. Banach) spaces. In \cite{cuth} the method has been slightly simplified and specified. We briefly recall some basic facts. More details may be found e.g. in \cite{cuth} and \cite{cuthKalenda}.

First, let us recall some definitions. Let $N$ be a fixed set and $\phi$ a formula in the language of $ZFC$. Then the {\em relativization of $\phi$ to $N$} is the formula $\phi^N$ which is obtained from $\phi$ by replacing each quantifier of the form ``$\forall x$'' by ``$\forall x\in N$'' and each quantifier of the form ``$\exists x$'' by ``$\exists x\in N$''.

If $\phi(x_1,\ldots,x_n)$ is a formula with all free variables shown (i.e., a formula whose free variables are exactly $x_1,\ldots,x_n$) then  $\phi$ is said to be {\em absolute for $N$} if
\[
\forall a_1,\ldots,a_n\in N\quad (\phi^N(a_1,\ldots,a_n) \leftrightarrow \phi(a_1,\ldots,a_n)).
\]

A list of formulas, $\phi_1,\ldots,\phi_n$, is said to be {\em subformula closed} if  every subformula of a formula in the list is also contained in the list.

The method is based mainly on the following theorem (a proof can be found in \cite[Chapter IV, Theorem 7.8]{Kunen}).

\begin{theorem}\label{T:countable-model}
Let $\phi_1, \ldots, \phi_n$ be any formulas and $Y$ any set. Then there exists a set $M \supset Y$ such that
$\phi_1, \ldots, \phi_n \text{ are absolute for } M$ and $|M| \leq \max(\omega,|Y|)$.
\end{theorem}

Since the set from Theorem~\ref{T:countable-model} will often be used, the following notation is useful.

\begin{definition}
Let $\phi_1, \ldots, \phi_n$ be any formulas and $Y$ be any countable set.
Let $M \supset X$ be a countable set such that $\phi_1, \ldots, \phi_n$ are absolute for $M$.
Then we say that $M$ is an \emph{elementary model for $\phi_1,\ldots,\phi_n$ containing $X$}.
This is denoted by $M \prec (\phi_1,\ldots,\phi_n; Y)$.
\end{definition}

The fact that certain formula is absolute for $M$ will always be used in order to satisfy the assumption of the following lemma from \cite[Lemma 2.3]{cuthRmoutilZeleny}. Using this lemma we can force the model $M$ to contain all the needed objects created (uniquely) from elements of $M$.

\begin{lemma}\label{l:unique-M}
Let $\phi(y,x_1,\ldots,x_n)$ be a formula with all free variables shown and $Y$ be a countable set.
Let $M$ be a fixed set, $M \prec (\phi, \exists y \colon \phi(y,x_1,\ldots,x_n);\; Y)$, and
$a_1,\ldots,a_n \in M$ be such that there exists a set $u$ satisfying
$\phi(u,a_1,\ldots,a_n)$. Then there exists $u \in M$ such that $\phi(u,a_1,\ldots,a_n)$.
\end{lemma}

\begin{proof}Let us give here the proof just for the sake of completeness. Using the absoluteness of the formula $\exists u\colon \phi(u,x_1,\ldots,x_n)$ there exists $u\in M$ satisfying $\phi^M(u,a_1,\ldots,a_n)$.
Using the absoluteness of $\phi$ we get, that for this $u\in M$ the formula $\phi(u,a_1,\ldots,a_n)$ holds.
\end{proof}

It would be very laborious and pointless to use only the basic language of the set theory.
For example, having a function $f$, we often write $y = f(x)$ and we know that this is a shortcut for a formula with free variables $x$, $y$, and $f$.

Indeed, consider the formula
\[
\varphi(x,y,z) = \forall a (a\in z \leftrightarrow (a=x\vee a=y)).
\]
Then $\varphi(x,y,z)$ is true if and only if $z = \{x,y\}$. Recall that $y = f(x)$ means $\{\{x\},\{x,y\}\}\in f$. Hence, $y = f(x)$ if and only if the following formula is true
\[
\forall z (\forall a (a\in z \leftrightarrow \varphi(x,x,a)\vee \varphi(x,y,a)) \Rightarrow z\in f).
\]

Therefore, in the following text we use this extended language of the set theory as we are used to.
We shall also use the following convention.

\begin{convention}
Whenever we say ``\emph{for any suitable model $M$ (the following holds \dots)}''
we mean that  ``\emph{there exists a list of formulas $\phi_1,\ldots,\phi_n$ and a countable set $Y$ such that for every $M \prec (\phi_1,\ldots,\phi_n;Y)$ (the following holds \dots)}''.
\end{convention}

By using this new terminology we lose the information about the formulas $\phi_1,\ldots,\phi_n$ and the set $Y$.
However, this is not important in applications.

Let us recall several further results about elementary models
(all the proofs are based on Lemma \ref{l:unique-M} and they can be found in \cite[Proposition 2.9, 2.10 and 3.2]{cuth} and \cite[Lemma 4.8]{cuthCMUC}).

\begin{lemma}\label{l:predp}
There are formulas $\theta_1,\dots,\theta_m$ and a countable set $Y_0$ such that any $M\prec(\theta_1,\ldots,\theta_n;\; Y_0)$ satisfies the following conditions:
\begin{itemize}
	\item If $f\in M$ is a mapping, then $\dom(f)\in M$, $\rng(f)\in M$ and $f[M]\subset M$.
	\item If $A$ is finite, then $A\in M$ if and only if $A\subset M$.
	\item If $A\in M$ is a countable set, then $A\subset M$.
	\item If $A,B\in M$, then $A\cup B\in M$.
\end{itemize}
\end{lemma}

Moreover, we will need to find suitable models in a ``monotonic way''. Thus, the following lemma from \cite[Lemma 4]{cuthKalenda} will be useful as well.

\begin{lemma}\label{l:BasicSkolem}
 Let $\phi_1,\ldots,\phi_n$ be a subformula closed list of formulas and let $R$ be a set such that $\phi_1,\ldots,\phi_n$ are absolute for $R$. Then there exists a function $\psi:[R]^{\leq\omega}\to [R]^{\leq\omega}$ such that
 \begin{enumerate}[\upshape (i)]
	\item For every $A\in[R]^{\leq\omega}$, $\psi(A)\prec (\phi_1,\ldots,\phi_n; A)$.
	\item The mapping $\psi$ is $\omega$-monotone.
\end{enumerate}
\end{lemma}

\begin{definition}We say that the function from Lemma \ref{l:BasicSkolem} is a \emph{Skolem function for $\phi_1,\ldots,\phi_n$ and $R$}.
\end{definition}

\section{Proof of the main result}

In this section we are going to prove our main result, Theorem~\ref{t:charactFullSkeleton}. This is the content of the equivalence (i)$\Leftrightarrow$(iii) from the following theorem. We add one more equivalent condition, formulated with the use of elementary models, because via this
condition the proof will be done.

\begin{theorem}\label{t:main}Let $X$ be a countably compact space. Then the following are equivalent:
	\begin{itemize}
	\item[(i)] $X$ has a full retractional skeleton.
	\item[(ii)] For any suitable model $M$, $\C(X)\cap M$ separates the points of $\ov{X\cap M}$.
	\item[(iii)] $X$ is monotonically retractable.
\end{itemize}
\end{theorem}

Recall that a compact space is Corson if and only if it has a full retractional skeleton; see e. g. \cite[Theorem 3.11]{cuthCMUC}.
Hence, in case $X$ is compact, the equivalence (i)$\Leftrightarrow$(ii) comes from \cite[Theorem 7]{ban91} (for a simplified and generalized version see \cite[Theorem 30]{kubisSkeleton}, a more detailed proof which suits our situation the most can be found in \cite[Theorem 4.9]{cuthCMUC}).

The rest of this section will be devoted to the proof of Theorem~\ref{t:main}.
We start by proving the implication (iii)$\Rightarrow$(ii). This is the content of the following proposition -- note that it holds even without
assuming countable compactness of $X$. Let us also remark that this already provides a proof of Corollary~\ref{t:charactCorson}.

\begin{proposition}\label{p:charactCorson} Let $X$ be a monotonically retractable space. Then, for any suitable model $M$, $\C_b(X)\cap M$ separates the points of $\ov{X\cap M}$.
\end{proposition}

\begin{proof}
Suppose that for any countable set $A\subset X$, we have a retraction $r_A:X\to X$ and a family $\N(A)$ that witness the monotone retractability of $X$. Fix formulas $\phi_1,\ldots,\phi_n$ containing the formulas $\theta_1,\dots,\theta_m$ from Lemma \ref{l:predp} and the formula (and its subformulas) marked by $(*)$ in the proof below, and a countable set $Y$ containing the set $Y_0$ from Lemma \ref{l:predp} and the set $\{\C_b(X),\N\}$. Fix $M\prec(\phi_1,...,\phi_n;\; Y)$. Put $A = \bigcup\{B\in[X]^{\leq\omega}\setsep B\in M\}$. This is a countable set.
\begin{claim}\label{claim1}$\N(A)\subset M$\end{claim}
\begin{proof}By Lemma \ref{l:predp}, the set $\{B\in[X]^{\leq\omega}\setsep B\in M\}$ is closed under finite unions. Hence, there exists an increasing sequence $(B_n)_{n\in\en}$ with $A = \bigcup_{n\in\en} B_n$ and $B_n\in M$ for every $n\in\en$. Since the assignment $\N$ is $\omega$-monotone, we have $\N(A) = \bigcup_{n\in\en}\N(B_n)$. Fix $n\in\en$. By Lemma~\ref{l:predp}, $\N(B_n)\in M$ and $\N(B_n)\subset M$. Consequently, $\N(A)\subset M$.\end{proof}
\begin{claim}\label{claim2}$\ov{X\cap M}\subset r_A[X]$\end{claim}
\begin{proof}Fix $x\in X\cap M$. Then $\{x\}\in [X]^{\leq\omega}\cap M$ (by Lemma~\ref{l:predp}); hence, $x \in A$. Thus, $X\cap M\subset A$ and $\ov{X\cap M}\subset \ov{A}\subset r_A[X]$.\end{proof}

Fix $x,y\in\ov{X\cap M}$, $x\neq y$. By Claim \ref{claim2}, $x,y\in r_A[X]$. Find sets $U\in\tau(x,r_A[X])$ and $V\in\tau(y,r_A[X])$ such that $\ov{U}\cap\ov{V} = \emptyset$. Since $\N(A)$ is a network of $r_A$, we can find $N_x\in\N(A)$ and $N_y\in\N(A)$ with $x\in N_x\subset r_A^{-1}[U]$ and $y\in N_y\subset r_A^{-1}[V]$. Note that $\ov{N_x}\cap\ov{N_y} = \emptyset$ and recall that $X$ is normal by Fact~\ref{f:mrs}. By Claim \ref{claim1}, $N_x, N_y\in M$. Hence, by Lemma \ref{l:unique-M} and the absoluteness of the formula (and its subformula)
\[
\exists f\in\C_b(X)\quad(\forall a\in N_x: f(a) = 0 \wedge \forall b\in N_y: f(b) = 1),\eqno{(*)}
\]
there is $f\in\C_b(X)\cap M$ with $f(x) = 0 \neq 1 = f(y)$. Thus, $\C_b(X)\cap M$ separates the points of $\ov{X\cap M}$.
\end{proof}

We continue with proving the equivalence (i)$\Leftrightarrow$(ii) from Theorem~\ref{t:main}. In fact, this equivalence
is essentially known due to the following result:

\begin{lemma}\label{l:generskel} {\rm (\cite[Theorem 30]{kubisSkeleton}, see also \cite[Theorem 4.9]{cuthCMUC})}
Let $K$ be a compact space and $X\subset K$ a dense countably compact subset. The following assertions are
equivalent:
\begin{itemize}
	\item[(i)] $X$ is induced by a retractional skeleton in $K$.
	\item[(ii)] For any suitable model $M$, $\C(K)\cap M$ separates the points of $\ov{X\cap M}$.
\end{itemize}
\end{lemma}

In fact, the quoted results use a slightly stronger assumption that $X$ is countably closed in $K$. However, if $X$ is induced by a retractional skeleton, it is automatically countably closed by Fact~\ref{f:basics}, so this assumption is not used for (i)$\Rightarrow$(ii).
For the opposite implication, by \cite[Theorem 4.9]{cuthCMUC} it follows from (ii) that $X$ is contained in a set $Y$ induced by retractional skeleton.
Now it follows easily from \cite[Theorem 32]{kubisSkeleton} that $X=Y$.

The proof of the equivalence (i)$\Leftrightarrow$(ii) from Theorem~\ref{t:main} will be done by reducing the situation to the use
of Lemma~\ref{l:generskel}. More precisely, let us consider $K=\beta X$. We will show that the validity of assertion (i) in Theorem~\ref{t:main}
is equivalent to the validity of (i) in Lemma~\ref{l:generskel} and similarly for the respective assertions (ii).
We begin with the assertions (ii). The key tool to do that is the following easy lemma.

\begin{lemma}\label{l:separatePointsInCompactification} Let $L$ be a compact space and $A\subset L$ a dense countably compact subset. Let $S\subset \C(L)$ be a countable set separating the points of $A$. Then $S$ separates the points of $L$.
\end{lemma}
\begin{proof}Arguing by contradiction, let $x_1,x_2\in L$ be such that $x_1\neq x_2$ and $f(x_1) = f(x_2)$ for every $f\in S$. Find $g\in\C(L)$ with $g(x_1)\neq g(x_2)$. Denote, for $i\in\{1,2\}$,
\[
A_i = \bigcap_{h\in S\cup\{g\}}\{t\in L\setsep h(x_i) = h(t)\}.
\]
Then $A_1, A_2$ are nonempty $G_\delta$ sets and $A_1\cap A_2 = \emptyset$. Hence, e. g. by \cite[Lemma 1.11]{kalendaSurvey}, there are $y_1\in A\cap A_1$ and $y_2\in A\cap A_2$. This is a contradiction because $S$ does not separate the points $y_1\neq y_2$ from $A$.
\end{proof}

Let us now show the equivalence of the respective assertions (ii) from Theorem~\ref{t:main} and Lemma~\ref{l:generskel}.
Suppose that the assertion (ii) from Theorem~\ref{t:main} holds. Let $M$ be such a suitable model containing moreover the
extension map $f\mapsto \beta f$, $f\in \C(X)$, and the restriction map $f\mapsto f\restriction_X$, $f\in\beta X$. Then
$\C(X)\cap M=\{f\restriction_X:f\in \C(\beta X)\cap M\}$. Hence the validity of assertion (ii) from Lemma~\ref{l:generskel} follows from
the previous lemma applied to $L=\overline{X\cap M}^{\beta X}$, $A=\overline{X\cap M}^X$ and $S=\{f\restriction_L:f\in C(\beta X)\cap M\}$.
The converse implication can be proved in the same way, just the final use of the previous lemma is not necessary.

 The equivalence of the respective assertions (i) is the content of the following proposition.

\begin{proposition}\label{p:rSkeletonInBetaX} Let $X$ be a countably compact space. Then $X$ has a full retractional skeleton if and only if it is induced by a retractional skeleton in $\beta X$.

Moreover,  if $\{r_s\}_{s\in\Gamma}$ is a full retractional skeleton in $X$, then there is a retractional skeleton $\{R_s\}_{s\in\Gamma}$ in $\beta X$ inducing $X$ such that $R_s\restriction_X = r_s$ for every $s\in\Gamma$.
\end{proposition}

\begin{proof} We start by proving the `if part'.  Let $\mathfrak{s} = \{R_s\}_{s\in\Gamma}$ be a retractional skeleton in $\beta X$ with $D(\mathfrak{s}) = X$. Then $\mathfrak{s'} = \{R_s\restriction_X\}_{s\in\Gamma}$ is a full retractional skeleton in $X$. Indeed, since $X$ is induced by $\mathfrak{s}$, we have, for each $s\in\Gamma$, $R_s[\beta X]\subset X$. Since $R_s$ is a retraction, we get $R_s[\beta X]=R_s[R_s[\beta X]]\subset R_s[X]$, hence $R_s[X]=R_s[\beta X]$. It follows that ranges of $R_s\restriction_X$ cover $X$. Further, it is immediate that (i)--(iv) from the definition of a retractional skeleton are satisfied. This finishes the proof.

To show the `only if' part let $\mathfrak{s} = \{r_s\}_{s\in\Gamma}$ be a full retractional skeleton in $X$. Fix $s\in\Gamma$. We extend the retraction $r_s:X\to\beta X$ to a continuous function $R_s:\beta X\to\beta X$. Then $R_s$ is a retraction because $R_s\circ R_s = R_s$ on a dense subset $X$; hence, $R_s\circ R_s = R_s$ on $\beta X$. Moreover, $r_s[X] = R_s[\beta X]$ because $R_s[X] = r_s[X]$ is compact and dense in $R_s[\beta X]$;
hence, $R_s[\beta X] = r_s[X] \subset X$ is a metrizable compact. Now, it is immediate that $\mathfrak{s'} = \{R_s\}_{s\in\Gamma}$ is a system of retractions on $\beta X$ satisfying (i), (ii) from the definition of a retractional skeleton and $D(\mathfrak{s'}) = X$. In order to verify that (iii) from the definition of a retractional skeleton holds, let us fix a sequence $s_0 < s_1 < \cdots$ in $\Gamma$ with $t = \sup_{n\in\omega}s_n\in\Gamma$ and $x\in\beta X$. Then $R_t(x)\in X$. Therefore, $R_t(x) = r_t(R_t(x)) = \lim_{n\to\infty} r_{s_n}(R_t(x)) = \lim_{n\to\infty} R_{s_n}(x)$.

Finally, let us fix $x\in\beta X$. It remains to show that $\lim_{s\in\Gamma} R_s(x) = x$. Arguing by contradiction, let $y\in\beta X$ be a cluster point of the net $\{R_s(x)\}_{s\in\Gamma}$ with $y\neq x$. Fix $U\in\tau(x,\beta X)$ and $V\in\tau(y,\beta X)$ with $\ov{U}\cap\ov{V} = \emptyset$ and $s_0\in\Gamma$. We inductively find sequences $\{s_n\}_{n\in\en}$, $\{s'_n\}_{n\in\en}$ of indices from $\Gamma$, $\{x_n\}_{n\in\en}$ of points from $X$ and $\{U_n\}_{n\in\en}$ of sets from $\tau(x,\beta X)$ such that, for every $n\in\en$,

\begin{itemize}
	\item $\ov{U_1}\subset U$,
	\item $s_n\leq s'_n\leq s_{n+1}$, $\ov{U_{n+1}}\subset U_n$,
	\item $R_{s_n}(U_n)\subset V$,
	\item $x_n\in U_n\cap X$ and
	\item $R_{s'_n}(x_n) = x_n$.
\end{itemize}

Let us describe the inductive process. Let $s'_{n-1}$ and $U_{n-1}$ be defined (we put $s'_0 = s_0$ and $U_0 = U$ if $n=1$). Find $s_n\geq s'_{n-1}$ with $R_{s_n}(x)\in V$ and $U_n\in\tau(x,\beta X)$ with $\ov{U_n}\subset U_{n-1}$ and $R_{s_n}(U_n)\subset V$. Since  $X$ is dense in $\beta X$ we can find $x_n\in X\cap U_n$. Finally, we choose $s'_n$ to be such that $s'_n\geq s_n$ and $R_{s'_n}(x_n) = x_n$.

By Fact~\ref{f:basics}, $X$ is sequentially compact and so we may without loss of generality assume that the sequence $\{x_n\}_{n\in\en}$ converges to some $z\in X$. For $t = \sup_{n\in\omega}s_n$ we get
\[
R_t(z) = \lim_{n\to\infty} R_t(x_n) = \lim_{n\to\infty} R_t(R_{s'_n}(x_n)) = \lim_{n\to\infty} R_{s'_n}(x_n) = \lim_{n\to\infty} x_n = z.
\]
Hence, $R_t(z) = z\in\ov{U}$. Moreover, $x_k\in U_n$ for every $k\geq n$; hence, $z\in\bigcap_{n\in\en}\ov{U_n}$ and
\[
R_t(z)\in R_t\left[\bigcap_{n\in\en} \ov{U_n}\right] = R_t\left[\bigcap_{n\in\en} U_n\right] \subset\ov{V},
\]
which is a contradiction with $\ov{U}\cap\ov{V} = \emptyset$.

\smallskip

The `moreover part' follows immediately from the construction.
\end{proof}

To complete the proof of Theorem~\ref{t:main} we will show (ii)$\Rightarrow$(iii).
The idea is to use a Skolem function given by (ii) to create the required $\omega$-monotone mapping.
We begin with the following lemma which gives a formula for a network of a given retraction.

\begin{lemma}\label{l:networkForRetract}
Let $X$ be a space and $r:X\to X$ a retraction with a compact range. Let $S\subset\C(X)$ be a subset separating the points of $r[X]$ such that $f\circ r = f$ for every $f\in S$. Then
\begin{multline*}\N(S) = \{f_1^{-1}(I_1)\cap\dots\cap f_k^{-1}(I_k)\setsep f_1,\dots,f_k\in S,\\ I_1,\dots, I_k\mbox{ are open intervals with rational endpoints}\}\end{multline*} is a network of $r$.
\end{lemma}

\begin{proof}Fix $y\in X$ and $U\in\tau(r(y),r(X))$. For any  $z\in r[X]\setminus U$ there is a function $f_z\in S$ such that $f_z(y)\ne f_z(z)$.
We can find disjoint open intervals $I_z$ and $J_z$ with rational endpoints such that $f_z(y)\in I_z$ and $f_z(z)\in J_z$. The open sets $f_z^{-1}(J_z)$, $z\in r[X]\setminus U$ cover the compact set $r[X]\setminus U$, so there are $z_1,\dots,z_k\in r[X]\setminus U$ such that $\bigcup_{i=1}^k f_{z_i}^{-1}(J_{z_i})\supset  r[X]\setminus U$. Then
\[
y\in \bigcap_{i=1}^k f_{z_i}^{-1}(I_{z_i})\subset r^{-1}[U],
\]
which completes the proof.
\end{proof}

We continue by the following lemma which we use to improve a bit the model provided by the assumption (ii).

\begin{lemma}\label{l:retrakce} Let $X$ be a countably compact space satisfying the assumption (ii) from
Theorem~\ref{t:main}. Then for any suitable model $M$ the following holds:
\begin{itemize}
	\item[(i)] $\C(X)\cap M$ separates the points of $\overline{X\cap M}$.
	\item[(ii)] $\overline{X\cap M}$ is compact.
	\item[(iii)] There is a retraction $r:X\to X$ with $r[X]=\ov{X\cap M}$  such that $f\circ r= f$ for each
	$f\in\C(X)\cap M$.
\end{itemize}
\end{lemma}

\begin{proof}
In this proof we will use the identification of any $n\in\omega$ with the set $\{0,\dots,n-1\}$.
Further, denote by $\B$ the set of all the open intervals with rational endpoints and by $\B^{<\omega}$ the set of all the functions whose domain is some $n\in\omega$ and whose values are in $\B$.

Fix formulas $\phi_1,\ldots,\phi_n$ containing all the formulas $\theta_1,\dots,\theta_m$ from Lemma \ref{l:predp}, the formulas provided by the assertion (ii) from Theorem~\ref{t:main} and the formulas (and their subformulas) marked by $(*)$ in the proof below, and a countable set $Y$ containing the set $Y_0$ from Lemma \ref{l:predp}, the set provided by the assertion (ii) from Theorem~\ref{t:main} and the set $\{X, \C(X), \B, \B^{<\omega}\}$. Fix $M\prec(\phi_1,...,\phi_n;\; Y)$.

Set $A=\C(X)\cap M$. By the assumptions $A$ separates points of $\ov{X\cap M}$, hence the assertion (i) is fulfilled. Let us define
the mapping $\Phi:X\to \er^A$ by the formula
\[
\Phi(x)(f)=f(x), \quad f\in A,x\in X.
\]
Then $\Phi$ is continuous, hence $\Phi[X]$ is countably compact. Since $A$ is countable, we deduce that $\Phi[X]$ is a metrizable compact.
Moreover, $\Phi$ is a closed mapping (any closed $F\subset X$ is countably compact, $\Phi[F]$ is then countably compact, hence compact and thus closed).
By the already proved condition (i) the mapping $\Phi$ is one-to-one when restricted to $\ov{X\cap M}$, so it is a homeomorphism of $\ov{X\cap M}$
onto its image. In particular, $\ov{X\cap M}$ is compact, which proves the assertion (ii).

The next step is to prove that $\Phi[X]=\Phi[\ov{X\cap M}]$. Since $\Phi$ is a closed mapping, it is enough to show that $\Phi[X\cap M]$ is
dense in $\Phi[X]$. To do that fix $x_0\in X$ and $U$ an open set in $\er^A$ containing $\Phi(x_0)$. It follows that there is a finite set
$F\subset A$ and intervals $I_f\in \B$, $f\in F$, such that
\[
\Phi(x_0)\in \{z\in \er^A\setsep z(f)\in I_f\mbox{ for }f\in F\}\subset U,
\]
which means
\[
x_0\in\{x\in X\setsep f(x)\in I_f\mbox{ for }f\in F\}\subset \Phi^{-1}(U).
\]
Since $F\subset A\subset M$ and $F$ is finite, Lemma~\ref{l:predp} yields $F\in M$. Further, by absoluteness of the formula
\[
\exists n\in\omega\; \exists \eta\quad (\eta \mbox{ is a mapping of $n$ onto }F)\eqno{(*)}
\]
and its subformulas, there is $n\in\omega$ and an onto mapping $\eta:n\to F$ in $M$. Let us further define mapping $\zeta:n\to\B$ by
$\zeta(i)=I_{\eta(i)}$. Since $\zeta\in\B^{<\omega}$, $\B^{<\omega}\in M$ and it is countable, it follows from Lemma~\ref{l:predp} that $\zeta\in M$.
Finally, by absoluteness of the formula
\[
\exists x\in X\; \forall i\in n \quad(\eta(i)(x)\in \zeta(i)) \eqno{(*)}
\]
and its subformulas, there is $x\in X\cap M$ such that $\eta(i)(x)\in\zeta(i)$ for each $i\in n$, in other words $f(x)\in I_f$ for each $f\in F$,
hence $\Phi(x)\in U$. This completes the proof that $\Phi[X\cap M]$ is dense in $\Phi[X]$, hence $\Phi[X]=\Phi[\ov{X\cap M}]$.

Finally, set $r=\left(\Phi\restriction_{\ov{X\cap M}}\right)^{-1}\circ \Phi$. It is clear that $r$ is a continuous retraction on $X$ with the range $\ov{X\cap M}$. Further, if $f\in A$ and $x\in X$, then
\[
(f\circ r)(x)=f(r(x))=\Phi(r(x))(f)=\Phi\left(\left(\Phi\restriction_{\ov{X\cap M}}\right)^{-1}\left( \Phi(x)\right)\right)(f)=\Phi(x)(f)=f(x),
\]
hence $f\circ r=f$, which completes the proof of (iii).
\end{proof}

Finally, we give the proof of the missing implication of Theorem~\ref{t:main}.

\smallskip

Let us assume that the assertion (ii) holds.  We will show that (iii) holds as well.
For any countable $S\subset \C(X)$ let us define $\N(S)$ by the formula given in  Lemma~\ref{l:networkForRetract}.
Note that the assignment $S\mapsto \N(S)$ is $\omega$-monotone.
Let a subformula closed list of formulas $\phi_1,\ldots,\phi_n$ and a countable set $Y$ be the ones provided by Lemma~\ref{l:retrakce}.
By Theorem~\ref{T:countable-model} there exists a set $R\supset X\cup Y$ such that $\phi_1,\ldots,\phi_n$ are absolute for $R$.
Let $\psi$ be a Skolem function for $\phi_1,\ldots,\phi_n$ and $R$; see Lemma~\ref{l:BasicSkolem}. For every $A\in[X]^{\leq\omega}$, we put $M(A) = \psi(A\cup Y)$. By Lemma~\ref{l:BasicSkolem}, $M(A)\prec(\phi_1,\ldots,\phi_n;Y)$, $M(A)\supset A$ and the assignment $A\mapsto M(A)$ is $\omega$-monotone. Let $r_A$ be the retraction assigned to $M(A)$ by Lemma~\ref{l:retrakce} and $\O(A) = \N(\C(X)\cap M(A))$. Then $\O(A)$ is a countable network of $r_A$ and $A\subset M(A)\cap X\subset \ov{M(A)\cap X} = r_A[X]$. Finally, the assignment $A\mapsto \O(A)$ is $\omega$-monotone because it is a composition of $\omega$-monotone mappings $A\mapsto \C(X)\cap M(A)$ and $\N$. This completes the proof.

\section{A function-space characterization of compact spaces with retractional skeleton}

The aim of this section is to prove Theorem~\ref{t:answerCuth} and Theorem~\ref{t:answerKubis}. In fact, instead of the latter we prove a more precise version, namely Theorem~\ref{t:skeletonIffXSokolov} below.

Let us start with Theorem~\ref{t:answerCuth}. It answers \cite[Problem 1]{cuthCMUC} and can be viewed as a noncommutative analogue of \cite[Theorem 2.1]{kalendaCharact}. Let us comment it a bit. Let $K$ be a compact space and $D\subset K$ dense subset. Then $D$ is induced by a commutative retractional skeleton in $K$ (here, \emph{commutative} means that each two projections from the skeleton commute, not only the compatible pairs)
if and only if $D$ is a ``$\Sigma$-subset'' of $K$; see e.g. the \cite[p. 56]{cuthCMUC}. In \cite[Theorem 2.1]{kalendaCharact} it is proved that $D$ is a $\Sigma$-subset of $K$ if and only if $D$ is countably compact and $(\C(K),\tau_p(D))$ is primarily Lindel\"of (see {\cite[Definition 1.2]{kalendaCharact}}). To characterize sets induced by a possibly noncommutative retractional skeleton, we replace the property to be primarily Lindel\"of by the monotonical Sokolov property.

\begin{proof}[Proof of Theorem \ref{t:answerCuth}]
Assume that $D$ is induced by a retractional skeleton in $K$. One can notice that, by Fact~\ref{f:basics}, $D$ is countably compact and $K=\beta D$.
Hence, $D$ has a full retractional skeleton (by the trivial implication of Proposition~\ref{p:rSkeletonInBetaX}). By Theorem~\ref{t:main}, $D$ is monotonically retractable; hence, by Fact~\ref{f:mrs}, $\C_p(D)$ is monotonically Sokolov. Taking into account that $\beta D = K$, $\C_p(D)$ is homeomorphic to $(\C(K),\tau_p(D))$. Thus, $(\C(K),\tau_p(D))$ is monotonically Sokolov.

For the converse implication, let us assume that $D$ is countably compact and $(\C(K),\tau_p(D))$ is monotonically Sokolov.
By Fact~\ref{f:mrs} the space $\C_p(\C(K),\tau_p(D))$ is monotonically retractable. The mapping $\Psi:D\to\C_p(\C(K),\tau_p(D))$
defined by
\[
\Psi(d)(f)=f(d),\quad f\in \C(K), d\in D
\]
is continuous (by the very definition of the respective topologies) and one-to-one. Further, for any closed
$F\subset D$ its image $\Psi(F)$ is countably compact and hence closed in $\C_p(\C(K),\tau_p(D))$ (by Fact~\ref{f:mrs}). It follows that
$\Psi$ is a homeomorphism of $D$ onto a closed subset of $\C_p(\C(K),\tau_p(D))$, thus $D$ is monotonically retractable. So, by Theorem~\ref{t:main} that $D$ has a full retractional skeleton. It follows that $D$ is countably closed in $K$ (it follows from the definitions that the closure in $D$ of any countable subset of $D$ is compact). Further, $(\C(K),\tau_p(D))$ is Lindel\"of by Fact~\ref{f:mrs}. Hence, by \cite[Proposition 2.13]{kalendaCharact}, $\beta D = K$.  By Proposition~\ref{p:rSkeletonInBetaX}, $D$ is induced by a retractional skeleton in $K$.\end{proof}

Let us now formulate the more precise version of Theorem~\ref{t:answerKubis} which we will prove. It is the following theorem which can be viewed
as a noncommutative version of \cite[Theorem 2.7]{kalendaSurvey} (which is a precise formulation of \cite[Theorem 2.3]{kalendaCharact}).

\begin{theorem}\label{t:skeletonIffXSokolov} Let $E$ be a Banach space and $D$ a dense subset of $(B_{E^*},w^*)$. Then the following are equivalent:
\begin{enumerate}[\upshape (i)]
	\item $\sspan(D)$ is induced by a 1-projectional skeleton in $E$ and $\sspan(D)\cap B_{E^*} = D$.
	\item $D$ is a convex symmetric set induced by a retractional skeleton in $(B_{E^*},w^*)$.
	\item $D$ is weak$^*$ countably compact and $(E,\sigma(E,D))$ is monotonically Sokolov.
\end{enumerate}
\end{theorem}

A \emph{projectional skeleton} in a Banach space $E$ is an indexed system of bounded linear projections on $E$ with the properties of a retractional skeleton, except for the first property which is replaced by the assumption that the projections have separable ranges. By metrizability the last condition implies that the ranges of projections cover $E$. A $1$-projectional skeleton is a projectional skeleton formed by norm one projections.
The subspace generated by a projectional skeleton is the union of ranges of adjoint projections. The adjoint projections of a $1$-projectional skeleton on $E$ form a retractional skeleton on $(B_{E^*},w^*)$. For exact definitions and explanations see \cite{kubisSkeleton} or \cite{cuthSimul}.
We will deal with projectional skeletons via retractional skeletons using the following lemma. In its proof we use the notation from \cite{kubisSkeleton}.

\begin{lemma}\label{l:projectionalIffRetractional}Let $E$ be a Banach space and $D\subset E^*$ a 1-norming subspace of $E^*$. Then $D$ is induced by a 1-projectional skeleton if and only if $D\cap B_{E^*}$ is induced by a retractional skeleton in $(B_{E^*},w^*)$.
\end{lemma}
\begin{proof} The `only if part' is easy and is proved in \cite[Theorem 4.2]{cuthSimul}. Let us prove the `if part'. Suppose that
$D\cap B_{E^*}$ is induced by a retractional skeleton in $(B_{E^*},w^*)$. By \cite[Theorem 4.2]{cuthSimul}, $D$ is a subset of a set $D(\mathfrak{s})$ induced by a 1-projectional skeleton. Thus, by the `if part', $D(\mathfrak{s})\cap B_{X^*}$ is induced by a retractional skeleton. We have $D\cap B_{X^*}\subset D(\mathfrak{s})\cap B_{X^*}$, both induced by a retractional skeleton. Consequently, by \cite[Lemma 3.2]{cuthCMUC}, $D\cap B_{X^*} = D(\mathfrak{s})\cap B_{X^*}$ and $D = D(\mathfrak{s})$ is induced by a 1-projectional skeleton.
\end{proof}

Now we proceed to the proof of  Theorem~\ref{t:skeletonIffXSokolov}. We follow the line of the proof of \cite[Theorem 2.3]{kalendaCharact}; instead of ``$\Sigma$-subset'' we use the notion of a set induced by a retractional skeleton and instead of ``homeomorphic to a closed coordinatewise bounded subset of some $\Sigma(\Gamma)$'' we use spaces with a full retractional skeleton. Thus, some technical details must be handled in a slightly different way. Namely, we need the following analogue of \cite[Lemma 2.18]{kalendaCharact}.

\begin{lemma}\label{l:kalendaBetaA}Let $X$ be a Banach space and $A\subset (B_{E^*},w^*)$ be a dense, convex and symmetric set with a full retractional skeleton. If $(E,\sigma(E,A))$ is Lindel\"of, then $B_{E^*} = \beta A$.
\end{lemma}
\begin{proof}
The proof is identical with the proof of \cite[Lemma 2.18]{kalendaCharact} which goes through a technical \cite[Lemma 2.17]{kalendaCharact}.
There, instead of a set with a full retractional skeleton (resp. a set induced by a retractional skeleton), set ``homeomorphic to a closed coordinatewise bounded subset of some $\Sigma(\Gamma)$'' (resp. ``$\Sigma$-subset'') is considered. Thus, it is enough to observe that sets with a full retractional skeleton (resp. sets induced by a retractional skeleton) have the topological properties needed in the proofs.

Namely, it is enough to use the following properties:
\begin{itemize}
	\item If $D$ has a full retractional skeleton, is is countably closed in each superspace, in particular $A$ is countably closed in $(B_{E^*},w^*)$.
	\item If $D$ has a full retractional skeleton, it is induced by a retractional skeleton in $\beta D$ (Proposition~\ref{p:rSkeletonInBetaX}).
	\item If $D$ is induced by a retractional skeleton in a compact space $K$ and $F\subset D$ is relatively closed, then $F$ is induced by a retractional skeleton in $\ov{F}^K$ (\cite[Lemma 3.5]{cuthCMUC}) and hence $\ov{F}^K=\beta F$ (Fact~\ref{f:basics}).
	\item If $D_i$ are sets induced by a retractional skeleton in compact spaces $K_i$ for $i = 1,\ldots,n$, then $D_1\times\ldots\times D_n$ is induced by a retractional skeleton in $K_1\times\ldots\times K_n$ (see the proof of \cite[Theorem 31]{kubisSkeleton}).
\end{itemize}
\end{proof}

\begin{proof}[Proof of Theorem \ref{t:skeletonIffXSokolov}] Implication (i)$\Rightarrow$(ii) follows immediately from Lemma~\ref{l:projectionalIffRetractional}. Let us assume that (ii) holds. By Fact~\ref{f:basics}, $D$ is weak$^*$ countably compact. Put $K = (B_{E^*},w^*)$. By Theorem~\ref{t:answerCuth}, $(\C(K),\tau_p(D))$ is monotonically Sokolov. Consider the $\sigma(E,D)$-$\tau_p(D)$ homeomorphism $I:E\to\C(B_{E^*},w^*)$ defined by $I(x)(x^*) = x^*(x)$, $x\in E$, $x^*\in E^*$. It is a standard fact, see e. g. \cite[Lemma 4.4]{cuthSimul}, that $I(E)$ is $\tau_p(D)$-closed in $\C(B_{E^*},w^*)$. By Fact~\ref{f:mrs} $I(E)$ is monotonically Sokolov and hence $(E,\sigma(E,D))$ is monotonically Sokolov.

It remains to prove (iii)$\Rightarrow$(i). Let us assume that (iii) holds. Since $(E,\sigma(E,D))$ is monotonically Sokolov, $\C_p(E,\sigma(E,D))$ is monotonically retractable due to Fact~\ref{f:mrs}. Observe that $\sspan(D)\subset \C(E,\sigma(E,D))$ and that the inclusion map $i:(\sspan(D),w^*)\to \C_p(E,\sigma(E,D))$ is a homeomorphism. Since $D$ is weak$^*$ countably compact, it is a countably compact subset of $\C_p(E,\sigma(E,D))$,
so $D$ is closed in the latter space by Fact~\ref{f:mrs}. Hence $D$ is monotonically retractable. If we put $A = \sspan(D)\cap B_{E^*}\subset\C_p(E,\sigma(E,D))$, then $D$ is dense in $A$ (since it is weak$^*$ dense in $B_{E^*}$). It follows that $D=A$.
By Theorem~\ref{t:main} $A$ has a full retractional skeleton. By Lemma~\ref{l:kalendaBetaA}, $\beta A = B_{E^*}$ and hence $A$
is induced by a retractional skeleton in $B_{E^*}$ by Proposition~\ref{p:rSkeletonInBetaX}. Finally, by Lemma~\ref{l:projectionalIffRetractional}, $\sspan(D)$ is induced by a 1-projectional skeleton in $E$.
\end{proof}

We finish by showing how Theorem~\ref{t:answerKubis} follows from Theorem~\ref{t:skeletonIffXSokolov}. Similarly as above, for details concerning projectional skeletons we refer to \cite{kubisSkeleton} where all the fact needed in the proof bellow may be found.

\begin{proof}[Proof of Theorem \ref{t:answerKubis}]
Let $\langle E,\|\cdot\|\rangle$ be a Banach space and $D\subset E^*$ a norming subspace. Then there is an equivalent norm $|\cdot|$ on $X$ such that $D$ becomes 1-norming; see e. g. \cite[Proposition 1]{kubisSkeleton}. Then $D\cap B_{\langle E,|\cdot|\rangle^*}$ is weak$^*$ dense in $B_{\langle E,|\cdot|\rangle^*}$. So,
it follows from Theorem~\ref{t:skeletonIffXSokolov} that $D$ is induced by a $1$-projectional skeleton in $E$ if and only $D\cap B_{\langle E,|\cdot|\rangle^*}$
is weak$^*$-countably compact and $(E,\sigma(E,D))$ is monotonically Sokolov. Since the topology $\sigma(E,D)$ does not depend on the choice of an equivalent norm and any subspace induced by a projectional skeleton is weak$^*$ countably closed, the assertion (ii) holds if and only if $D$ is induced by a $1$-projectional skeleton in $\langle E,|\cdot|\rangle$.

Now, it is enough to show that $D$ is induced by a projectional skeleton in $\langle E,\|\cdot\|\rangle$ if and only if $D$ is induced by a 1-projectional skeleton in $\langle E,|\cdot|\rangle$. If $D$ is induced by a 1-projectional skeleton in $\langle E,|\cdot|\rangle$,
the same system of projections is a projectional skeleton in $\langle E,\|\cdot\|\rangle$ and induces $D$.
Conversely, let $D$ be induced by a projectional skeleton in $\langle E,\|\cdot\|\rangle$.  By \cite[Theorem 15]{kubisSkeleton} then $D$ generates projections in $E$ and there exists a 1-projectional skeleton $\mathfrak{s}$ in $\langle E,|\cdot|\rangle$ such that $D\subset D(\mathfrak{s})$.
Since the projectional skeleton in $\langle E,\|\cdot\|\rangle$ inducing $D$ remains to be a projectional skeleton in $\langle E,|\cdot|\rangle$,
\cite[Corollary 19]{kubisSkeleton} implies $D= D(\mathfrak{s})$.
\end{proof}

\def\cprime{$'$}