---
author:
- 'Alexey Mints[^1]'
- Saskia Hekker
bibliography:
- 'sage\_gap.bib'
date: 'XXX/YYY'
title: 'A Unified tool to estimate Distances, Ages, and Masses (UniDAM) from spectrophotometric data.[^2]'
---

 .

Introduction {#sec:intro}
============

The Milky Way Galaxy is a unique object to test our understanding of stellar evolution, galaxy formation, and cosmology. For this test a detailed map of our Galaxy, including bulge, disk, halo, spiral structure, and streams formed by recent mergers, is required. Through an analysis of the Galaxy, we can learn how our Galaxy has formed, evolved, and how it interacts with its surroundings. To build such a map we need to find the distribution of stars in their positions, velocities, chemical compositions, and ages throughout the Galaxy. These parameters can be measured with different kinds of observations, such as astrometry, photometry, spectroscopy, and asteroseismology.

Astrometric observations provide stellar positions, proper motions and, through parallaxes, distances. These kind of data have been available for decades . In the nearest future Gaia [@2016arXiv160904172G] will vastly increase the precision and amount of such information. The first Gaia data release [@2016arXiv160904303L] already provides proper motions and parallaxes for about two million stars, although the precision of parallaxes in this sample limits their application [see e.g. @2016arXiv160905390S]. In the next data releases Gaia will provide high-precision parallaxes and proper motions for hundreds of millions of stars, vastly increasing our knowledge of the Galaxy.

Another rich source of data is spectroscopy, which can provide radial velocities, chemical compositions as well as the effective temperature ${\ensuremath{T_{\rm{eff}}}}$ and the surface gravity $\log g$. These data can be used to derive stellar ages and distances (see below). A growing number of large spectroscopic surveys, such as RAdial Velocity Experiment [RAVE; @2016arXiv160903210K], Large Sky Area Multi-Object Fibre Spectroscopic Telescope (LAMOST) surveys [@2015RAA....15.1095L], Apache Point Observatory Galactic Evolution Experiment [APOGEE; @2014ApJS..211...17A], Sloan Extension for Galactic Understanding and Exploration [SEGUE; @2009AJ....137.4377Y], and Gaia-ESO [@GAIA_ESO] provide rich spectroscopic information for millions of stars.

Photometric surveys can be used in two ways. Stromgren or Washington-DDO51 photometry can be used to estimate stellar parameters such as the effective temperature ${\ensuremath{T_{\rm{eff}}}}$, surface gravity $\log g$, and metallicity ${[\rm{Fe/H}]}$ [see @2011AA...530A.138C], or to separate giants from dwarfs for spectroscopic follow-up [@2000AJ....120.2550M]. Otherwise, broadband photometry is commonly used as a supplement to spectroscopic data to infer stellar distances.

Asteroseismology is a relatively young and very promising method of exploring stars. For low-mass dwarfs, subgiants, and red giant stars asteroseismology can provide a direct measure of mean density and surface gravity. The surface gravities measured by asteroseismic methods have much higher precision than spectroscopic methods. In case the effective temperature ${\ensuremath{T_{\rm{eff}}}}$ or luminosity $L$ are also measured it is possible to obtain stellar mass and radius from the asteroseismic observables. When compared with models stellar ages can also be determined from asteroseismology. COnvection ROtation and planetary Transits [CoRoT; @2006ESASP1306...33B], *Kepler* [@2010Sci...327..977B], and *K2* [@2014PASP..126..398H] observations provide such asteroseismic data. These datasets provide high-precision data on small patches of the sky and also have proved to be a perfect sample for the calibration of large spectroscopic surveys . Transiting Exoplanet Survey Satellite [TESS; @2014SPIE.9143E..20R] and PLAnetary Transits and Oscillations of stars [PLATO; @2014ExA....38..249R] space missions are scheduled to be launched in 2018 and 2024, respectively, and will vastly increase the number of stars with asteroseismic data in the coming years.

Stellar ages and distances remain among the most challenging parameters to measure. A comprehensive list of age determination methods is given in . For a number of stars ages can be derived from asteroseismic observations [@2016AN....337..823S] or from carbon and nitrogen abundances [@2016MNRAS.456.3655M]. When these data are not available, a typical approach is to compare the parameters directly derived from spectroscopic measurements, which we designate as observed parameters, such as the effective temperature ${\ensuremath{T_{\rm{eff}}}}$, surface gravity $\log g$, and metallicity ${[\rm{Fe/H}]}$, to a grid of stellar models. A model or a set of models that have their parameters close to observed parameters give estimates of ages, masses, and absolute magnitudes $M_\lambda$ of a star. Then by comparing the absolute magnitudes to visible magnitudes $m_\lambda$ from photometric surveys we can estimate distances to stars. An overview of this approach is given by and .

Proper application of this approach requires some care. First, the transformation from observed ([${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{}) to stellar parameters (age and mass) and distance is often degenerate, with the same observables giving two or more possible combinations of stellar parameters. This degeneracy can in some rare cases be resolved when additional observables are available, for example from asteroseismology. Second, the interstellar extinction needs to be accounted for in distance estimations. Extinction values can be taken from external sources or can be derived from observables. Both ways have their advantages and disadvantages. We discuss this in Section \[sec:bayes\]. Third, observed parameters have their uncertainties and correlations that have to be propagated to uncertainties in stellar parameters.

In the literature a number of methods based on the comparison of observed parameters from spectroscopic and photometric surveys with models to estimate distances and other stellar parameters were proposed and used recently. Here we briefly discuss some of them, and how they deal with the issues stated above.

#### GCS. {#gcs. .unnumbered}

The Geneva-Copenhagen Survey (GCS) [@2011AA...530A.138C] team exploited the advantage of having *HIPPARCOS* parallaxes for the majority of their objects; this facilitated the calculation of absolute magnitudes for each star. @2011AA...530A.138C used a Bag of Stellar Tracks and Isochrones (BASTI) [@2009ApJ...697..275P and references therein] and PAdova and TRieste Stellar Evolution Code (PARSEC) [@PARSEC] isochrones to select models that have ${\ensuremath{T_{\rm{eff}}}}$, absolute Johnson $V$ magnitude and metallicity close to the observed ones for each star. Applying a Bayesian scheme described in to selected models, Casagrande et al. derived masses and ages of stars. They used a flat prior on ages and a Salpeter initial mass function (IMF) as a prior for masses.

#### RAVE. {#rave. .unnumbered}

There is a series of papers on distance estimations for stars in the RAVE survey [DR5 is described in @2016arXiv160903210K]. proposed a method for distance estimation for RAVE stars based on a comparison of observed ${\ensuremath{T_{\rm{eff}}}}, \log g$, metal abundance ${[\rm{M/H}]},$ and colour $(J-K_s)$ with $Y^2$ models [@2004ApJS..155..667D]. For each star 5000 realisations of observed parameters were sampled from a Gaussian distribution with dispersions equal to the measured uncertainties and for each realisation a closest model was selected. These authors took an average of the model parameters measured in all realisations to derive an absolute $J$ magnitude of the star $M_J$. The difference between the derived absolute magnitude and visible $J$ magnitude from Two Micron All Sky Survey (2MASS) gives a distance. Extinction was ignored in this work. This approach is limited by the fact that it does not take into account the inhomogeneity of models in the ${\ensuremath{T_{\rm{eff}}}}- \log g$ plane, effectively increasing the weight for short evolutionary stages and decreasing it for longer ones. This issue was solved in by weighting models with a weight proportional to age and mass range represented by each model. A likelihood depending on the difference between observed and model ${\ensuremath{T_{\rm{eff}}}}$ and $\log g$ was also added. Other important changes were applied, including a change from $Y^2$ to PARSEC [@PARSEC] isochrones, the addition of a prior on mass (assuming [@2003PASP..115..763C] IMF), and the application of a volume correction. Zwitter et al. calculated an absolute $J$ magnitude as a weighted mean of the absolute magnitudes derived from luminosities of the models. The difference between the visible $J$ magnitude from 2MASS and the absolute magnitude gives the distance modulus for each star. As in , extinction was ignored.

[@2014MNRAS.437..351B] further developed the above method by adding priors from the Galactic structure; they provide priors on age, metallicity, and positions from halo, thin, and thick disk models. A kinematic correction [see @2012MNRAS.420.1281S] was also applied. Extinction was included into distance calculations. An exponential prior on the value of $ln(A_V)$ was imposed with the extinction value at infinity $ A_{V\infty}(b, l)$ taken from [@1998ApJ...500..525S]. The extinction at a given distance was calculated as $A_{Vprior}(b, l, s) = A_{V\infty}(b, l) \int_0^s \rho(s) ds / \int_0^\infty \rho(s) ds$, where $\rho(s)$ is the density of extincting material along the line of sight, taken from the model of the Galaxy [see the Equation 10 in @2014MNRAS.437..351B]. This is so far the most advanced method and it was applied with minor modifications to LAMOST data as well (see below). Distance moduli (but not ages and masses) were recalculated with the same method for RAVE DR5. [@2014MNRAS.437..351B] solved the problem of multimodal probability distribution functions (PDFs) for the distance modulus by fitting a Gaussian mixture model to it with up to three Gaussians. This approach works fine in most cases. However, as we illustrate below in it cannot be applied to mass and log(age) PDFs because they can be skewed or truncated, a shape which is hard to fit with a small set of Gaussians. Truncated shapes of the PDF arise from a limited range of allowed masses and log(age)s. For [@2014MNRAS.437..351B] limits are imposed by an age prior; see their Equations 3, 4, and 5.

#### APOKASC. {#apokasc. .unnumbered}

[@2014MNRAS.445.2758R] applied Bayesian methods to estimate distances and extinctions for approximately 2000 red giant stars from the joint APOGEE and Kepler Asteroseismic Science Consortium (APOKASC) sample [@2014ApJS..215...19P], which is a part of APOGEE [@2014ApJS..211...17A], covering the *Kepler* field of view. They supplemented spectroscopic parameters ${\ensuremath{T_{\rm{eff}}}}$ and ${[\rm{M/H}]}$ with asteroseismic data from *Kepler*. As alluded to before, from asteroseismic values $\Delta \nu$ and $\nu_{\rm{max}}$ and knowing ${\ensuremath{T_{\rm{eff}}}}$, it is possible to derive an estimate of stellar radius $R$ and mass $M$, using scaling relations from , i.e. $$\begin{aligned}
 \Delta \nu &\propto& M^{1/2} R^{-3/2} \\
 \nu_{\rm{max}} &\propto & M R^{-2} {\ensuremath{T_{\rm{eff}}}}^{-1/2}.\end{aligned}$$ This puts more constraints on stellar models, thus increasing the precision of stellar parameters and distance determinations. Using PARSEC isochrones, [@2014MNRAS.445.2758R] built PDFs for stellar parameters (mass, radius, and surface gravity) and stellar absolute magnitudes. The latter were then combined with photometric data from Sloan Digital Sky Survey (SDSS), 2MASS, and Wide-field Infrared Survey Explorer (WISE) to be converted to the PDFs of distance modulus $\mu_d$ and extinction $A_K$. The mode and 68% confidence intervals of the PDFs were calculated for both distance and extinction. [@2014MNRAS.445.2758R] noted that over one-third of stars in their sample have bimodal PDFs. Bimodal PDFs were treated in the same way as single-peaked PDFs. Using the mode allows one to select the highest peak of the PDF and other peaks only show themselves by broadening of confidence intervals. Only distance estimates were published by [@2014MNRAS.445.2758R].

#### LAMOST. {#lamost. .unnumbered}

The LAMOST team is also working on estimating distances to stars from spectroscopic data. First and second public data releases of the project include spectral properties for about one and two million stars, respectively [@2015RAA....15.1095L].

[@2015AJ....150....4C] used a Bayesian approach to derive distances from LAMOST DR1 data combined with 2MASS photometry. They used the Dartmouth Stellar Evolution Database [@2008ApJS..178...89D] and a Bayesian technique similar to that by to derive the PDF of the absolute magnitude for each star. This was then converted to distances using 2MASS photometry. Interstellar extinction was ignored in this work. [@2015AJ....150....4C] performed a comparison with RAVE distances to test their method. The derived distances are systematically smaller by 12% than those derived by with 16% spread. Given the precision of the LAMOST data, they derived distance uncertainties to be on the order of 40%.

[@2016MNRAS.456..672W] applied the Bayesian approach from [@2014MNRAS.437..351B] to derive parallaxes and extinctions for LAMOST data. Again, 2MASS photometry was used. The reported uncertainty in parallax is about 20% for dwarf stars and 40% for giants. Kinematic correction [see @2012MNRAS.420.1281S] was applied using PPMXL [@2010AJ....139.2440R] and UCAC4 [@2013AJ....145...44Z] data. Data from [@2015AJ....150....4C] and [@2016MNRAS.456..672W] are not yet publicly available.

Distances are provided in the LAMOST Galactic Anti-Centre project data release [@2015MNRAS.448..855Y]. These data include spectroscopic measurements of [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} and photometry from 2MASS and Xuyi Schmidt Telescope Photometric Survey [@2014RAA....14..456Z]. In their work, [@2015MNRAS.448..855Y] applied two different methods to get distances. In the first method, which they call “empirical”, stars are divided into four groups (OB stars, giants, and two groups of dwarfs). For each group absolute magnitudes were calculated using a third-order polynomial of [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{}. Polynomials were derived by fitting data from the parts of the medium resolution INT Library of Empirical Spectra (MILES) library [@2006MNRAS.371..703S] corresponding to each group. The precision of the obtained distance modulus is about $0.^m65$ for GKM giants and $0.^m3$ for other groups. A second, “isochrone” distance estimate was derived using the isochrones of Dartmouth Stellar Evolution Database [@2008ApJS..178...89D]. For each star a model with closest values of [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} was selected from the database. A difference between the visible magnitudes of the star and absolute magnitudes for the closest model provides distance. For both methods extinction values were derived from the LAMOST data using the star-pairs method, which is described in [@2014IAUS..298..240Y]. The “isochrone” method provides distances that are about 5 percent lower than those derived by the “empirical” method.

####  {#section .unnumbered}

Studies listed above use similar methods, but the implementation can vary, leading to different results even for the same input data. Moreover, while distances are typically calculated, mass and, most importantly, age estimates are less common. The amount of complementary spectroscopic data available in different surveys calls for a more unified approach. In this paper we present a Unified tool to estimate Distances, Ages, and Masses from spectrophotometric data (UniDAM). There are two major points in which we differ from studies listed above:

First, whereas most of the previously published studies were dedicated to data from a single survey, we processed data from several large surveys with one tool. For some surveys no data on distances, masses, and ages are publicly available to date. For others our results are consistent with previously published studies with the advantage that our catalogue was produced with the same method, isochrones, and priors on parameters for all surveys. Thus all differences in results for different surveys can be attributed to systematic differences in parameters determined in the spectroscopic surveys. We provide more details on spectroscopic surveys used in Section \[sec:catalog\]. Another advantage of using many surveys simultaneously comes from the fact that different surveys probe different parts of the Galaxy because of different observing strategies and locations of telescopes. Therefore we do not simply increase the statistics, but have a more complete coverage of the Galaxy.

Second, we try to lift the degeneracy of the transformation from observed to stellar parameters by representing PDFs as sums of unimodal functions (unimodal sub-PDFs or USPDF) for each evolutionary stage. Thus we separate out physically different solutions. This allows us to increase the precision of stellar parameters for each solution.

Data samples used {#sec:catalog}
=================

We used observable parameters from a set of publicly available spectroscopic surveys in our work. All surveys were cross-matched with 2MASS [@2006AJ....131.1163S] and AllWISE [@2014yCat.2328....0C] to get the infrared photometry. We used only ”clean“ photometry that is only bands that are not affected by low photometric quality, contamination, or confusion. This was achieved by taking only bands with 2MASS quality flag (`Qfl`) set to `’A’` and AllWISE bands with the contamination and confusion flag (`ccf`) set to zero and photometric quality flag (`qph`) set to `’A’`. We also requested that the reported uncertainty in magnitude has a positive value. summarises properties of the spectroscopic surveys from which we extracted our input data. We discuss some of them below, focusing on parameters for each survey, which we added or modified for our purposes.

[lrrd[3.1]{}ccc]{} Survey & N sources & Resolution & [ ]{} & [ ]{} & [ ]{} & Reference\
APOGEE (DR12) & $88\,000$ & $22\,500$ & 91.5 & 0.11 & 0.03 &\
APOGEE (DR13)\* & $89\,000$ & $22\,500$ & 91.5 & 0.11 & 0.03 &\
APOKASC & $2\,000$ & $22\,500$ & 91.5 & 0.11 & 0.03 &\
LAMOST-GAC (Main sample)\* & $368\,000$ & $1\,800$ & 115 & 0.19 & 0.15 &\
LAMOST-GAC (Bright sample)\* & $1\,075\,000$ & $1\,800$ & 100 & 0.15 & 0.13 &\
LAMOST-CANNON\* & $450\,000$ & $1\,800$ & 96.3 & 0.13 & 0.05 &\
RAVE (DR5) & $450\,000$ & $7\,500$ & 92 & 0.20 & 0.10 &\
RAVE-on\* & $450\,000$ & $7\,500$ & 85 & 0.14 & 0.07 &\
GCS\* & $13\,800$ & $20\,000$ & 80 & 0.10 & 0.10 &\
SEGUE\* & $277\,500$ & $2\,000$ & 145 & 0.26 & 0.13 &\
Gaia-ESO (DR2)\* & $7\,000$ & $16\,000$ & 50 & 0.10 & 0.07 &\
AMBRE\* & $3\,400$ & $16\,000$ & 120 & 0.20 & 0.10 &\
GALAH (DR1)\* & $28\,000$ & $10\,700$ & 108 & 0.30 & 0.11 &\
Mock & $4 \times 8\,000$ & - & 100 & 0.10 & 0.10 & -\

\[tbl:catalog\]

APOGEE and APOKASC {#sec:apogee}
------------------

We used APOGEE data from SDSS DR12 [@2015ApJS..219...12A] and DR13 [@2016arXiv160802013S]. We kept only those stars that belong to the Main Survey Targets[^3] and have their temperatures, gravities, and metallicities measured. Both DR12 and DR13 were used, as they differ mainly in spectroscopic calibration, and it is interesting to test how that influences the estimates of age, mass, and distance. We include our results for DR13 data in our final catalogue, whereas results for DR12 data are provided as a separate table.

We use as a separate input survey the APOKASC sample [@2014ApJS..215...19P], although it is in this context just a subset of APOGEE. Therefore the result for this sample is not included in our final catalogue. These data were used to compare the results of [@2014MNRAS.445.2758R] with the prospect of the inclusion of asteroseismic data (see Section \[sec:compare\_apokasc\]).

LAMOST
------

The second public data release of the LAMOST project [@2015RAA....15.1095L] contains spectral parameters for over 2 million stars. However, the uncertainties in the stellar parameters reported, i.e. $170\,$K in ${\ensuremath{T_{\rm{eff}}}}$, $0.5\,$dex in $\log
g$ and $0.2\,$dex in ${[\rm{Fe/H}]}$, are too high for these data to be used reliably for the model fitting. Therefore we decided not to use the main LAMOST dataset. We focused instead on the LAMOST Galactic Anti-Center (LAMOST-GAC) project second data release [@2017arXiv170105409X]. This data release contains spectral parameters for about one-third of a million stars in the direction of the Galactic anti-center in its main sample. The bright sample contains over a million stars from a larger area. A different processing pipeline was used by LAMOST-GAC team, which resulted in substantially lower parameter uncertainties of $115\,$K in ${\ensuremath{T_{\rm{eff}}}}$, $0.2\,$dex in $\log g,$ and $0.13\,$dex in ${[\rm{Fe/H}]}$.

An additional dataset derived from LAMOST DR2 data was prepared with The Cannon tool [@2015ApJ...808...16N; @2016arXiv160200303H]. This tool allows the transfer of parameters from high-resolution APOGEE spectra to LAMOST data using stars observed by both surveys for the calibration. This method transfers APOGEE uncertainties in the measured parameters to the LAMOST data, improving the precision of obtained parameters. To account for calibration uncertainties we added in quadrature the median APOGEE absolute uncertainties to the formal uncertainties reported by *The Cannon*. Another benefit of *The Cannon* tool is that it measures the value of $[\alpha/\rm{Fe}]$, which is not provided by LAMOST. The *The Cannon* tool was only calibrated for giant stars, which are available from APOGEE-LAMOST overlap and therefore the LAMOST-CANNON sample contains only giant stars.

RAVE surveys
------------

The fifth data release of the RAVE project [@2016arXiv160903210K] contains spectral parameters for almost half a million stars. This release contains a flag indicating whether the fitting algorithm has converged, but it turns out that even for stars with this flag set to zero (indicating that the fit converged) there are clear concentrations of values of effective temperatures and gravities towards grid points. This feature is known to the community [see @2014MNRAS.437..351B]. We added in the output catalogue a flag that indicates if $\log {\ensuremath{T_{\rm{eff}}}}$ is within $0.01\,$dex of a grid point or if $\log g$ or ${[\rm{Fe/H}]}$ are on a grid point. About one-third of the stars are affected by clustering around grid points.

The RAVE-on [@2016arXiv160902914C] is a product of processing of original RAVE spectra with *The Cannon* tool. Calibration set was constructed from the overlap of RAVE with APOGEE giants and K2/EPIC survey [@2016ApJS..224....2H]. In addition to [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{},the output of *The Cannon* tool also contains the value of $[\alpha/\rm{Fe}]$ and abundances for several chemical elements. The RAVE-on data refer to exactly the same stars as the main RAVE survey, but the reported stellar parameters might be slightly different and the quoted uncertainties are smaller, therefore we chose to use RAVE-on in our catalogue, providing results for the main RAVE survey in a separate table.

Geneva-Copenhagen survey
------------------------

Geneva-Copenhagen survey (GCS) is the only non-spectroscopic survey used in this work. GCS is a photometric survey, which contains [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} derived using Stromgren photometry. We used GCS re-analysed data published by [@2011AA...530A.138C]. We exclude $15\%$ of the stars for which no estimates of [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{}  are provided or for which no photometry was present. The latter was mainly because a number of GCS sources are too bright for 2MASS.

SEGUE
-----

We used SEGUE data from SDSS DR12 [@2009AJ....137.4377Y] with internal uncertainties from the SDSS database. We add in quadrature the internal and systematic uncertainties derived by [@2008AJ....136.2070A] of $130\,$K in ${\ensuremath{T_{\rm{eff}}}}$, $0.21\,$dex in $\log g$ and $0.11\,$dex in ${[\rm{Fe/H}]}$. The SEGUE survey is based on SDSS photometry, which is deeper than 2MASS, therefore for about one-half of SEGUE targets no 2MASS or AllWISE photometry is available or the photometry is very uncertain. We do not use such stars in our work.

Gaia-ESO
--------

For the Gaia-ESO survey, the data release 2 [@GAIA_ESO] was used. For nearly half of its nearly $15\,000$ spectra ${\ensuremath{T_{\rm{eff}}}}, \log g$ and ${[\rm{Fe/H}]}$ are available. So we used approximately $7\,000$ sources from this survey.

AMBRE
-----

Atmospheric Parameters and Chemical Abundances from Stellar Spectra [AMBRE; @AMBRE] project released parameters extracted from the automatic analysis of the ESO spectral data archives for over $4\,500$ observations (over $2\,000$ sources). No photometry or positional information are provided in the project data, so we attempted to get this information using target names. With the SIMBAD service we obtained positions for nearly $1\,500$ sources, having a total of $3\,400$ observations in the AMBRE survey.

GALAH
-----

[@GALAH] describe the GALactic Archaeology with HERMES (GALAH) survey first data release. Stellar parameters were derived for 2576 GALAH stars with the Spectroscopy Made Easy (SME) tool [@2012ascl.soft02013V]. These data were used as a training sample for *The Cannon* tool, which was then used to derive stellar parameters for the rest of the survey. @GALAH provide typical uncertainties of *The Cannon* tool used to derive spectral parameters and internal precision of the SME. We added them in quadrature to get uncertainties of $108\,$K in ${\ensuremath{T_{\rm{eff}}}}$, $0.3\,$dex in $\log g$ and $0.11\,$dex in ${[\rm{Fe/H}]}$.

Mock survey {#sec:data_mock}
-----------

In addition to real survey data we also created a mock survey to test our UniDAM tool. In this case we have full control on both the input parameters for our tool and the desired output parameters of the star. We produced mock surveys by sampling a number of models from PARSEC isochrones [@PARSEC] (see Section \[sec:iso\]).

We stress that the choice of models was aimed at covering model parameter space. So our mock survey does not resemble observed stellar surveys, which are typically magnitude-limited, nor a physical distribution of stars in masses and ages. We motivate our choice by the need to study the behaviour of our tool over a large parameter range. We chose isochrones with 8 different metallicities and 20 ages, which we selected at random. From each isochrone we randomly selected 20 models (with mass below 4 ${\ensuremath{\rm{M}_\odot}}$). We used ${\ensuremath{T_{\rm{eff}}}}, \log g, {[\rm{Fe/H}]}$ as well as 2MASS and AllWISE magnitudes for each selected model. High-mass stars were excluded because of their rarity. We took absolute magnitudes from PARSEC models as our “observed” magnitudes, thus setting the distance to 10 pc and extinction to zero. Parameter uncertainties were taken to be $100\,$K for ${\ensuremath{T_{\rm{eff}}}}$, $0.1\,$dex for $\log g$, and ${[\rm{Fe/H}]}$, and $0^m.03$ for each magnitude $m_\lambda$, which is similar to uncertainties in real spectroscopic and photometric surveys.

We prepared four mock surveys. In the first survey we took spectral and photometric values as provided by the PARSEC models. In the second survey we perturbed photometric parameters with random Gaussian noise, while keeping original spectroscopic parameters. In the third we perturbed spectral parameters with random Gaussian noise, while keeping original photometry. In the last survey all parameters were perturbed. Perturbation spread was always taken to be equal to the chosen parameter uncertainties. This allows us to control how uncertainties in observations influence our results.

Isochrones {#sec:iso}
==========

We used PARSEC 1.2S isochrones [@PARSEC], which provide a large sample of models covering a wide range of stellar parameters. These data include effective temperatures, surface gravities, radii, and absolute photometric magnitudes for a models covering large ranges in metallicities, ages, and masses. We selected nearly three million models that cover the following ranges:

-   $10^{-4} : 0.06\,$dex in metallicity ($Z$), corresponding to $-2.2 : 0.6\,$dex in ${[\rm{Fe/H}]}$

-   $6.6 : 10.13$ in log(age) $\tau$, corresponding to $4\cdot 10^6 : 13.5\cdot10^9$ years

-   $0.09 : 67\,{\ensuremath{\rm{M}_\odot}}$ in mass

The density of models varies within the ranges indicated above. The reason for this is that isochrones are designed to reproduce details of stellar evolution. Therefore, there are a relatively large number of models covering some rapid stages of evolution and there are a lower number of models for stages of slow evolution. To account for this, we introduced a value $w_j$ that is a measure of the volume of the parameter space (metallicity, age, and mass) represented by each model. Otherwise we would be biased towards rare evolutionary stages.

We calculated $w_j$ for each model as a product of width of the bin in each dimension represented by the model, $$w_j = w_{\rm{age}, j} w_{Z, j} w_{\rm{mass}, j}. \label{eq:weight}$$ The PARSEC isochrone models are calculated for the bin mid-points and they are not equal to the average model in each bin, which makes the binning somewhat arbitrary.

The PARSEC isochrones are equally spaced in log(age)s $\tau$. Therefore the density of models with lower ages is higher than that of models with higher ages. This has to be compensated for to avoid a bias towards lower ages. We took for the age bin width $w_{\rm{age}}$ the time span represented by the isochrone. It is calculated as $w_{\rm{age}, j} = (10^{\tau_{j+1}} - 10^{\tau_{j-1}})/2$, so time span range is defined by mid-points between isochrones in age.

Observations provide ${[\rm{M/H}]}$ or ${[\rm{Fe/H}]}$, which are proportional to the logarithm of $Z$. We created a grid in $Z$, ranging from $10^{-4}$ to $0.05$, such that the spacing between the values of ${[\rm{Fe/H}]}$ is smaller than the mean uncertainty $\sigma_{{[\rm{Fe/H}]}}$ of iron abundance measure at a given ${[\rm{Fe/H}]}$ in the most precise input data, i.e. APOGEE data. Typically, uncertainties in ${[\rm{Fe/H}]}$ are smaller for metal-rich stars than for metal-poor stars with $\sigma_{{[\rm{Fe/H}]}} \propto Z^{-0.15}$. Therefore $\Delta_Z$ – the bin width in $Z$ – is roughly $\Delta_Z \propto Z \sigma_{{[\rm{Fe/H}]}} \propto Z^{1 - 0.15} = Z^{0.85}$. The width of the bin in $Z$ was used for $w_Z$, thus ensuring a flat prior in $Z$. To check the impact of this, we performed tests with $w'_Z$ proportional to the width of the bin in ${[\rm{Fe/H}]}$. These tests showed that this difference has little impact on our results. This is caused by the fact that for given values of ${\ensuremath{T_{\rm{eff}}}}$ and $\log g$, stellar parameters like age, mass, and luminosity are changing slowly with ${[\rm{Fe/H}]}$ and $Z$, so the variations in weights are second-order effects. Thus $w_Z$ is the second-order effect, but we kept it to keep the flat prior in physical quantity $Z$.

Masses for models were selected by the PARSEC algorithm to track the shape of the isochrone as well as possible. This results in more models in more curved parts of the isochrone. Such an approach produces heavily inhomogeneous coverage of the mass range, which has to be corrected for. We used for $w_{\rm{mass}}$ the width of the bin in mass.

One of nine evolutionary stages is assigned to every PARSEC model. We grouped these stages into main-sequence stars and giants ascending the red giant branch (pre-core-helium burning; stage I), core-helium burning stars (stage II), and asymptotic giant branch stars (post-core-helium burning; stage III). These stage labels were used to separate models with different internal structures.

  Column        Description                                         Unit
  ------------- --------------------------------------------------- -------------------------------
  Z             Metallicity                                         -
  log(age/yr)   Age                                                 log(years)
  M\_ini        Initial mass                                        ${\ensuremath{\rm{M}_\odot}}$
  M\_act        Actual mass                                         ${\ensuremath{\rm{M}_\odot}}$
  logL/Lo       Luminosity                                          -
  logTe         Effective temperature                               -
  logG          Gravity                                             -
  ...           Set of absolute magnitudes (see text)               mag
  int\_IMF      Value of the cumulative IMF function $F(M_{ini})$   -
  stage         Evolutionary stage                                  -

  : PARSEC model columns (as named in the output of <http://stev.oapd.inaf.it/cgi-bin/cmd_2.7>).[]{data-label="tbl:parsec"}

For each model we used basic physical information (see ) and 2MASS and AllWISE absolute magnitudes that were derived from the luminosities. Other magnitudes are often available, but we did not use them for the reasons discussed below.

Methodology {#sec:bayes}
===========

The method used in our tool is similar to the Bayesian method described in [@2014MNRAS.445.2758R]. We introduced the vector ${\ensuremath{\textbf{O}}}$ for input (“observed”) parameters and their uncertainties ${\ensuremath{\textbf{O}}}= ({\ensuremath{T_{\rm{eff}}}}, \log g, {[\rm{Fe/H}]}, m_\lambda, \sigma_{{\ensuremath{T_{\rm{eff}}}}}, \sigma_{\log g}, \sigma_{{[\rm{Fe/H}]}}, \sigma_{m_\lambda})$. Here, $m_\lambda$ indicates visible magnitudes in several photometric bands and $\sigma_x$ is the uncertainty of the parameter $x$. These values were taken from surveys listed in . When $\alpha$ element abundances were available, the metallicity ${[\rm{Fe/H}]}$ was corrected with the relation ${[\rm{Fe/H}]}= {[\rm{Fe/H}]}_0 + \log(1. + 0.638[\alpha/\rm{M}])$ [see @1993ApJ...414..580S]. Additional input parameters for each star can be used in ${\ensuremath{\textbf{O}}}$, for example masses and radii derived from asteroseismic data or parallaxes from Gaia.

We used two vectors for output parameters. The first vector, $\textbf{X}_m = (\tau, M, {[\rm{Fe/H}]})$ represents stellar model parameters log(age), mass, and metallicity. These parameters are taken from isochrone models and therefore have discrete values. We always refer to the actual rather than initial stellar mass because this quantity can be measured from other data, for example from asteroseismic quantities or from binary orbital solutions. The second vector, ${\ensuremath{\textbf{X}}}_p = (\mu_d, A_K),$ where subscript $p$ stands for photometry, represents distance modulus and extinction; these parameters can formally have any value, but we set a physically motivated limit $A_K \geq 0$ (see discussion in ). The full output parameter vector is then ${\ensuremath{\textbf{X}}}= {\ensuremath{\textbf{X}}}_m \cup {\ensuremath{\textbf{X}}}_p$.

The probability of having parameters ${\ensuremath{\textbf{X}}}$ with given observables ${\ensuremath{\textbf{O}}}$ can be expressed via Bayesian formula as $$P({\ensuremath{\textbf{X}}}|{\ensuremath{\textbf{O}}}) = \frac{P({\ensuremath{\textbf{X}}}) P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}})}{P({\ensuremath{\textbf{O}}})} \propto P({\ensuremath{\textbf{X}}}) P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}).\label{eq:bayes}$$

We used flat priors on age (in linear scale) and metallicity $Z$, which means a star formation rate that is constant in time and is independent of $Z$. The quantitative effect of different priors is described below in Section \[sec:compare\_rave\]. We used a mass prior based on the IMF $F_\textrm{IMF}$ from @2003ApJ...598.1076K. Therefore, $$P({\ensuremath{\textbf{X}}}) = F_\textrm{IMF}({\ensuremath{M}}).\label{eq:prior}$$

Isochrones give us for each ${\ensuremath{\textbf{X}}}_m$ a new vector $\textbf{O'} = ({\ensuremath{T_{\rm{eff}}}}, \log g, {[\rm{Fe/H}]}, M_\lambda)$, where $M_\lambda$ indicates absolute magnitudes in several photometric bands. So we can define a function $\mathcal{I}$ as $\textbf{O'} = \mathcal{I}({\ensuremath{\textbf{X}}}_m)$. Noticeably, ${[\rm{Fe/H}]}$ is contained in both ${\ensuremath{\textbf{O}}}$ and ${\ensuremath{\textbf{X}}}_m$, so $\mathcal{I}_{{[\rm{Fe/H}]}}({\ensuremath{\textbf{X}}}_m) \equiv {[\rm{Fe/H}]}$. We express $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}})$ using two log-likelihoods $$P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}) = P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_m, {\ensuremath{\textbf{X}}}_p) = e^{-L_{iso}-L_{sed}}.$$

Here, $L_{iso}$ is a measure of the separation between observed spectral parameters [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} and those predicted by model parameters ${\ensuremath{\textbf{X}}}_m$. Assuming Gaussian uncertainties in ${\ensuremath{\textbf{O}}}$, we can write $$\begin{aligned}
 L_{iso} &= \sum_{i \in ({\ensuremath{T_{\rm{eff}}}}, \log g, {[\rm{Fe/H}]})} \frac{(O'_i - O_i)^2}{2 \sigma^2_{O, i}} \nonumber \\
         &= \sum_{i \in ({\ensuremath{T_{\rm{eff}}}}, \log g, {[\rm{Fe/H}]})} \frac{(\mathcal{I}_i({\ensuremath{\textbf{X}}}) - O_i)^2}{2 \sigma^2_{O, i}}\label{eq:liso}.\end{aligned}$$

We use for the log-likelihood as in most cases spectroscopic surveys do not provide information about the correlations of the uncertainties on the different parameters. When this information or the PDFs of the spectroscopic parameters are known, this information can be included in $L_{iso}$.

$L_{sed}$ is a measure of similarity of the observed spectral energy distribution (SED) (set of $m_\lambda$ obtained from photometric surveys) and that predicted by isochrone model for ${\ensuremath{\textbf{X}}}$. Visible magnitudes $m_\lambda$ come from 2MASS and AllWISE. These magnitudes are related to the absolute magnitudes $M_\lambda$ in ${\ensuremath{\textbf{O}}}'$ by the following relation: $$m_\lambda = \mu_d + M_\lambda + A_\lambda = \mu_d + M_\lambda + C_\lambda A_K,$$ where the extinction in band $\lambda$ is defined as $A_\lambda = \frac{R_\lambda}{R_K} A_K = C_\lambda A_K$, with the extinction coefficients $R_\lambda$ taken from [@Extinction] and summarised in . Therefore to compare observed visible and model absolute magnitudes we need to know the distance modulus $\mu_d$ and the extinction $A_K$ in the direction of the star. The latter can be obtained from extinction maps or by comparing magnitudes in different bands. We chose the second method and calculated the extinction value for each star using photometric infrared data. This allowed us to take into account variations of extinction that might occur on scales smaller than the typical map resolution. We were also able to calculate extinction for any position on the sky and any distance, whereas a detailed three-dimensional extinction maps are created only for the nearest kiloparsec [@2012AstL...38...87G] or for the Galactic plane [@2014MNRAS.443.2907S], which is not sufficient for our purpose. A more recent three-dimensional map by @2015ApJ...810...25G covers a large fraction of the sky, but a full-sky three-dimensional extinction map is still not available.

We use 2MASS and AllWISE data as infrared bands are much less affected by interstellar extinction. Extinction in optical bands is generally higher than in the infrared and can have higher spectral variations between different points on the sky [see a discussion in @2011ApJ...739...25M]. By using infrared data alone we increased the precision of our distance estimates at a cost of decreasing the precision for the extinction estimate. As far as we focus on distances, this seems a fair trade.

   Band   Value of $R_\lambda$   Value of $C_\lambda$
  ------ ---------------------- ----------------------
    J            0.720                   2.35
    H            0.460                   1.5
    K            0.306                    1
    W1           0.180                   0.59
    W2           0.160                   0.52

  : Values of the extinction coefficients $R_\lambda$ and $C_\lambda$ used for 2MASS and AllWISE photometry. Values were taken from @Extinction[]{data-label="tbl:rlambda"}

For $L_{sed}$ we use the following expression: $$L_{sed} = \sum_\lambda \frac{(m_\lambda - M_\lambda - C_\lambda A_K - \mu_d)^2}{2 \sigma_{m_\lambda}^2} - V_{corr}(\mu_d),$$ where the summation is carried out over all bands, for which photometry is available for a given star and $V_{corr}(\mu_d)$ is a volume correction. We introduce volume correction to compensate for the fact that with a given field of view we probe larger space volume at larger distances than at smaller distances. See a discussion of the effect of volume correction in . Using the relation between distance modulus and distance ($d = 10^{0.2\mu_d + 1}$), we can write $$V_{corr}(\mu_d) = \log d^2 = \log 10^{2 (0.2 \mu_d + 1)} = (0.4 \mu_d + 2) \log 10.$$

We use both $L_{iso}$ and $L_{sed}$ in $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}})$. Therefore on top of the spectroscopic parameters we utilise additional information, namely, the SED of the star. The drawback is that this also brings in the systematic errors of both stellar spectra modelling in PARSEC and possible large errors in photometry in the case of a mismatch between spectroscopic and photometric surveys.

Probability distribution functions {#sec:pdf}
----------------------------------

In order to get the PDF in each parameter, we need to marginalise a multi-dimensional PDF of output parameters, $P({\ensuremath{\textbf{X}}}|{\ensuremath{\textbf{O}}})$, defined in , over all other parameters. For example, for log(age) $\tau$ one has to calculate $$P(\tau) = \iiiint P({\ensuremath{\textbf{X}}}) P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}) dM d{[\rm{Fe/H}]}d{\ensuremath{\textbf{X}}}_p,$$ with the integral taken over the whole parameter space. In practice, we have a discrete sample of models from isochrones. So we can replace $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}})$ with the sum of delta functions $$\
   P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}) = \sum_j P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_p) {\delta_{\tau,j}}{\delta_{M,j}}{\delta_{{[\rm{Fe/H}]},j}}w_j,\label{eq:pox}$$ where we write for brevity ${\delta_{\tau,j}}= \delta(\tau_j - \tau)$, ${\delta_{{[\rm{Fe/H}]},j}}= \delta({[\rm{Fe/H}]}_j - {[\rm{Fe/H}]})$, ${\delta_{M,j}}= \delta(M_j - M)$. Here we have to use volumes represented by each model $w_j$ from , which reflect the volume of the parameter space represented by the model. The summation is carried out over all models and ${\ensuremath{\textbf{X}}}_{m,j} = (\tau_j, M_j, {[\rm{Fe/H}]}_j)$ is a vector of parameters of the model $j$. Therefore we can write, using equations \[eq:prior\] and \[eq:pox\], $$\begin{aligned}
 P(\tau) = \sum_j \iiiint & F_{IMF}(M) P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_p) {\delta_{\tau,j}}{\delta_{M,j}}{\delta_{{[\rm{Fe/H}]},j}}\nonumber \\ 
          & \times w_j d M\,d{[\rm{Fe/H}]}\,d{\ensuremath{\textbf{X}}}_p, \label{eq:p_tau}\end{aligned}$$ with again the summation carried out over all models. We need to keep integration over ${\ensuremath{\textbf{X}}}_p$, because both $\mu_d$ and $A_K$ are continuous values.

We can make two important simplifications here. First, there is no need to sum over all models because for most of them $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}})$ is very small. We chose a threshold of $L_{iso} < 8$. In this case [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} are within 4 sigma uncertainties from observed values. We verified that increasing the threshold from 8 to 12.5 (or going from a combined 4 sigma to 5 sigma uncertainty threshold) leads to marginal changes in the output; parameter estimates change by more than 3% for only less than 2 percent of the stars. Because models are selected from three-dimensional space, this comes at a cost of doubling the number of models to be considered. A decreasing the likelihood threshold however leads to more significant changes in the resulting parameters.

Second, $L_{sed}$ is a quadratic form in $\mu_d$ and $A_K$. Therefore, for a given model $j$, $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{p,j}) = \exp(-L_{sed})$ is a bivariate Gaussian distribution. The location of the maximum of this distribution can be found by solving the system of equations as follows: $$\large{
 \begin{cases}
   {\ensuremath{\frac{\partial {L_{sed}}}{\partial {\mu_d}}}} &= 0 \\
   {\ensuremath{\frac{\partial {L_{sed}}}{\partial {A_K}}}} &= 0
 \end{cases}}.$$ This is equivalent to the following set of equations: $$\label{eq:old_system}
\large{
\begin{cases}
  \sum_\lambda {\ensuremath{\frac{1}{\sigma_{m_\lambda}^2}}}\mu_d + \sum_\lambda {\ensuremath{\frac{C_\lambda}{\sigma_{m_\lambda}^2}}} A_K &= \sum_\lambda {\ensuremath{\frac{m_\lambda - M_\lambda}{\sigma_{m_\lambda}^2}}} - 0.4 \log 10 \\
  \sum_\lambda {\ensuremath{\frac{C_\lambda}{\sigma_{m_\lambda}^2}}} \mu_d + \sum_\lambda {\ensuremath{\frac{C_\lambda^2}{\sigma_{m_\lambda}^2}}} A_K &= \sum_\lambda {\ensuremath{\frac{C_\lambda(m_\lambda - M_\lambda)}{\sigma_{m_\lambda}^2}}},
\end{cases}}$$ which is solved for $\mu_d$ and $A_K$. If $A_K < 0$, which is not physical, or if only one magnitude is available we set $A_K = 0$ and obtained $\mu_d$ from the first part of . By doing so we increase $L_{sed}$ for a given model, which decreases the contribution of this model to the PDFs. In some cases $A_K$ is zero for all models for a star. This indicates either that the extinction for this star is statistically indistinguishable from zero or that there is a mismatch between spectral and photometric data, which results in using visible magnitudes from a different star. In the first case we still produce a reliable distance estimate, while in the second case the obtained $L_{sed}$ is high and the quality of the result is low (see Section \[sec:p\_best\_p\_sed\]).

The covariance matrix of $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{p,j})$ is exactly the inverse Hessian matrix $H$ of $L_{sed}$ , i.e. $$\large{
  H = 
    \begin{vmatrix}
     \frac{\partial^2 L_{sed}}{\partial \mu_d^2}            & \frac{\partial^2 L_{sed}}{\partial \mu_d \partial A_K} \\
     \frac{\partial^2 L_{sed}}{\partial \mu_d \partial A_K} & \frac{\partial^2 L_{sed}}{\partial A_K^2}
    \end{vmatrix} =
    \begin{vmatrix}
     \sum_\lambda{\ensuremath{\frac{1}{\sigma_{m_\lambda}^2}}}         & \sum_\lambda{\ensuremath{\frac{C_\lambda}{\sigma_{m_\lambda}^2}}} \\
     \sum_\lambda{\ensuremath{\frac{C_\lambda}{\sigma_{m_\lambda}^2}}} & \sum_\lambda{\ensuremath{\frac{C_\lambda^2}{\sigma_{m_\lambda}^2}}}
    \end{vmatrix}
    }.$$ It is important to note that $H$ depends only on $C_\lambda$, which are constants and photometric uncertainties $\sigma_{m_\lambda}$, thus $H$ has a constant value for a given star.

The width of the $L_{sed}$ distribution in $\mu_d$ for a given model is thus $\Delta_{\mu_d} = \sqrt{H^{-1}_{0,0}}$, which is of the order of $\sigma_m$ and is about an order of magnitude smaller than a typical uncertainties in $\mu_d$ that we derive. This is not true for the extinction, but we are not focused on derivation of high-quality extinctions. Moreover, tests show that the error we bring into mean extinction values by this simplification is small. Furthermore there is an obvious correlation between $\mu_d$ and $A_K$, but we ignore it here. This is justified because $\Delta_{\mu_d}$ is approximately one order of magnitude smaller than a typical uncertainties in $\mu_d$ for a star, so a correlation between derived $\mu_d$ and $A_K$ in a two-dimensional PDF $P(\mu_d, A_K)$ for a given star is dominated by scatter in $\mu_d$ and $A_K$ for models used to build the PDF, rather than by correlation of $\mu_d$ and $A_K$ for each model.

As far as $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_p)$ is a bivariate Gaussian function, the integral over $d{\ensuremath{\textbf{X}}}_p$ in is exactly the value of $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_p)$ at the location of its maximum, derived in . So we can replace the integral in with a delta function $$\begin{aligned}
 P(\tau) &= \sum_j \iiiint F_{IMF}(M) P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}) {\delta_{\tau,j}}{\delta_{M,j}}{\delta_{{[\rm{Fe/H}]},j}}\nonumber \\ 
        & \times  \delta({\ensuremath{\textbf{X}}}_{p,j} - {\ensuremath{\textbf{X}}}_p) w_j d M d {[\rm{Fe/H}]}d {\ensuremath{\textbf{X}}}_p \label{eq:pdf} \\ 
        & = \sum_j P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_{p,j}) F_{IMF}(M_j) \delta(\tau_j - \tau) w_j, \nonumber \end{aligned}$$ where ${\ensuremath{\textbf{X}}}_{p,j}$ is the solution of for model $j$. A similar equation can be written for $P(M)$.

For $\mu_d$ and $A_K$ each model contributes to the PDF a Gaussian summand with a width of $\Delta_{\mu_d}$ and $\Delta_{A_K} = \sqrt{H^{-1}_{1,1}}$, respectively. We can correct for using delta function in place of a bivariate Gaussian for $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_p)$ by adding a Gaussian smoothing multiplier with the corresponding width

$$\begin{aligned}
  P(\mu_d) &= \sum_j P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_{p,j}) F_{IMF}(M_j) w_j e^{-\frac{(\mu_{d,j} - \mu_d)^2}{2 \Delta_{\mu_d}^2}} \\
  P(A_K)   &= \sum_j P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_{p,j}) F_{IMF}(M_j) w_j e^{-\frac{(A_{K,j} - A_K)^2}{2 \Delta_{A_K}^2}}.\end{aligned}$$

\[eq:pdf\_mu\]

Quality of model fit to the data {#sec:p_best_p_sed}
--------------------------------

It is important to quantify how well a set of models represents the observed parameters of a star. To accomplish this, we used the $\chi^2$ distribution to get the $p$ values from our log-likelihoods. We characterise our model quality by the $p$ value corresponding to the value of $\chi^2 = L_{iso}+L'_{sed}$ for the model with the highest $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_{p,j})$. Here we use $L'_{sed} = L_{sed} + V_{corr}(\mu_d)$. We added $V_{corr}(\mu_d)$, thus removing the volume correction. This is necessary because $V_{corr}(\mu_d)$ adds a non-$\chi^2$ summand, that depends on $\mu_d$. Thus, the $\chi^2$ value used to compute the $p$ value is not the lowest possible value, but that corresponding to the model with the highest $P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_{m,j}, {\ensuremath{\textbf{X}}}_{p,j})$, thus the value that is closest to observables. The number of degrees of freedom in this case equals the number of observables, which is the number of available magnitudes plus three (for the temperature, surface gravity, and metallicity dimensions). This $p$ value is designated as $p_{best}$. Low values of $p_{best}$ can be caused either by observables falling out of the range covered by the models or by inconsistencies between observed stellar parameters and the observed SED. We flagged data with $p_{best} < 0.1$ (see Section \[sec:quality\]).

In addition to $p_{best}$, we quantify how good our models are at representing the observed SED. We use the same model used for $p_{best}$ and report as $p_{sed}$ the $p$ value corresponding to the chi-square value $\chi^2 = -L'_{sed}$. The number of degrees of freedom in this case is equal to the number of available magnitudes. Low values of $p_{sed}$ might be caused, for example, by a mismatch between spectral and photometric data, which results in using visible magnitudes from a different star. Another possible reason is a problematic spectral parameter estimation, which makes ${\ensuremath{T_{\rm{eff}}}}$ inconsistent with the SED from photometry. We flagged data with $p_{sed} < 0.1$ (see Section \[sec:quality\]).

Calculating final values {#sec:final_values}
------------------------

From we can define a weight for each model $j$ as $$\label{eq:model_weight}
  W_j = P({\ensuremath{\textbf{O}}}|{\ensuremath{\textbf{X}}}_j)F_{IMF}(M_j) w_j = e^{-L_{iso}-L_{sed}} w_j F_{IMF}(M_j).$$

The PDF in each parameter can thus be calculated as a distribution of parameters for models, with weights $W_j$. For the PDF in $\mu_d$ and $A_K$ we smooth histograms with Gaussian kernel of width $\Delta_{\mu_d}$ or $\Delta_A$, respectively (see ).

### Determination of unimodal sub-PDFs

For each combination of stellar mass, age, and metallicity, PARSEC models provide a single combination of effective temperature and surface gravity. The transition from the effective temperature, surface gravity, and metallicity to stellar mass and age is however non-unique. For a given combination of [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} with their uncertainties it is possible to find more than one corresponding model with different combinations of age and mass. For example, red clump stars and red giant stars can have similar spectral parameters [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{}, but different ages, masses, and internal structures. Therefore, distributions in ages, masses, and absolute magnitudes (and thus distances) are in some cases different from Gaussian. This is illustrated in , where we show typical PDFs in log(age), mass, and distance modulus for two stars. Some of the distributions shown are multimodal with two or more peaks. Reporting mean values and standard deviations do not capture that properly. Mode values, as used by [@2014MNRAS.445.2758R], give the value of the highest peak only. Full distributions can be provided, but they are often considered too complex for further analysis. We suggest an intermediate solution: split PDFs into several USPDFs with each of these described by a unimodal function, assuming that this represents a group of models with similar stellar structure.

We split all models in three evolutionary stages, described in Section \[sec:iso\], i.e. pre-core-helium burning, core-helium burning, and post-core-helium burning stars (plotted in with red, blue, and yellow, respectively). Splitting our results this way has a benefit in case of overlapping isochrones from different evolutionary stages for a given ${\ensuremath{T_{\rm{eff}}}}, \log g, {[\rm{Fe/H}]}$ combination. Without this split, we would combine values for substantially different evolutionary stages that are not physical.

Splitting in evolutionary stages is not enough, as due to curvature of isochrones we can have sub-groups of models within one stage that are physically different. A good example is stage I, which contains both main-sequence and giant stars. This results in multimodal distributions of models in space of stellar parameters. An example of such a situation is given in (see their Figures 1 and 2). To split a multimodal distribution into several unimodal distributions we applied an additional empirically derived routine to our PDFs, which is described in . This routine works in the vast majority of cases. Those cases in which our splitting of the PDFs breaks down typically have too few models to produce a histogram (such cases are given the quality flag “N”, see Section \[sec:quality\]).

The overall weight $V_m$ for a USPDF $m$ is defined as a ratio of the sum of weights of models within the USPDF and the sum of weights of all models $$V_m = \frac{\sum_{j \in m}W_j}{\sum W_j}.$$

![image](PDF_example.png){width="90.00000%"}

### Output values {#sec:outvalues}

We provide output for each USPDF such that it is possible to reproduce the PDF in each parameter we are interested in mass ${\ensuremath{M}}$, logarithm of age $\tau$, distance modulus $\mu_d$, distance $d$, parallax $\pi$, and extinction $A_K$. Even for a unimodal distribution the mean, median, or mode might be a poor estimate for the value of interest in case the distribution is non-symmetric. Values of mode and median might produce less bias but should be used with care as they are not proper moments of the PDF and many statistical methods rely on moments. To provide a simple representation of each USPDF (for each parameter), we fit them with a Gaussian, a skewed Gaussian, a truncated Gaussian, a modified truncated exponential distribution (MTED) and a truncated [Student’s t-distribution]{} (see definitions of these functions in the Appendix \[app:functions\]). For the truncated functions the upper and lower truncation limits were not fitted, but were set to upper and lower limits of the considered USPDF. We selected the function that gives the lowest symmetric Kullback–Leibler divergence value, which is the measure of the information gain $$D_{KL} = \sum_i H_i \log \frac{H_i}{F_i},$$ where $H_i$ are histogram counts and $F_i$ are fitted function values.

Truncated functions were taken because we have a natural upper limit on the age of the star, which is the age of the Universe and therefore there is a lower limit on the mass of a star that left the main sequence, which is approximately $0.7 {\ensuremath{\rm{M}_\odot}}$ if we consider the full range of metallicities. This limit produces sharp cut-offs in histograms, making truncated functions a natural choice.

A modified truncated exponential distribution in log-age is equivalent to a flat distribution in ages, thus such a fit indicates that age is poorly constrained. Such PDFs are typical for main-sequence stars, where, as expected, it is hard to constrain age from spectrophotometric data.

In rare (less than $1\%$) cases in which the fit did not converge for all five fitting functions. This is primarily caused by long tails in the distributions or insufficient data for a proper fit. In this case we reported only mean and standard deviation of the data as fit parameters.

An important property of our result is that values of distance, mass, and log(age) for models are strongly correlated. We used the fact that distance modulus, log(age), and logarithm of mass have a nearly linear correlation within every USPDF in most cases. We report coefficients (slope $a$ and intercept $b$) of a weighted linear fit and a scatter around it for three relations for each USPDF: $\tau = a_1 \mu_d + b_1$ (distance modulus versus logarithm of age; red lines on left panels of ), $\mu_d = a_2 \tau + b_2$ (logarithm of age versus distance modulus; blue lines on left panels of ), and $M = 10^{a_3 \mu_d + b_3}$ (distance modulus versus logarithm of mass; red lines on right panels of ). An illustration of correlations is given in , where we show the two-dimensional PDFs for several stars and our fits to them. From the right-hand side panels it is clear that the relation of distance modulus and logarithm of mass is close to linear; the mass is plotted in linear scale, thus our fits are not straight lines. The relation of distance modulus and log(age) is weak for the main-sequence stars and lower giant branch stars. The shape of two-dimensional PDF can be quite complex, like in panels a and c of . For these cases the scatter is large and our relations does not work. For giant stars these correlations are much more pronounced, as can be seen in panels e and g of . Correlations between distance modulus, log(age), and log(mass) can be used, for example, if the new distance estimate $\mu'_d$ is obtained from some external source (like Gaia) for a star in our catalogue. We verified that our estimates for mass and log(age) can then be corrected for by the value of the slope times the difference between the externally determined distance modulus and our estimate as follows:  $$\begin{aligned}
 \tau' &=& \tau + a_1 (\mu'_d - \mu_d) \\
 M' &=& M \times 10^{a_3 (\mu'_d - \mu_d)}.\end{aligned}$$ In the future work we will show applications of these relations, which are beyond the scope of this work.

![image](TwoD_PDF.png){width="80.00000%"}

Summing up, we chose to provide for each USPDF $m$ and each stellar parameter designated as $Y_{i, m}$, where $Y_i \in ({\ensuremath{M}}, \tau, \mu_d, d, \pi, A_K)$ the following quantities:

-   A weighted mean (catalogue column suffix `_mean`) of model values $Y_{i,j}$ for all models, $$Y_{i,m} = \frac{\sum_{j \in m} W_j Y_{i,j}}{\sum_{j \in m}W_j},$$ where the summation is carried out over all models within USPDF $m.$

-   A weighted standard deviation (suffix `_err`), $$\sigma_{Y_{i, m}} = \sqrt{\frac{\sum_{j \in m} W_j (Y_{i,j} - Y_{i, m})^2}{\sum_{j \in m}W_j}}
    .$$

-   A mode of the USPDF (suffix `_mode`).

-   A weighted median value (suffix `_median`).

-   A character indicating which fitting function was chosen: &lt;&lt;G&gt;&gt; for Gaussian, &lt;&lt;S&gt;&gt; for skewed Gaussian, &lt;&lt;T&gt;&gt; for truncated Gaussian, &lt;&lt;L&gt;&gt; for MTED, &lt;&lt;P&gt;&gt; for truncated [Student’s t-distribution]{}, &lt;&lt;E&gt;&gt; if the fit failed for all five functions, and &lt;&lt;N&gt;&gt; if there was not enough data for a fit (suffix `_fit`).

-   Parameters for a chosen fit (suffix `_par`). The first two values are location and shape for the chosen best fitting function. For a Gaussian function, by definition, location parameter is equal to the mean value and shape parameter to the variance. If the chosen function is a skewed Gaussian then the third value is the skew value. If the chosen function is a truncated Gaussian or MTED, then third and fourth values are lower and upper limits. If the chosen function is [Student’s t-distribution]{} then the third value is the number of degrees of freedom and the fourth and fifth values are lower and upper limits.

-   One- and three- sigma confidence intervals. These are defined as a region containing 68.27% (for one-sigma uncertainties) or 99.73% (for three-sigma uncertainties) of the USPDF, positioned to minimise its span. By construction, such a confidence interval always includes the mode value. For a Gaussian distribution this is equivalent to a range centred on the mean value with width of one- or three- standard deviations. (suffixes `_low_1sigma, _up_1sigma, _low_3sigma, _up_3sigma`).

We report all USPDFs with weights $V_m$ higher than $0.03$. Integer priority values starting from 0 were assigned to each USPDF in order of decreasing weights $V_m$. We list all measures provided for our catalogue in .

In we show examples of different USPDFs and fits to them. For the first star (left column) three different evolutionary stages are possible. For the evolutionary stage I a truncated Gaussian is required to fit log(age) distribution and for the evolutionary stage II a skewed Gaussian is needed to fit distribution in mass and distance modulus. For the second star (right column) mainly stage II is possible, but the distribution for this stage can be split in two parts. We need a truncated [Student’s t-distribution]{} to fit the histogram for the higher age solution. The small USPDF visible for mass around $1 {\ensuremath{\rm{M}_\odot}}$ and log(age) of $9.3$ for stage I was excluded because its weight $V_m$ is below the accepted $0.03$ threshold.

[lcp[4cm]{}]{}\
Column name & Units & Description\
id & & Unique ID of the star from the input data\
stage & & Stage number (I, II or III)\
uspdf\_priority & & Priority order of a given USPDF (starting from 0)\
uspdf\_weight & & Weight $V_m$ of a given USPDF\
total\_uspdfs & & Number of USPDF with $V_m > 0.03$\
p\_best & & Probability for a best-fitting model (see Section \[sec:p\_best\_p\_sed\])\
p\_sed & & $p$-value from $\chi^2$ SED fit (see Section \[sec:p\_best\_p\_sed\])\
quality & & Quality flag (see Section \[sec:quality\])\
distance\_modulus$\dagger$ & mag & Distance modulus $\mu_d$\
distance$\dagger$ & kpc & Distance $d$\
parallax$\dagger$ & mas & Parallax $\pi$\
extinction$\dagger$ & mag & Extinction $A_K$ in 2MASS K-band\
mass$\dagger$ & ${\ensuremath{\rm{M}_\odot}}$ & Mass\
age$\dagger$ & log(yr) & Logarithm of age $\tau$\
\
dm\_age\_slope & & Slope of the relation\
dm\_age\_intercept & & Intercept of the relation\
dm\_age\_scatter & & Scatter of the relation\
\
age\_dm\_slope & & Slope of the relation\
age\_dm\_intercept & & Intercept of the relation\
age\_dm\_scatter & & Scatter of the relation\
\
dm\_mass\_slope & & Slope of the relation\
dm\_mass\_intercept & & Intercept of the relation\
dm\_mass\_scatter & & Scatter of the relation\

Role of age and extinction cuts {#sec:cuts}
-------------------------------

We chose to impose hard cuts on log(age) $\tau \leq 10.13$ and extinction $A_K \geq 0$. This is not an obvious choice, so we justify it here.

We first consider a star for which two equally good solutions are possible: one with $\tau = 8$ and one with $\tau = 10.7$, where all other parameters are equal (see ). If we do not use the hard cut on ages, both solutions are reported with good quality flags and equal weights $W_{1,2} = 0.5$ (blue lines in ). The unphysical age value for the second solution might be used as a sign of a problem either with data or with models. It is therefore likely that this solution or even both solutions for this star will be dropped from further study. If we, on the other hand, use the cut in log(age) $\tau \leq 10.13$, we will keep both solutions, but their weights will change. Only the tail of the USPDF for the second solution will be retained. Because the sum of USPDF weight still has to be unity, the weight of the first solution will increase. We get for this example $W_1 = 0.89$ and $W_2 = 0.11$ (red lines in ). As a result, we get a “realistic” first solution with $\tau = 8$ and retain a part of the second solution. For the second solution, and, in general, for all cases when part of the USPDF is cut away, the mean of the USPDF is a poor measure of log(age) and it is biased towards lower values. But in such cases the USPDF is fitted with either a MTED, a truncated Gaussian or a truncated [Student’s t-distribution]{}. So instead of a solution with high weight and correct, but unphysical, mean log(age), we get a solution with lower weight and biased value of the mean with a proper fitting function.

![Sketch of PDF in log(age) for a star with two possible ages without (blue lines) and with (red lines) hard upper limit on log(age). See text for details.[]{data-label="fig:cut"}](age_cut_example.png){width="48.00000%"}

We now consider the case when only one solution is available for a given star, which is $\tau = 10.7$. We can use such values of $\tau$ as an indication of a problem in spectroscopic parameters, photometry, or in isochrones. If the cut in log(age) $\tau \leq 10.13$ is applied, there are several possibilities. In some cases the PDF in log(age) follows an exponential distribution, which means that the age is poorly constrained for a given star and extending the range of possible ages does not improve this.

An other possibility is that models that have $\tau \leq 10.13$ represent observables and thus have $p_{best}$ close to unity; see . This means that we still have a reliable log(age) PDF for $\tau \leq 10.13$, but the mean, mode, and median values might be biased. Without the age cut, the mean, mode, and median log(age) values will be above $\tau = 10.13$, and such solution will likely be excluded from further analysis, despite the fact that a fraction of it is reliable.

In yet another case the value for a best-fitting model probability $p_{best}$ will be small, which will indicate potential problems in either the data or with the models. Such cases will be flagged as unreliable with and without age cut.

The same arguments as discussed above are applicable to the cut in extinction. Moreover, a cut in extinction has minor influence on the result, as extinction values are typically very small, i.e. about 10 times smaller than the derived uncertainty in the distance modulus. We verified that negative extinctions typically arise for faint stars, for which photometric uncertainties are large. In the vast majority of cases for which the derived value of extinction is negative, the value is still consistent with zero within uncertainties.

Tests: Comparison with other measurements {#sec:test}
=========================================

We tested our UniDAM tool in two ways. We first applied it to mock surveys (see Section \[sec:data\_mock\]). By doing that we checked the accuracy and performance of the tool and explored the effect of random perturbations added to input values. Then we proceeded with comparing our parameter measurements for real stars with those obtained by other groups and presented in the literature. The aim of these exercises was to check the quality of our estimates compared to results obtained by the consortia of the different surveys and the sensitivity of our results to priors.

Mock survey {#mock-survey}
-----------

We ran our UniDAM tool on all four mock surveys, described in Section \[sec:data\_mock\]. Knowing the input values allowed us to evaluate which of the reported measures, that is mean, median, or mode, is the best proxy. In agreement with we find that the mode is less biased than the mean or median, but produces slightly more outliers.

Mean, mode, and median values show similar qualitative patterns, so we used only mean output values of the highest weight USPDF for comparison. We compared derived mean values $X$ with input values $X_0$. We considered several measures of interest as follows:

-   Median fractional uncertainty of derived value ${\ensuremath{\mathcal{M}\!\left( \frac{\sigma_X}{X} \right)}}$ ; this is an internal precision measure.

-   Median relative deviation (median bias) of derived value ${\ensuremath{\mathcal{M}\!\left( \frac{\Delta X}{X} \right)}} = {\ensuremath{\mathcal{M}\!\left( \frac{X_0-X}{X} \right)}}$; this shows whether the values that we calculate are systematically offset with respect to the input.

-   Median absolute relative deviation of derived value ${\ensuremath{\rm{M.A.D.}}}= {\ensuremath{\mathcal{M}\!\left( \left|\frac{\Delta X}{X} - {\ensuremath{\mathcal{M}\!\left( \frac{\Delta X}{X} \right)}}\right| \right)}}$; this shows how scattered our derived values are with respect to input. Median absolute deviation is a much better estimate of scatter than standard deviation in the presence of outliers [@Leys2013].

-   Outlier fraction rate $O$; this is the fraction of stars for which the input value $X_0$ lies outside the three-sigma confidence interval. We use two values: $O_{best}$ is calculated using only highest weight USPDF, whereas $O_{all}$ is calculated using all USPDFs (i.e. $X_0$ lies outside the three-sigma confidence intervals of all reported USPDFs).

Measures for all four mock surveys are listed in . For a normally distributed random variable, median absolute deviation $\sigma_{MAD}$ relates to standard deviation $\sigma$ as $\sigma \approx 1.4826\,\sigma_{MAD}$, therefore we expected median absolute relative deviation to be approximately equal to two-thirds of the median fractional uncertainty. As can be seen from the second and fourth columns of , this is the case for our data, which means that the distribution of the offsets is close to normal.

Outliers are expected for two reasons. First, a model with the “correct” (i.e. input) values might not belong to the highest weight USPDF. This is revealed by $O_{best}$. We detected that in about one to seven percent of the cases input parameters are better recovered with USPDF that has second (or even the third) priority. This happens primarily in the upper part of the giant branch, where isochrone overlap is highest. This is inherent to the method; we seek a model that most likely represents the data. If the mock star was taken to be in some short phase of its evolution (thus having low model weight $w_j$), chances are high that we assign a highest weight USPDF not to this phase but to a much longer phase, which has similar observables. Second, because the three-sigma range includes by definition $99.7\%$ of the data, we expect at least a fraction of $0.003$ of stars for which no USPDF recovers the “correct” values within three-sigma confidence intervals (i.e. $O_{all} \gtrsim 0.003$) due to our random perturbations added to input values. In fact, this fraction is slightly higher, of the order of $0.01-0.02$. We checked that this is caused by a combination of both the perturbations of input values and models selected for the mock sample that is in a very short phase of evolution. In the latter case USPDFs might be pulled away from the “correct” solution by nearby models with higher weights. Another possible case in which there might be no “correct” solution found is when the mock star is located on the edge of the parameter space covered by models.

In cases where perturbations were added, the values of the bias, median absolute relative deviation, and outlier fractions increase. This increase is most prominent in the outlier fractions; this is caused by the fact that sometimes even a small perturbation of input parameters might change the priorities of USPDFs, thus changing the parameters of the highest weight USPDF by a large value.

[lrrrp[0.9cm]{}p[0.9cm]{}]{} Parameter & ${\ensuremath{\mathcal{M}\!\left( \frac{\sigma_X}{X} \right)}}$ & ${\ensuremath{\mathcal{M}\!\left( \frac{\Delta X}{X} \right)}}$ & ${\ensuremath{\rm{M.A.D.}}}$ & $O_{best}$ & $O_{all}$\
\
mass & 0.17 & -0.02 & 0.10 & 0.06 & 0.01\
age & 0.03 & 0.01 & 0.02 & 0.06 & 0.00\
distance & 0.13 & -0.02 & 0.08 & 0.06 & 0.00\
\
mass & 0.17 & -0.00 & 0.10 & 0.04 & 0.01\
age & 0.03 & 0.00 & 0.02 & 0.04 & 0.00\
distance & 0.13 & 0.01 & 0.08 & 0.03 & 0.00\
\
mass & 0.17 & -0.00 & 0.12 & 0.06 & 0.02\
age & 0.03 & 0.00 & 0.02 & 0.06 & 0.01\
distance & 0.13 & 0.00 & 0.11 & 0.05 & 0.01\
\
mass & 0.17 & -0.01 & 0.12 & 0.06 & 0.02\
age & 0.03 & 0.01 & 0.02 & 0.06 & 0.01\
distance & 0.13 & 0.00 & 0.11 & 0.06 & 0.01\

We also tested if distance modulus or parallax provide a better estimate of distance than distance value itself. We find that this is not the case, and all three estimates give very similar precision, with distance itself showing a slightly smaller fraction of outliers. This contradicts the statement of [@2014MNRAS.437..351B] that “the most reliable distance indicator is the expectation of parallax”. This might be because [@2014MNRAS.437..351B] compared their derived values with parallaxes from *HIPPARCOS*, and comparing parallaxes with parallaxes is likely less biased. We nevertheless provide all three estimates for each star in the output catalogue.

Literature {#sec:compare}
----------

We compared our results with values available in the literature. Results of this comparison are shown in and in , and are discussed here. The aim of this comparison is to show that our results are consistent with previous studies. In most cases these previous studies were based on similar data and methods. So the differences that appear are primarily due to different models used and differences in details of the method implementation. The exceptions are GCS parallaxes that are coming from *HIPPARCOS* and APOKASC distances, derived with asteroseismic values of $\log g$, which are more precise than spectroscopic values. In both cases our results are consistent with published data.

We verified that our extinction estimates are consistent with those provided in surveys. In fact, the differences between our extinction estimates and those in surveys are comparable to differences between extinctions derived with different methods for the same survey, for example, in the LAMOST-GAC data [@2017arXiv170105409X]. We do not provide a detailed analysis here, as the derivation of precise extinctions is beyond the scope of this work.

![image](Compare_input.png){height="0.95\textheight"}

[ccd[1.2]{}d[1.2]{}d[1.2]{}c]{} Survey & Value & [ ]{} & [ ]{} & [ ]{} & $O_{best}$\
GCS &$\pi$ & 0.13 & -0.065 & 0.03 & 0.03\
&${\ensuremath{M}}$ & 0.064 & 0.024 & 0.024 & 0.02\
&$\tau$ & 0.02 & -0.000 & 0.005 & 0.05\
APOKASC &$d$ & 0.11 & -0.017 & 0.05 & 0.15\
RAVE (1) & $\mu_{d, \textrm{Z}}$ & 0.044 & -0.011 & 0.050 & 0.20\
RAVE (2) &$\mu_{d, \textrm{B}}$ & 0.044 & -0.03 & 0.055 & 0.25\
&${\ensuremath{M}}$ & 0.15 & -0.016 & 0.12 & 0.17\
&$\tau$ & 0.027 & 0.009 & 0.018 & 0.13\
LAMOST-GAC &$d_{\textrm{emp}}$ & 0.20 & 0.1 & 0.08 & 0.03\
(main sample)&$d_{\textrm{iso}}$ & 0.20 & 0.02 & 0.063 & 0.05\

### GCS parallaxes, masses, and ages

The GCS [@2011AA...530A.138C and references therein] mainly covers nearby main-sequence stars. The big advantage is that for most of them parallaxes were measured by *HIPPARCOS*. The three top rows of and show differences between parallaxes, masses, and log(age)s from GCS and our estimate. We detected a small bias in parallaxes and masses but a negligible bias in log(age)s. Median absolute deviations are three times lower than fractional uncertainties, which means that our method is consistent with GCS results.

### Distances of APOKASC red giants {#sec:compare_apokasc}

[@2014MNRAS.445.2758R] have determined distances for about 2000 red giant stars from the APOKASC sample. Our distances are less precise than those of [@2014MNRAS.445.2758R] because we do not include asteroseismic data. This test therefore helps us estimate the quality of distance estimations we make for the whole APOGEE sample, as stellar parameters in APOGEE DR13 were calibrated with the use of asteroseismic data from APOKASC. We predicted slightly larger distances ($-0.017$ relative offset), but both bias and scatter are well below the mean fractional uncertainty ($0.11$) of our derived distances. The origin of the bias is likely the difference in how the distance value is calculated when distance PDF is multimodal. This is supported by the fact that for stars with unimodal PDFs we got a relative distance bias of less than $0.0025$.

### RAVE stars {#sec:compare_rave}

We ran the UniDAM tool on RAVE DR4 data [@2013AJ....146..134K] and compared these findings with the results of for distance moduli and @2014MNRAS.437..351B for distance moduli, log(age)s, and masses. We used DR4 data here, as these were used by and @2014MNRAS.437..351B. The relative difference between our distance estimates and $\mu_{d, \textrm{Z}}$ by is around $-0.01$. As compared to the @2014MNRAS.437..351B results ($\mu_{d, \textrm{B}}$), our distance moduli have a relative difference of $-0.03$. The median absolute deviations are large in both cases and are comparable to or larger than the mean relative uncertainties of our values.

The reason for a larger difference for $\mu_{d, \textrm{B}}$ is that @2014MNRAS.437..351B use strong priors on distances, metallicities, and ages coming from a model of the Galaxy. These priors are decreasing functions of distance from the Galactic centre and from the Galactic plane. Therefore they decrease with distance from the Sun for the majority of directions probed by RAVE. The prior that decreases with distance results in smaller estimates for stellar distances and thus slightly smaller masses and larger ages as compared to our results. Difference in log(age) are further enhanced due to age priors used by @2014MNRAS.437..351B.

As can be seen in panels *c* and *e* of , distributions of differences between our results for log(age)s and masses and @2014MNRAS.437..351B results are bimodal, with a secondary peak at approximately $-0.75$ in relative mass difference and $0.2$ in relative log(age) difference. The same can be seen in panel *d*. In panel *f* the second peak is out of the plotted range. This second peak contains about 12% of stars and is caused by a difference in the evolutionary stages accepted in @2014MNRAS.437..351B and by our UniDAM tool. A similar pattern but with a much smaller secondary peak can be seen with data from the mock survey (black histogram in panels c and d of ).

We show in the distributions of the median difference between our results and the @2014MNRAS.437..351B results for distance modulus and log(age) on the Hertzsprung-Russell diagram. We chose RAVE because it contains estimates for both distance modulus and log(age) and because it covers both main-sequence and giant stars. There is clearly a good agreement in both distance modulus and log(age) for the main-sequence stars and large fraction of giant branch, including the red clump. A disagreement for pre-main-sequence stars and large and hot (thus most massive) giants is primarily due to difference in the models and priors used. Similar plots can be produced for other datasets, revealing similar patterns.

![Hertzsprung-Russell diagrams of RAVE data showing colour differences between our results and RAVE results [@2014MNRAS.437..351B] for distance moduli (top panel) and log(age)s (bottom panel).[]{data-label="fig:RAVE"}](RAVE_distance_modulus.png){width="48.00000%"}

![Hertzsprung-Russell diagrams of RAVE data showing colour differences between our results and RAVE results [@2014MNRAS.437..351B] for distance moduli (top panel) and log(age)s (bottom panel).[]{data-label="fig:RAVE"}](RAVE_age.png){width="48.00000%"}

### LAMOST-GAC distances

We compared our results with two distance estimates provided in [@2015RAA....15.1095L]. Our values are systematically smaller by a fraction of $0.1$ as compared to their “empirical” estimates based on the MILES library. We have much better agreement with estimates based on isochrones from Dartmouth Stellar Evolution Database ($0.02$ fractional difference). [@2015RAA....15.1095L] do not provide uncertainties for their distance estimates. Relative uncertainties of our distance estimates for LAMOST-GAC are higher than estimates build on data from other surveys due to the higher uncertainties in spectral parameters, which lead to a fractional uncertainties on our distances of $0.2$.

Effect of the volume correction {#sec:priors}
-------------------------------

We ran tests to see how much the use of the volume correction (see ) affects our results. Volume correction can be seen as a distant prior that ensures constant number density. In general, if the distance prior is a decreasing (increasing) function, the resulting distance is smaller (larger) than in the case of a flat prior. The size of this effect depends on the relative variation of the prior function within the uncertainty range of the parameter. We chose two datasets for the test: GCS and APOKASC giants [@2014MNRAS.445.2758R]. The GCS dataset contains primarily main-sequence stars with distances derived from *HIPPARCOS* parallaxes. These parallaxes are in most cases more precise than our distance measurements. Distances of APOKASC giants were derived using asteroseismic data, and therefore should also be more precise than our measurements. We ran our UniDAM tool with and without volume correction. We selected only USPDFs with highest weight for analysis in each case. We then explored how parallaxes, distances, masses, and log(age)s were affected by volume correction. For multimodal cases it is important that the use of the volume correction might change the relative weights of USPDFs, so that priorities might also change. The result of our experiment is that in $7\%$ cases for APOGEE the assigned evolutionary stage changed when we applied the volume correction. This did not happen for GCS as PDFs are unimodal in most cases for main-sequence stars in that survey. By removing volume correction we decreased distance estimations in both datasets by a fraction of $0.032$ if the assigned evolutionary stage did not change. This is well below the median relative distance uncertainties that we have ($\approx 0.13$). The mass estimates are correlated with distance, and decreased by a fraction of $0.03$, again, this is well below relative uncertainties in mass that we find ($\approx 0.15$). The logarithm of age estimates, which are anti-correlated with distance, increased, but only by a fraction of $0.005$ (log(age) fractional uncertainties $\approx 0.03$). So the conclusion here is that the volume correction has a measurable and well understood effect on measured parameters, but this effect is smaller than our typical parameter uncertainties. This effect is systematic and has to be taken into account when comparing with results obtained with distance priors; see for example . However, we expect the contribution from the (unknown) systematic uncertainties of spectroscopic measurements to be at least as high as the influence of the volume correction.

We also compare how the volume correction affects the agreement between our measurements and data from the literature, which is described above in Section \[sec:compare\]. The effect of volume correction is summarised in the . For the GCS sample there is a clear advantage of using the volume correction. Without volume correction our parallax estimates are lower than those in GCS by a fraction $0.091$. If we use the volume correction, our parallax estimates increase on average, which improves the agreement (fractional difference of $0.059$; see the first row of ). The same applies for log(age) and mass estimates. As for the APOKASC sample, there seems to be an opposite result, as we seem to overestimate the distance compared to [@2014MNRAS.445.2758R]. This is likely caused by the fact that distances provided in [@2014MNRAS.445.2758R] are in fact modes of probability density function. If we use modes instead of means for our USPDFs for distances, than we get a relative difference of less than $10^{-3}$ if the volume correction is included and a relative difference around $0.014$ if there is no volume correction used.

The effect of the volume correction increases gradually with increasing distances, where our distance uncertainty is larger. This is caused by an increase in the relative variation of the value of the volume correction within the distance uncertainty. The effect of volume correction is approximately proportional to a square of the uncertainty in distance modulus. If the assigned evolutionary stage changes, the estimates of distance, mass, and log(age) can change by a large amount, sometimes by more than $50\%$.

[ccd[1.3]{}d[1.3]{}]{} Survey & Value & [ ]{} & [ ]{}\
GCS & $\pi$ & -0.091 & -0.059\
& $M$ & 0.027 & 0.015\
& $\tau$ & -0.000 & 0.000\
APOKASC & $d$ & -0.001 & -0.021\

Stellar parameters catalogue
============================

We provide a catalogue of stellar distances, masses, and log(age)s determined with the UniDAM tool described in this manuscript. Our catalogue contains over 3.8 million rows (one row for each USPDF) for over 2.5 million stars. We summarise some properties of this catalogue in . This figure shows medians of different quantities in each bin on the Hertzsprung-Russell (HR) diagram. Data from all input spectroscopic surveys have been used to produce this figure. Quantification of differences between spectroscopic data from different surveys and effects of incompleteness and selection are beyond the scope of this paper and will be addressed in future work. Here, we are interested in a qualitative description of how the quality of our estimates vary in different parts of the HR diagram. Panels *a* and *b* of show uncertainties in measured log(age)s and masses. Log-ages are best constrained in the upper part of the main sequence, where parameters change fast as a star leaves the main sequence. On the contrary, masses are much better constrained on the main sequence.

Panels *c* and *d* show median values of $p_{best}$ (the probability for a best-fitting model) and $p_{sed}$ (a measure of how good we reproduce SED with our model). Patterns on both panels are similar with worse results close to the edges of the region covered by the PARSEC isochrones and additionally for $p_{sed}$ between the main sequence and giant branch.

Panels *e* and *f* show median values for the weights $V_0$ of the highest weight USPDF and total number of USPDFs with $V_i > 0.03$. The patterns are nearly inverse: on the main sequence we typically have only one USPDF with weight equals to unity, whereas on the giant branch the number of USPDFs increases and the weights of the highest weight USPDF decreases. It is important that for the giant branch we typically have two or more USPDFs, therefore using just the one with the highest weight is insufficient; the best solution is to use all USPDFs with their relative weight taken into account.

![image](Catalog.png){width="90.00000%"}

Quality flags {#sec:quality}
-------------

The output catalogue contains a `quality` column, which indicates how reliable data contained in each row are. Values have been assigned as follows:

1

:   - single PDF

A

:   - highest-weight USPDF has power of 0.9 or more

B

:   - 1st and 2nd priority USPDFs together have power of 0.9 or more

C

:   - 1st, 2nd, and 3rd priority USPDFs together have power of 0.9 or more

D

:   - 1st, 2nd, and 3rd priority USPDFs together have power of less than 0.9

L

:   - low power USPDF (between 0.03 and 0.1)

E

:   - USPDF has $p_{sed} < 0.1$ (possibly bad photometry)

X

:   - highest weight USPDF has $p_{best} < 0.1$ (likely off the model grid)

N

:   - USPDF has less than 10 models (unreliable result)

Although `the quality` value provides some information on the quality of the parameter estimation, it is not recommended to select stars based on that value alone (apart from removing unreliable results with values **E, N,** or **X**), because the quality value varies heavily over the HR diagram: for main-sequence stars the quality is in most cases **1** or **A**, whereas for giants quality **B, C,** or even **D** are much more common. This is illustrated by the distribution of the number of USPDFs in panel f of . There are $2\%$ cases where a highest weight USPDF has quality **E**, $4.2\%$ cases with quality **X,** and less than $0.01\%$ cases with quality **N**.

Discussion and conclusions {#sec:discussion}
==========================

We provide a catalogue of distances, log(age)s, and masses for over 2.5 million stars. This number will increase as new data is made available, for example new data releases for surveys already included, or data from new surveys. Gaia data will be of high value and can be used as an independent test of our distances or as a parallax prior. In the latter case it should improve our extinction, mass, and log(age) estimates considerably.

In the current version of our UniDAM tool we use infrared magnitudes, [${\ensuremath{T_{\rm{eff}}}}, \log g$, and ${[\rm{Fe/H}]}$]{} as inputs to derive distances, log(age)s, and masses of stars. The tool was also successfully used to derive temperatures for a APOKASC sample, with inputs being surface gravities, and masses derived from seismic information and spectroscopic metallicities (Tayar et al. 2017, accepted).

An advantage of our approach is that we represent multi-peaked PDFs for parameters with a sum of unimodal distributions. Additionally we provide parameters of fits representing each distribution and the correlations between distance modulus, log(age), and mass. Therefore our catalogue contains not only mean values and uncertainties, but detailed information on PDFs. This allows us to apply more sophisticated analysis to the dataset to reveal both global and local structures in the Galaxy.

The next step will be to add proper motion data, thus obtaining all six dimensions of stellar positions and velocities. Combination of positions and velocities with ages, metallicities, and (where available) chemical abundances will open up new possibilities to study Galactic structure. Furthermore, it is important to get a correct estimate of the selection function, as this might affect results not only quantitatively, but also qualitatively, as was shown by @2012ApJ...751..131B. We intend to produce a selection function for our catalogue and then proceed to study Galactic structure on large and small scales.

Acknowledgements {#acknowledgements .unnumbered}
================

Authors thank the anonymous referee for a detailed report with many useful suggestions. It helped us to improve the manuscript substantially.

The research leading to the presented results has received funding from the European Research Council under the European Community’s Seventh Framework Programme (FP7/2007- 2013)/ERC grant agreement (No 338251, StellarAges).

This publication makes use of data products from the Two Micron All Sky Survey, which is a joint project of the University of Massachusetts and the Infrared Processing and Analysis Center/California Institute of Technology, funded by the National Aeronautics and Space Administration and the National Science Foundation.

Guoshoujing Telescope (the Large Sky Area Multi-Object Fiber Spectroscopic Telescope LAMOST) is a National Major Scientific Project built by the Chinese Academy of Sciences. Funding for the project has been provided by the National Development and Reform Commission. LAMOST is operated and managed by the National Astronomical Observatories, Chinese Academy of Sciences.

This publication makes use of data products from the Wide-field Infrared Survey Explorer, which is a joint project of the University of California, Los Angeles, and the Jet Propulsion Laboratory/California Institute of Technology, and NEOWISE, which is a project of the Jet Propulsion Laboratory/California Institute of Technology. WISE and NEOWISE are funded by the National Aeronautics and Space Administration.

Funding for RAVE has been provided by the Australian Astronomical Observatory; the Leibniz-Institut fuer Astrophysik Potsdam (AIP); the Australian National University; the Australian Research Council; the French National Research Agency; the German Research Foundation (SPP 1177 and SFB 881); the European Research Council (ERC-StG 240271 Galactica); the Istituto Nazionale di Astrofisica at Padova; The Johns Hopkins University; the National Science Foundation of the USA (AST-0908326); the W. M. Keck foundation; the Macquarie University; the Netherlands Research School for Astronomy; the Natural Sciences and Engineering Research Council of Canada; the Slovenian Research Agency; the Swiss National Science Foundation; the Science and Technology Facilities Council of the UK; Opticon; Strasbourg Observatory; and the Universities of Groningen, Heidelberg and Sydney. The RAVE website is at <https://www.rave-survey.org>.

Funding for SDSS-III has been provided by the Alfred P. Sloan Foundation, the Participating Institutions, the National Science Foundation, and the U.S. Department of Energy Office of Science. The SDSS-III website is http://www.sdss3.org/. SDSS-III is managed by the Astrophysical Research Consortium for the Participating Institutions of the SDSS-III Collaboration including the University of Arizona, the Brazilian Participation Group, Brookhaven National Laboratory, University of Cambridge, Carnegie Mellon University, University of Florida, the French Participation Group, the German Participation Group, Harvard University, the Instituto de Astrofisica de Canarias, the Michigan State/Notre Dame/JINA Participation Group, Johns Hopkins University, Lawrence Berkeley National Laboratory, Max Planck Institute for Astrophysics, Max Planck Institute for Extraterrestrial Physics, New Mexico State University, New York University, Ohio State University, Pennsylvania State University, University of Portsmouth, Princeton University, the Spanish Participation Group, University of Tokyo, University of Utah, Vanderbilt University, University of Virginia, University of Washington, and Yale University.

This research has made use of the SIMBAD database, operated at CDS, Strasbourg, France

Splitting the PDF into unimodal sub-PDFs {#sec:split_uspdf}
========================================

Here we describe a method used to split complex PDFs into a set of unimodal sub-PDFs.

First, we produced a histogram for logarithm of stellar masses of models of the same evolutionary stage (weighted by $W_j$, see ). Then, we detected local minima and maxima of this histogram. Local minima (or maxima) are defined as locations of bins that have lower (higher) value $h_i$ than all other bins within the window: i.e. $h_i = min\{h_j, i-n \leq j \leq i+n\}$ for a local minimum and $h_i = max\{h_j, i-n \leq j \leq i+n\}$ for a local maximum. Window size $n$ was taken to be 3 for maxima and 2 for minima. Differences in window sizes are caused by the need to locate minima with high precision and to avoid too many maxima in noisy data. Formally, it is possible to have more than one local minimum between two local maxima; we split only by the lowest of them in this case. We split the sample at positions of local minima that are lower than 0.75 times the value of the smallest of the two enclosing maxima. We thus could have one or several USPDFs, for each evolutionary stage.

We chose the histogram in logarithm of mass to split the multimodal PDFs as the logarithmic scale is close to linear one around $1 {\ensuremath{\rm{M}_\odot}}$, but gives a smoother histogram for high-mass stars. Mass is a better choice to split the PDF because values of log(age)s are quantised by construction of the isochrones, and distances are much less sensitive to evolutionary stage.

Distributions used in the paper {#app:functions}
===============================

Here we give definitions for some functions used in the paper.

We define $\phi(x)=\frac{1}{\sqrt{2 \pi}}\exp\left(-\frac{1}{2}x^2\right)$ as the PDF of the standard normal distribution and $\Phi(x)$ as it’s cumulative distribution. This PDF is designated as a Gaussian in the text.

Introducing $\xi=\frac{x-\alpha}{\sigma}$ and $Z=\Phi(\frac{b-\alpha}{\sigma})-\Phi(\frac{a-\alpha}{\sigma})$, we have for a truncated Gaussian $$f(x,\alpha,\sigma, a,b) = \frac{\phi(\xi)}{\sigma Z},$$ if $a < x < b$ and $f(x;\alpha,\sigma, a,b) = 0$ otherwise. Here $\alpha$ is a location, $\sigma$ - scale, $a, b$ - lower and upper limits.

For skewed Gaussian with a shape parameter $s$ $$f(x,\alpha,\sigma, s) = \frac{2}{\sigma} \phi(\xi) \Phi(s \xi).$$

We use the definition of the truncated [Student’s t-distribution]{}$$f_t(x, \nu) = \frac{\Gamma \left(\frac{\nu+1}{2} \right)} {\sqrt{\nu\pi}\,\Gamma \left(\frac{\nu}{2} \right)} \left(1+\frac{x^2}{\nu} \right)^{-\frac{\nu+1}{2}},$$ where $\nu$ is the “number of degrees of freedom” (which can be an arbitrary real number here). Again, $\Phi_t(x, \nu)$ is the cumulative distribution function.

A modified truncated exponential distribution with lower and upper limits $a$ and $b$, respectively is defined as $$f_{\textrm{exp}}(x, \alpha, \sigma, a, b) = 
 \begin{cases}
   C e^{-\frac{|x-\alpha|}{\sigma}}, & \textrm{if}\ a < x < b \\
   0,& \textrm{otherwise.}
 \end{cases}$$ Here, $C$ is the normalisation constant, so that $\int_a^b f_{\textrm{exp}}(x, \alpha, \sigma, a, b) = 1$.

For a truncated Student’s t-distribution with lower and upper limits $a$ and $b$, respectively, we define $\xi=\frac{x-\alpha}{\sigma}$ and $Z_t=\Phi_t(\frac{b-\alpha}{\sigma}, \nu)-\Phi_t(\frac{a-\alpha}{\sigma}, \nu)$. Then for the PDF we have $$f_{\textrm{truncated-t}}(x, \alpha, \sigma, a, b) = \frac{f_t(\xi, \nu)}{Z_t}.$$

[^1]: email: mints@mps.mpg.de

[^2]: The unified tool source code is available at <https://github.com/minzastro/unidam>, tables with results are available in electronic form at the CDS via anonymous ftp to cdsarc.u-strasbg.fr (130.79.128.5) or via <http://cdsweb.u-strasbg.fr/cgi-bin/qcat?J/A+A/>

[^3]: see APOGEE target selection description at <http://www.sdss.org/dr12/irspec/targets/>
