\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{multirow}
%\usepackage{subfig}

%\input epsf.sty
%\topmargin   0.25in
\topmargin -.5cm \textheight 21cm

\oddsidemargin -.125cm

\textwidth 16cm

\newcommand{\ra}{\rangle}
\newcommand{\la}{\langle}
\newcommand{\T}{\widetilde \Phi_{CFT}}
\newcommand{\Cn}{{\cal C}_n}
\newcommand{\vp}{\varphi}

\newcommand{\B}{b'}
\newcommand{\C}{c'}
\newcommand{\bB}{\bar b'}
\newcommand{\bC}{\bar c'}
\newcommand{\Bu}{B_{\vec u}}
\newcommand{\VV}{{\cal V}}
\newcommand{\II}{{\cal I}}
\newcommand{\HH}{{\cal H}}
\newcommand{\MM}{{\cal M}}
\newcommand{\BB}{{\cal B}}
\newcommand{\CC}{{\cal C}}
\newcommand{\OO}{{\cal O}}
\newcommand{\QQ}{{\cal Q}}
\newcommand{\PP}{{\cal P}}
\newcommand{\EE}{{\cal E}}
\newcommand{\LL}{{\cal L}}
\newcommand{\SSS} {{\cal S}}
%\newcommand{\lll}{\langle\langle}
%\newcommand{\rrr}{\rangle\rangle}
\newcommand{\half}{{1\over 2}}
\newcommand{\wt}{\widetilde}
\newcommand{\wh}{\widehat}
\newcommand{\wc}{\check}
\newcommand{\wb}{\bar}
\newcommand{\RR}{{\cal R}}
\newcommand{\NN}{{\cal N}}
\newcommand{\TT}{{\cal T}}
\newcommand{\bet}{\beta'}
\newcommand{\gam}{\gamma'}
\newcommand{\WW}{{\cal W}}
\newcommand{\nl}{\hspace{-.65cm}}
\newcommand{\bd}{\begin{displaymath}}
\newcommand{\ed}{\end{displaymath}}
\newcommand{\ba}{\begin{eqnarray}}
\newcommand{\ea}{\end{eqnarray}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\ben}{\begin{eqnarray}}
\newcommand{\een}{\end{eqnarray}}
\newcommand{\refb}[1]{(\ref{#1})}
\newcommand{\p}{\partial}
\newcommand{\sectiono}[1]{\section{#1}}
\setcounter{equation}{0}
\renewcommand{\theequation}{\thesection.\arabic{equation}}

\def\sqr#1#2{{\vcenter{\vbox{\hrule height.#2pt
         \hbox{\vrule width.#2pt height#1pt \kern#1pt
            \vrule width.#2pt}
         \hrule height.#2pt}}}}
\def\square{\mathop{\mathchoice\sqr66\sqr66\sqr{3.75}4\sqr34\,}\nolimits}

\begin{document}
\section{Methodology}
By comparing the statistic of the observed lensed galaxies to the theoretical
predictions one can constrain the intrinsic luminosity function. Here we make
use of the observed sub-mm galaxies  located between $z = 1$ and $z = 4$ with
the  redshift distribution of sources from Simpson et al. 2014 \cite{Simpson:2014lr}, $
dN/dz \propto \exp\left[-(\ln(z+1)-\ln(1+z_\mu))^2/2\sigma_z^2\right]/\left[(z+1)\sigma_z\sqrt{2\pi}\right]$, where $z_\mu = 2.6$, $\sigma_z = 0.2$ to constrain the intrinsic luminosity function. To this end, we test several theoretical models which include broken power law and Schechter luminosity functions with various parameters and test them against the data. Similar analysis appeared, e.g.  in  Lima et al. 2010a \cite{Lima:2010a}, Lima et al. 2010b \cite{Lima:2010b}, Wardlow et al. (2013) \cite{Wardlow:2013}, etc.

 In the following we first describe our way to model the foreground population, we then discuss the calculation of the lensing statistics, and, finally, we list our choices for the intrinsic luminosity functions.

\subsection{Magnification by an individual lens}

We begin by summarizing the properties of the lenses. We use two ways to model our halos: (1) as a single isothermal sphere (SIS), and (2) a NFW profile (Navarro et al. 1997).  The NFW profile describes the outskirts of halos better whereas the SIS profile is good in describing the inside of a halo since it yields the  observed flat rotational curves. Here we make use of the both profiles to create the total probability distribution function.

In general, the magnification can be calculated as follows
\begin{equation}
\mu(\theta) = \frac{1}{(1-\kappa(\theta))^2-|\gamma(\theta)|^2},
\end{equation}
where  $\theta$ is the angular  coordinate in the lens plane, $\kappa$ is the convergence and $\gamma $ the shear, which depend on the properties of the lens and its distance from the source.

We start with the NFW halos. In this case the convergence and shear are given by
\begin{equation}
\kappa_{NFW}(\theta) = \frac{M_{vir}fc_{200}^2}{2\pi r_{200}^2}\frac{F\left(c_{200}\theta/\theta_{200}\right)}{\Sigma_{cr}}~~~~\textrm{and}~~~~\gamma(\theta) = \frac{M_{vir}f c_{200}^2}{2\pi r_{200}^2}\frac{G\left(c_{200}\theta/\theta_{200}\right)}{\Sigma_{cr}},
\label{Eq:kappa}\end{equation}
with  the critical projected density is given by
\begin{equation}
\Sigma_{cr} = \frac{1}{4\pi G(1+z)}\frac{D_A^s)}{D_A^l)D_A^{ls})},
\end{equation}
where $D_A^s$, $D_A^l$ and $D_A^{ls}$  are the angular diameter distance between the observer and the source,  the observer and the lens and the lens and the source respectively. In eq.  \ref{Eq:kappa}  F and G are two functions given by Takada and Jian 2003 \cite{Takada:2003}, for which we assumed a truncated NFW profile (truncated at $r_{vir}$).  $M_{vir}$ is the virial mass, $r_{200}$ is the comoving virial radius, $\theta_{200}$ is the angular size on the lens plane which corresponds to  $r_{200}$, $c_{200}$ is the concentration parameter of the dark matter halos calculated as in Diemer and Kravtsov (2014) \cite{Diemer:2014} and  $f = \left[\log(1+c_{200})-c_{200}/(1+c_{200})\right]^{-1}$.

The magnification of SIS can be written as
\begin{equation}
\mu_{SIS}(\theta)= \left(1-\frac{\theta_E}{|\theta|}\right)^{-1},~~~~\textrm{with}~~~~\theta_E = 4\pi\frac{\sigma_V^2}{c^2}\frac{D_{A}(r_{ls})}{D_A(r_s)}.
\end{equation}
Here $\sigma_V^2$ is the velocity  dispersion which we take from a simulation by Evrard et al. (2008) \cite{Evrard:2008}. In this simulation the dependence of $\sigma_V^2$ on the halo mass and redshift is provided which allows us to apply our model to high and low redshift galaxies.

Next for each given source we need to sum up the contributions to the total magnification from different lenses. Here we generate abundances of halos at each redshift using the Sheth-Tormen (1999) \cite{Sheth:1999} formalism which gives the number of halos per unit volume in each mass bin.

\subsection{Lensing Statistics}

The magnification of a source galaxy by a foreground galaxy depends on the profile of the foreground galaxy, redshifts of the lens and of the source and the impact parameter.  To model the probability distribution of lensing the  procedure is as follows. We first model the differential probability distribution $P(\mu)$ for a particular pair of source which emits light at $z_s$ and lens of mass $M_l$ which deflects the the light ray at $z_l$ where we account for a wide range of impact parameters. We next sum over the distribution of redshift sources and the masses and the redshifts of the  lenses to get the total probability distribution function.

Next, we calculate the total probability for lensig with the magnification larger than some $\mu$, $P(>\mu)$ and the probability density for magnification $\mu$, $P(\mu) = -dP(>\mu)/d\mu$. In this we generally follow the approach taken in Lima et al. (2010a) \cite{Lima:2010a}.

It should be noted that neither SIS nor NFW profiles fully describe the observations with SIS being a better match at small distances from the halo center and NFW better describing the outskirts. To be closer to reality,  we smoothly glue the probability densities $P_{SIS}(\mu)$ and $P_{NFW}(\mu)$ so that the former dominates at large magnifications (small impact parameters) and the latter dominates at small  magnifications (large impact parameters). We make sure that the resulting probability density, $P_{tot}(\mu)$, is normalized to unity.

We further use this probability density to estimate the effect of lensing on the observed luminosity function. To this end we calculate the mean magnification at given observed flux and compare it to data  \begin{equation}
 <\mu>(S_{obs}) = \int_0^\infty \mu P(\mu|S_{obs})  d\mu,
 \end{equation}
where the probability for lesning with magnification $\mu$ given the observed flux \cite{Lima:2010b} is
\begin{equation}
P(\mu|S_{obs}) = \frac{1}{N}\frac{P(\mu)}{\mu}\frac{dn}{dS}\left(\frac{S_{obs}}{\mu}\right), ~~~\textrm{where}~~~N = \frac{dn_{obs}(S_{obs})}{dS_{obs}} = \int  \frac{P(\mu)}{\mu}\frac{dn}{dS}\left(\frac{S_{obs}}{\mu}\right)d\mu.
\end{equation}
Here $ dn_{obs}(S_{obs})/dS_{obs}$ is the observed luminosity function and $dn/dS$ is the intrinsic one which we discuss in the next section.

In addition we calculate the expected fraction of the sources of observed flux $S_{obs}$ lensed with magnification greater than $\mu$
\begin{equation}
Fr = \frac{\int_\mu^\infty P(\mu|S_{obs})}{\int_0^\infty P(\mu|S_{obs})}.
\end{equation}

\subsection{Intrinsic luminosity function}

The effects of lensing are expected to be manifested at the bright-luminosity end of the luminosity function. Therefore it is natural to assume that the faint-luminosity end has undergone a negligible amount of lensing.
We use the faint-luminosity number counts recently reported by Karim et al. (2013) to normalize our intrinsic luminosity functions.

We use two functional forms to fit the number counts:
\begin{enumerate}
\item The Shechter function with
\begin{equation}
\frac{dn}{dS} = \frac{n_\star}{S_\star}\left(\frac{S}{S_\star}\right)^{-\alpha}\exp\left(-S/S_\star\right)
\end{equation}
with the parameters $n_s = 424$ $mJ^{-1}deg^{-2}$, $S_\star = 8$ [mJy], $\alpha = 1.1$ (from Karim et al. 2013) and $n_s = 424$ $mJ^{-1}deg^{-2}$, $S_\star = 7$ [mJy], $\alpha = 1.9$ (steep).
\item The broken power law
\begin{equation}
\frac{dn}{dS} = N_s\left(\frac{S}{S_\star}\right)^{-\beta_1},~~~~\textrm{for}~~~~S<S_\star,
\end{equation}
\begin{displaymath}
\frac{dn}{dS} = N_s\left(\frac{S}{S_\star}\right)^{-\beta_2},~~~~\textrm{for}~~~~S>S_\star,
\end{displaymath}
with the parameters $N_s = 25$ $mJ^{-2}deg^{-2}$, $S_\star = 8$ [mJy], $\beta_1 = 2$ and $\beta_2 = 18$.
\end{enumerate}

\begin{thebibliography}{9}

{\footnotesize

\bibitem{Simpson:2014}
J. M. Simpson, et al.,
ApJ, 788 (2014) 125.

\bibitem{Lima:2010a}
M. Lima, B. Jain, M. Devlin,
MNRAS, 406 (2010) 2352.

\bibitem{Lima:2010b}
M. Lima, B. Jain, M. Devlin,  J. Aguirre,
ApJL, 717 (2010) 31.

\bibitem{Wardlow:2013}
J.L.~Wardlow, et al.,
ApJ 762 (2013).

\bibitem{Takada:2003}
M.~Takada, B. Jain,
MNRAS 344 (2003) 857.

\bibitem{Diemer:2014}
B.~Diemer, A. V. Kravtsov,
arXiv:1407.4730.

\bibitem{Evrard:2008}
A.~E. Evrard et al.,
ApJ 672 (2008) 122.

\bibitem{Sheth:1999}
R. K. Sheth, G. Tormen,
 MNRAS  308 (1999) 119.
}
\end{thebibliography}
\end{document}


\chapter{A Second Approach : Constraint Based Learning}

As seen in the previous chapter, the initial approach suffered from significant difficulty scaling. Even simple two argument functions took upwards of 400 seconds to complete. This was mainly due to the sheer size of the ground learning task, and the complexity from combinations of rule and where predicates.

\section{Top Down Vs. Bottom Up}
The main issue with the interpreted approach is that it is bottom-up. To learn the output of a rule, it must first iterate down the expression tree (shown in Figure \ref{fig:expr_tree_2}), calculate the value of each simple sub-expression, then iterate back up the tree combining values until a value is known for the entire rule body. My second approach overcomes this issue by implementing a top down approach. \\ \\

\begin{figure}[h!]
\centering
\includegraphics[width=0.55\textwidth]{C1/expression_tree.png}
\caption{Expression tree for a simple expression}
\label{fig:expr_tree_2}
\end{figure}
\mbox{}\\
The idea behind this new approach is simple. By maintaining an ``equality constraint'', the tool keeps track of what each expression is supposed to be equal to (as defined by the input examples). Then, as the program iterates down the expression tree, it fails if it ever finds some easily provable equality failure, i.e 1 = 2. \\ \\
For example, if it knows that \lstinline{call(f, 2) = 5} and that the body of function f is \lstinline{(2 * X) + 1}, then it can deduce that
\begin{align*}
(2*2) + 1 &= 5 \\
(2*2) &= 4 \\
2 &= 2
\end{align*}
So there are no contradictions. \\ \\
However, if instead there is an example stating that \lstinline{call(f, 2) == 6}, with the same function, then instead we get %{
\begin{align*}
(2*2) + 1 &= 6 \\
(2*2) &= 5 \\
\end{align*}
Which fails because 5 is not a multiple of 2.

\subsection{Dealing with termination}
One issue with this new approach is that it does not automatically handle programs which do not terminate. Whilst these programs do not stop clingo from finding a solution, they are incorrect as the generated constraints never become simple enough to have a contradiction be proved. \\ \\
To deal with this, the tool has to check input examples for termination. While this is typically an undecidable problem, for my small target language it is decidable and computable. To represent this in ASP, there needed to be a way to represent the next step of execution of an expression. For example, we can say that \lstinline!next_step(add(1, mul(2, 3)), mul(2, 3))!, meaning that it next evaluates \lstinline!mul(2, 3)!. \\ \\
I then define termination as :
\begin{itemize}
\item If an expression is simple, containing only constants, then it terminates.
\item If the next step of an expression terminates, then that expression also terminates.
\end{itemize}
\mbox{}\\
This approach is fairly efficient as it as another top down approach, and generates a similar number of rules in the ground program as the constraint checking rules.
\mbox{}\\
\section{ASP Representation}
I represent this approach using the following ASP predicates.

\begin{center}
\begin{tabular}{| c | m{0.7\linewidth} |}
\hline
\textbf{ASP Term} & \textbf{Semantics} \\
\hline
\lstinline!eq(Expr, Val)!
&
\mbox{}\newline
An equality constraint. Expr, when evaluated, should equal Val. \newline
\\
\hline
\lstinline!is_call(call(F, Expr))!
&
\mbox{}\newline
Represents if a function is called. Used to generate more ground skeleton rules. \newline
\\
\hline
\lstinline!terminates(Expr)!
&
\mbox{}\newline
Represents if an expression terminates. \newline
\\
\hline
\lstinline!next_step(A, B)!
&
\mbox{}\newline
The next step of the execution of expression A is expression B.\newline
\\
\hline
\end{tabular}
\end{center}
\mbox{}\\
Now, these predicates are used in the following rules. \\

\lstinputlisting[language=Prolog, firstline=32, lastline=32, firstnumber=32, label=lst:eq_gen, caption=Equality generation]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:eq_gen} generates initial equality constraints given by the examples.  \\

\lstinputlisting[language=Prolog, firstline=33, lastline=33, firstnumber=33, label=lst:eq_const, caption=Equality contradiction]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:eq_const} constrains equality on constants. The tool should fail if two different constants are equal. \\

\lstinputlisting[language=Prolog, firstline=34, lastline=37, firstnumber=34, label=lst:eq_const_mul, caption=Multiplication contradictions]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:eq_const_mul} handles edge cases when dealing with multiplication. If multiplying any expression by 0, then it should be equal to 0, and if multiplying two things together, then the answer should be a multiple of them both. \\

\lstinputlisting[language=Prolog, firstline=38, lastline=38, firstnumber=38, label=lst:term_constraint, caption=Termination contradiction]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:term_constraint} handles termination. The tool fails if an input example does not terminate.\\

\lstinputlisting[language=Prolog, firstline=40, lastline=40, firstnumber=40, label=lst:is_call, caption=Is\_call generation]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:is_call} generates \lstinline{is_call} predicates, which are used to generate more ground instances of skeleton rules. \\ %{

\lstinputlisting[language=Prolog, firstline=42, lastline=45, firstnumber=42, label=lst:eq_call, caption=Constraint propagation through function calls]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:eq_call} handles propagation of equality constraints through function calls. If a called function is equal to some value, then the body of the function (with correct arguments) is also equal to that value. \\

\lstinputlisting[language=Prolog, firstline=47, lastline=60, firstnumber=47, label=lst:eq_math, caption=Constraint propagation through arithmetic operations]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:eq_math} specifies generation of equality predicates with arithmetic, through use of the opposite operations. Addition terms in the head of the rule are necessary to handle edge cases such as division by zero. \\

\lstinputlisting[language=Prolog, firstline=62, lastline=63, firstnumber=62, label=lst:eq_pair, caption=Constraint propagation through tuples]{../ASP/eq/eq_rules.lp}
\mbox{}\\
\ref{lst:eq_pair} describes the propagation of equality constraints through tuple pairs. If a tuple of expressions is equal to a tuple of values, then the respective halves of the tuple are equal to each other. \\

\lstinputlisting[language=Prolog, firstline=65, lastline=66, firstnumber=65, label=lst:term, caption=Termination]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:term} defines termination. If an expression is a constant, then it terminates, or if the next step of an expression terminates then that expression also terminates. \\

\lstinputlisting[language=Prolog, firstline=68, lastline=68, firstnumber=68, label=lst:next_init, caption=Next step initialisation]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:next_init} generates the initial \lstinline!next_step! predicates. If there exists an example input, then it is the next step of some arbitrary term \lstinline!e!. \\

\lstinputlisting[language=Prolog, firstline=82, lastline=82, firstnumber=82, label=lst:next_is, caption=Next step grounding improvement]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:next_is} exists to reduce the grounding. If any expression is a next step, we generate an \lstinline{is_next_step} predicate, used in the remaining \lstinline{next_step} rules.\\

\lstinputlisting[language=Prolog, firstline=70, lastline=73, firstnumber=70, label=lst:next_func, caption=Next step propagation through function calls]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:next_func} handles the next step of function calls. The next step of a function call is the body of that function. \\

\lstinputlisting[language=Prolog, firstline=65, lastline=81, firstnumber=65, label=lst:next_match, caption=Next step propagation through arithmetic operations]{../ASP/eq/eq_rules.lp}
\mbox{} \\
\ref{lst:next_match} generates \lstinline{next_step} predicates for arithmetic and tuples. The next step of an arithmetic expression is the argument that is not constant. %{

\section{Learning}
The actual learning task operates in a similar way to my initial approach. The task is again encoded as an ASP program, where the solution is a subset of the Answer Set of this program. \\ \\
By enumerating all possible rule bodies in the skeleton rules, a choice rule can be used to generate answer sets with each combination of skeleton rule, keeping the answer sets which do not fail the equality constraints. However, because \lstinline!where! rules are no longer being used, the skeleton rules now contain full bodies. This means that unfortunately the number of skeleton rules becomes large, numbering in the thousands for even simple tasks. To avoid this scaling poorly once again, I decided to implement a number of simple optimisations.%{

\subsection{Using inbuilt arithmetic}
As part of the first approach, arithmetic was represented with my own predicates \lstinline{add(A, B)}, \lstinline{sub(A, B)} and \lstinline{mul(A, B)} because the tool needed to evaluate expressions that the grounder would not be able to compute (i.e the value of function calls or where variables). \\ \\ %{
However, in my new approach I have made partial use of the clingo inbuilt arithmetic. If inside function arguments, or the rule body has no function calls at all, then the tool knows that all sub expressions will be arithmetic and it can make use of the simple \lstinline{+, -} and \lstinline{*}. \\ \\
The main advantage of this approach is that it vastly reduces the ground output. As the inbuilt operations are computed by the grounder, if two different expressions compute the same output number, then they are not repeated in the ground output. For example, \lstinline{X + X} and \lstinline{2 * X} are semantically equivalent, so when ground with \lstinline!X = 3! both produce the term \lstinline!6!, corresponding to one output rule.

\section{A Worked Example : Greatest common divisor}
Once again I will use Euclid's algorithm for the Greatest Common Divisor \cite{Euclid} to illustrate this new approach. Because the tool still does not have modulo as part of its target language, the simplified definition is used: \\

\lstinputlisting[language=Haskell, firstline=2, lastline=5]{../ASP/eq/gcd.lp}
\mbox{} \\
As input, I will be using the following examples : \\

\lstinputlisting[language=Prolog, firstline=34, lastline=40]{../ASP/eq/gcd.lp}
\mbox{} \\
Which cover both cases $(X < Y)$ and $(X > Y)$ while also not being too simplistic. \\ \\
After running the learning task, the resulting Answer Set contains the terms: \\

\begin{lstlisting}
choose(1,2).
choose(2,150, 0).
choose(3,159, 1, 1).
\end{lstlisting}
\mbox{} \\
These terms correspond to the following skeleton rules : \\

\begin{lstlisting}
rule(R, gcd, (N0, N1), N0) :- is_call(call(gcd, (N0, N1))), choose(R, 2).

rule(R, gcd, (N0, N1), call(gcd, ((N0 - N1), (N1 - 0)))) :-
		is_call(call(gcd, (N0, N1))),
		choose(R, 150, 0).

rule(R, gcd, (N0, N1), call(gcd, ((N1 * 1), (N0 * 1)))) :-
		is_call(call(gcd, (N0, N1))),
		choose(R, 190).
\end{lstlisting}
\mbox{} \\
Which then corresponds to the Haskell program (simplified for readability):

\begin{lstlisting}
gcd x y
	| x == y = x
	| x > y	 = gcd (x - y) y
	| x < y	 = gcd y x
\end{lstlisting}
\mbox{} \\
What is interesting is that whilst it has not learned the exact target program, the learned program is still correct. This is due to the optimisations preferring rules with shorter bodies.\\ \\
To see why this result is returned, it is useful to look at the corresponding \lstinline{eq} predicates for each example. \\ \\%{
The example \lstinline{example(call(gcd,(8,12)),4)} produces the terms :\\ %{
\begin{multicols}{2}
\begin{lstlisting}
eq(call(gcd,(8,12)),4).
eq(call(gcd,(12,8)),4).
eq(call(gcd,(4,8)),4).
eq(call(gcd,(8,4)),4).
eq(call(gcd,(4,4)),4).
eq(4, 4).
next_step(e,call(gcd,(8,12))).
next_step(call(gcd,(8,12)),call(gcd,(12,8))).
next_step(call(gcd,(12,8)),call(gcd,(4,8))).
next_step(call(gcd,(4,8)),call(gcd,(8,4))).
next_step(call(gcd,(8,4)),call(gcd,(4,4))).
next_step(call(gcd,(4,4)),4).
\end{lstlisting}
\end{multicols}
\mbox{}\\
Because these terms are all created without constraints failing, the respective rule bodies are returned as a solution.

\section{Performance}
While this new approach does perform better than the old one, it still suffers from a lot of the same issues limiting performance. \\ \\
Because of the large number of combinations of skeleton rules, they can still grow very large very quickly, lowering the performance of my tool. In addition, expanding the language bias to different types also has an adverse effect on this.

\subsection{Reducing the language bias}
As a way to deal with the explosive expansion of skeleton rules, I implemented a way to help contain this by artificially limiting the language bias. \\ \\
By removing operations from the bias that will not be used in the output functions, the tool can remove a large number of skeleton rules that will have no effect on the output of the learning task. In a similar way, learning can be limited to only tail recursive programs, meaning that the skeleton rules only use inbuilt arithmetic operations, further increasing performance. \\ \\
Of course, this method for improving performance is limited by the knowledge of the user. If they have no idea what the output function will look like, this is completely unhelpful, but in many cases they may have even a small idea of what operations will be used. Alternatively, users can iteratively add operations to the background knowledge, starting with a minimal set and gradually increasing it until a valid solution is found.

\pagebreak
\section{Full ASP Listing}
\lstinputlisting[firstline=32, firstnumber=32]{../ASP/eq/eq_rules.lp}

\pagebreak
%\renewcommand\bibname{{References}}
%\bibliography{References}
%\bibliographystyle{plain}


\begin{figure}
\begin{center}
\includegraphics[width=0.9\textwidth]{figs/inferred_props.pdf}
\caption{
    Comparison between the true galaxy properties, $\theta_{\rm true}$, and
    those inferred from SED modeling of mock observations, $\hat{\theta}$.
    From the left to right columns, we compare $\log M_*$, $\log \avgsfr$,
    $\log Z_{\rm MW}$, $\tage$ and $\tauism$.
    The inferred galaxy properties are derived from SED modeling of mock
    spectra (top), photometry (middle), and spectrophotometry (bottom).
    \edits{
        For each simulated galaxy, we plot 10 samples drawn from the
        marginalized posterior of $\theta$.
        We also include violin plots, whose widths represent the marginalized
        posteriors, for a handful of randomly selected galaxies.
    }
    \emph{The posteriors demonstrate that, overall, we can derive accurate and
    precise constraints on certain galaxy properties from joint SED modeling of
    DESI photometry and spectra.}
    } \label{fig:prop_inf}
\end{center}
\end{figure}

\section{Results} \label{sec:results}
%\subsection{Inferred Galaxy Properties}
The goal of this work is to demonstrate the precision and accuracy of inferred
galaxy properties for PROVABGS.
We apply our SED modeling to the mock observables of 2,123 \lgal~galaxies.
From the posterior distributions of the SPS parameters, we derive the following
physical galaxy properties: stellar mass ($M_*$), SFR averaged over 1 Gyr
($\avgsfr$), mass-weighted stellar metallicity ($Z_{\rm MW}$), mass-weighted
stellar age ($\tage$), and diffuse-dust optical depth ($\tau_{\rm ISM}$).
$M_*$ and $\tau_{\rm ISM}$ are SPS model parameters, while $\avgsfr$,
$Z_{\rm MW}$, and $\tage$ are derived as
\begin{equation} \label{eq:prop_eqs}
    \avgsfr = \frac{\int\limits_{t_{\rm age} - {\rm 1 Gyr}}^{t_{\rm age}}{\rm
    SFH}(t)\,{\rm d}t}{{\rm 1 Gyr}}, \quad
    Z_{\rm MW} = \frac{\int\limits_0^{t_{\rm age}}{\rm SFH}(t)\,{\rm
    ZH}(t)\,{\rm d}t}{M_*}, \quad{\rm and}\quad
    \tage = \frac{\int\limits_0^{t_{\rm age}}{\rm SFH}(t)\,t\,{\rm d}t}{M_*}.
\end{equation}

In Figure~\ref{fig:prop_inf}, we compare the galaxy properties inferred from
SED modeling the mock observations, $\hat{\theta}$, to the true (input) galaxy
properties, $\theta_{\rm true}$, of the simulated galaxies.
From left to right, we compare $\log M_*$, $\log \avgsfr$, $\log Z_{\rm MW}$,
$\tage$, and $\tauism$ in each column.
The inferred properties in the top, middle, and bottom rows are derived from
SED modeling of spectra, photometry, and spectrophotometry, respectively.
\edits{
    In each panel, we represent $\hat{\theta}$ by plotting 10 samples from the
    marginalized posterior for each simulated galaxy.
    We also include violin plots of  $\hat{\theta}$, where the width of the
    marker represents the marginalized posterior distribution of $\theta$, for
    a handful of randomly selected galaxies.
    We note that in our SED modeling of spectra only, we do not include
    $f_{\rm fiber}$ so the true stellar mass in this case corresponds to
    $f_{\rm fiber} \times M_*$, which has a different range than for the
    photometry and spectrophotometry cases.
}
The comparison demonstrates that \emph{overall we robustly infer galaxy
properties using the {\sc PROVABGS} SED modeling}.

In more detail, we find that we infer unbiased and precise constraints on
$M_*$ throughout the entire $M_*$ range.
%For spectra+photometry SED modeling, the posteriors have $\sigma_{M_*}\sim0.06$ dex.
We also infer robust $\avgsfr$ above $\log \avgsfr > -1$ dex; below this limit,
however, the inferred $\avgsfr$ are significantly less precise and
overestimate the true $\avgsfr$.
This bias at low $\avgsfr$ is caused by model priors, which we discuss in
further detail later in Section~\ref{sec:discuss} and
Appendix~\ref{sec:model_priors}.
Both $Z_{\rm MW}$ and $\tage$ are not precisely constrained.
\edits{
    The violin plots suggest that the inferred $Z_{\rm MW}$ overestimate the
    true $Z_{\rm true}$.
}
For $\tage$, the posteriors are less precise for galaxies with older stellar
populations and they reveal the log-spaced $\tlb$ binning used in our
SPS model for $\tage > 6$ Gyr.
Lastly, $\tauism$ is overall accurately inferred for galaxies with low
$\tauism$ but appears to be underestimated for high $\tauism$.

The overall constraints on galaxy properties for the mock observations is
encouraging due to the significant differences in the forward model used to
generate the observations and the SPS model used in the SED modeling.
First, the SFHs and ZHs in the mock observations are taken directly from
\lgal~simulation outputs while the SFH and ZH parameterization in the SPS model
is based on NMF bases fit to Illustris galaxies.
Second, in the forward model, we construct the SED of the bulge and disk
components of the simulated galaxies separately: the components have separate
SFHs and ZHs.
The SPS model treats all galaxies as having one component.
Lastly, we use different dust prescriptions: \cite{mathis1983} dust
attenuation curve in the forward model and \cite{kriek2013} dust attenuation
curve in the SPS model.
Despite these significant differences, our constraints on certain galaxy
properties are unbiased and precise.

Figure~\ref{fig:prop_inf}, also highlights the advantages of jointly modeling
spectra and photometry.
Comparing the constraints from spectrophotometry (bottom) versus photometry
alone (middle), we find that including spectra significantly tightens the
constraints for all properties.
In addition, including spectra also appears to reduce biases of the
constraints.
For instance, with only photometry, we derive significantly more biased
$\avgsfr$ constraints.
This is due to the limited constraining power of photometry, which allows the
posteriors to be dominated by model priors.
Adding spectra, significantly increases the contribution of the likelihood and
ameliorates this effect.
%Therefore, joint SED modeling of spectra and photometry

Beyond qualitative comparisons of the posterior, we want to quantify the
precision and accuracy of the inferred galaxy properties.
Let $\Delta_{\theta,i}$ be the discrepancy between the inferred and true
parameters for each galaxy:
$\Delta_{\theta,i} = \hat{\theta}_i - \theta^{\rm true}_i$.
Then, if we assume that $\Delta_{\theta,i}$ are sampled from a Gaussian
distribution,
\begin{equation} \label{eq:eta_gauss}
    \Delta_{\theta,i} \sim \mathcal{N}(\mu_{\Delta_{\theta}}, \sigma_{\Delta_{\theta}}),
\end{equation}
the mean ($\mu_{\Delta_{\theta}}$) and standard deviation
($\sigma_{\Delta_{\theta}}$) of the distribution are population hyperparameters
that represent the accuracy and precision of the inferred posteriors for the
galaxy population.
We can infer $\mu_{\Delta_{\theta}}$ and $\sigma_{\Delta_{\theta}}$ using a
hierarchical Bayesian framework~\citep[\emph{e.g.}][]{hogg2010,
foreman-mackey2014, baronchelli2020}.

Let $\{{\bfi X}_i\}$ represent the photometry or spectrum of a galaxy
population and $\eta_\Delta = \{\mu_{\Delta_{\theta}},
\sigma_{\Delta_{\theta}}\}$ represent the population hyperparameters.
Our goal is to constrain $\eta_\Delta$ from $\{{\bfi X}_i\}$ --- \emph{i.e.}
to infer $p(\eta_\Delta \given \{{\bfi X}_i\})$.
We expand
\begin{align}\label{eq:popinf}
p(\eta_\Delta \given \{{\bfi X_i}\})
    =&~\frac{p(\eta_\Delta)~p( \{{\bfi X_i}\} \given \eta_\Delta)}{p(\{{\bfi X_i}\})}\\
    =&~\frac{p(\eta_\Delta)}{p(\{{\bfi X_i}\})}\int p(\{{\bfi X_i}\} \given \{\theta_i\})~p(\{\theta_i\} \given \eta_\Delta)~{\rm d}\{\theta_i\}.
\intertext{
    $\theta_i$ is the SPS parameters for galaxy $i$ and $p(\{{\bfi X_i}\}
    \given \{\theta_i\})$ is likelihood of the set of observations $\{{\bfi
    X_i}\}$ given the set of $\{\theta_i\}$.
    Since the likelihoods for each of the $N$ galaxies, $p(\bfi X_i \given
    \theta_i)$, are not correlated, we can factorize and write the expression
    above as
}
    =&~\frac{p(\eta_\Delta)}{p(\{{\bfi X_i}\})}\prod\limits_{i=1}^N\int p({\bfi X_i} \given \theta_i)~p(\theta_i \given \eta_\Delta)~{\rm d}\theta_i\\
    =&~\frac{p(\eta_\Delta)}{p(\{{\bfi X_i}\})}\prod\limits_{i=1}^N\int
    \frac{p(\theta_i \given {\bfi X_i})~p({\bfi X_i})}{p(\theta_i)}~p(\theta_i
    \given \eta_\Delta)~{\rm d}\theta_i\\
    =&~p(\eta_\Delta)\prod\limits_{i=1}^N\int \frac{p(\theta_i \given {\bfi
    X_i})~p(\theta_i \given \eta_\Delta)}{p(\theta_i)}~{\rm d}\theta_i.
\intertext{
    $p(\theta_i \given {\bfi X_i})$ is the posterior for an individual galaxy,
    so the integral can be estimated using the Monte Carlo samples from the
    posterior:
}
    \approx&~p(\eta_\Delta)\prod\limits_{i=1}^N\frac{1}{S_i}\sum\limits_{j=1}^{S_i}
    \frac{p(\theta_{i,j} \given \eta_\Delta)}{p(\theta_{i,j})}.
    \label{eq:popinf2}
\end{align}
$S_i$ is the number of posterior samples and $\theta_{i,j}$ is the $j^{\rm th}$
sample of galaxy $i$.
$p(\theta_{i,j} \given \eta_\Delta) = p(\Delta_{\theta,i,j} \given
\eta_\Delta)$ is a Gaussian distribution and, hence, easy to evaluate.
$p(\theta_{i,j}) = 1$ since we use uninformative and Dirichlet priors
(Table~\ref{tab:params}).
Finally, we derive the maximum a posteriori (MAP) value of $\eta_\Delta$ by
maximizing the $p(\eta_\Delta \given \{{\bfi X_i}\})$ posterior distribution.
This type of population inference is a major advantage of inferring full
posteriors distributions of the galaxy properties.
We discuss the derivation and interpretation of the hyperparameters in more
detail in Appendix~\ref{sec:hyper}.

\begin{figure}
\begin{center}
    \includegraphics[width=0.85\textwidth]{figs/etas_v2.pdf}
    \caption{
        The accuracy and precision of galaxy property posteriors from our
        joint SED modeling of spectrophotometry, quantified using population
        hyperparameters $\eta_\Delta = \{\mu_{\Delta_{\theta}},
        \sigma_{\Delta_{\theta}}\}$, as a function of true galaxy property
        (green).
        We plot $\theta_{\rm true} + \mu_{\Delta_{\theta}}$ in solid line and
        represent $\sigma_{\Delta_{\theta}}$ with the shaded region.
        We include $\eta_\Delta$ for SED modeling of photometry alone (orange)
        for comparison.
        Including DESI spectra significantly improves both the accuracy and
        precision of the inferred galaxy properties.
        $\log\avgsfr$, $\log Z_{\rm MW}$, and $\tage$ constraints are
        significantly impacted by  priors imposed by the SPS model
        (Appendix~\ref{sec:model_priors}).
        Discrepancies in the dust prescriptions between our SPS model and the
        mock observations drive the bias in $\tauism$.
        Nevertheless, \emph{we accurately and precisely infer: $\log M_*$ for
        all $M_*$, $\log\avgsfr$ above $\log\avgsfr > -1\,{\rm dex}$, and
        $\tage$ below $8\,{\rm Gyr}$.}
        } \label{fig:etas}
\end{center}
\end{figure}

In Figure~\ref{fig:etas}, we present the accuracy ($\mu_{\Delta_{\theta}}$) and
precision ($\sigma_{\Delta_{\theta}}$) of our joint SED modeling of spectra and
photometry (green) as a function of true galaxy property.
$\mu_{\Delta_{\theta}}$ (solid) and $\sigma_{\Delta_{\theta}}$ (shaded region)
are the MAP values of $p(\eta_\Delta \given \{{\bfi X_i}\})$ posterior.
In each panel, we derive $p(\eta_\Delta \given \{{\bfi X_i}\})$ for
$\log M_*$, $\avgsfr$, $\log Z_{\rm MW}$, $\tage$, and $\tauism$ in bins of
widths 0.2 dex, 0.5 dex, 0.05 dex, 0.5 Gyr, and 0.1, respectively.
We only include bins with more than ten galaxies.
For comparison, we include $\eta_\Delta$ for SED modeling of photometry alone
(orange).
We also include $\eta_\Delta$ for $\log\zmw$ of galaxies with $r_{\rm fiber} >
20$ (black dot-dashed) and $\eta_\Delta$ for $\tauism$ of galaxies
without bulges (black dotted), which we discuss later.

\begin{figure}
\begin{center}
    \includegraphics[width=0.95\textwidth]{figs/etas_photo.pdf}
    \caption{
        Accuracy and precision of the galaxy properties inferred from joint SED
        modeling of spectrophotometry as a function of $r_{\rm fiber}$, $r$,
        $g-r$, and $r-z$.
        $r_{\rm fiber}$ and $r$ magnitudes are proxies for spectral and
        photometric SNR.
        From the top to bottom rows, we present $\eta_\Delta$ for $\log M_*$,
        $\log\avgsfr$, $\log Z_{\rm MW}$, $t_{\rm age, MW}$ and
        $\tau_{\rm ISM}$.
        We find a significant dependence on spectral SNR in the inferred
        $\log \zmw$.
        When the spectral SNR is low ($r_{\rm fiber} > 20$), the prior on
        $\log \zmw$ imposed by the SPS model dominate the posterior and
        cause $Z_{\rm MW}$ to be overestimated.
        We find a significant color dependence on $\log\avgsfr$, $\log Z_{\rm
        MW}$, and $\tage$.
        For $\log\zmw$ and $\tage$, the dependence is driven by underlying
        correlations with spectral SNR and true $\tage$.
        Meanwhile, $\log\avgsfr$ is overestimated for the reddest galaxies with
        $r - z > 0.6$, which correspond to quiescent galaxies with $\log\avgsfr
        < -1$ dex.
        Otherwise we find no significant dependence on SNR or optical color.
    }
    \label{fig:eta_photo}
\end{center}
\end{figure}

In Figure~\ref{fig:eta_photo}, we examine how the accuracy and precision of
our galaxy parameter constraints are impacted by signal-to-noise ratio (SNR) or
photometric color.
We present $\eta_\Delta$ of our joint SED modeling of spectra and photometry as
a function of $r_{\rm fiber}$, $r$, $g-r$, and $r-z$.
$r_{\rm fiber}$ and $r$ magnitudes serve as proxies of the SNR for the spectra
and photometry, respectively.
In each row, we plot $\eta_\Delta$ for a different galaxy property: $\log M_*$,
$\avgsfr$, $\log Z_{\rm MW}$, $\tage$ and $\tauism$ (from top to bottom).

\begin{figure}
\begin{center}
    \includegraphics[width=\textwidth]{figs/etas_msfr.pdf}
    \caption{
        Accuracy and precision of the galaxy properties inferred from joint SED
        modeling of spectrophotometry as a function of the galaxies' true $M_*$
        and $\avgsfr$.
        We present $\mu_{\Delta_{\theta}}$ and $\sigma_{\Delta_{\theta}}$ in
        ($M_*$, $\avgsfr$) bins for $\log M_*$, $\log\avgsfr$, $\log Z_{\rm
        MW}$, $t_{\rm age, MW}$ and $\tau_{\rm ISM}$ in the top and bottom
        panels respectively.
        $\log M_*$ is accurately and precisely constrained for all types of galaxies.
        $\log\avgsfr$ is accurately and precisely constrained for all galaxies
        except for quiescent galaxies with $\log\avgsfr < -1$ dex.
        $\log\zmw$ is overestimated for star-forming galaxies, due to their
        overall lower spectral SNR.
        $\tage$ is accurately and precisely constrained for star-forming
        galaxies that have overall younger stellar populations.
        $\tauism$ is accurately and precisely constrained for all galaxies
        except massive star-forming galaxies, which have high true $\tauism$.
    }\label{fig:etas_msfr}
\end{center}
\end{figure}

Lastly, in Figure~\ref{fig:etas_msfr}, we investigate whether there is any
underlying dependence in the inferred galaxy properties on the
$M_*$-${\rm SFR}$ plane.
In the top and bottom panels, we present $\mu_{\Delta_{\theta}}$ and
$\sigma_{\Delta_{\theta}}$ in $(\log M_*, \log\avgsfr)$ bins for
$\log M_*$, $\log\avgsfr$, $\log Z_{\rm MW}$, $\tage$ and $\tauism$ (left to
right).
We use $\log M_*$ bins of width 0.225 dex and $\log\avgsfr$ bins of width
0.25 dex for $\log \avgsfr > 0$ dex and 0.5 dex for $\log \avgsfr < 0$ dex.
We only present bins with more than 10 galaxies.
On the $M_*-{\rm SFR}$ plane, we can examine whether the accuracy and precision
of the inferred properties have significant dependencies for galaxy type.

Based on Figures~\ref{fig:etas}, \ref{fig:eta_photo}, and~\ref{fig:etas_msfr},
we draw the following conclusions on the accuracy and precision of the inferred
posteriors for each galaxy property:\\

% log M*
\noindent \underline{\emph{Inferred $\log M_*$}}:
Overall, we infer accurate and precise $\log M_*$ from the {\sc PROVABGS} SED
modeling.
There is no significant dependence in $\mu_{\Delta_{\theta}}$ and
$\sigma_{\Delta_{\theta}}$ with true $\log M_*$ throughout the $M_*$ range.
We accurately infer the true $M_*$ throughout ${\sim}10^{9}$- $10^{12} M_\odot$
with uniform precision of $\sigma_{\Delta_{\log M_*}}{\sim}0.1$ dex.
We also find no significant dependence on SNR for $M_*$ --- neither $r_{\rm
fiber}$ nor $r$ magnitudes significantly affect $\mu_{\Delta_{\log M_*}}$ and
$\sigma_{\Delta_{\log M_*}}$.
There is a noticeable correlation with $g-r$ and $r-z$ color, which also
appears in the $M_*-{\rm SFR}$ plane.
However, this correlation is small compared to the precision of our inferred
posterior on $\log M_*$.
When we compare the $\eta_\Delta$ from spectrophotometry to $\eta_\Delta$ from
photometry we find that including DESI spectra increases both the accuracy and
precision of the constraints, especially at high $M_* > 10^{11}M_\odot$. \\

% log SFR
\noindent \underline{\emph{Inferred $\log\avgsfr$}}:
We infer accurate $\log\avgsfr$ for galaxies with $\log\avgsfr > -1$ dex with
${\sim} 0.1$ dex precision.
In fact, we find a $\log \avgsfr \sim -1$ dex lower bound for the inferred
$\log \avgsfr$.
Below this limit, we significantly overestimate $\log \avgsfr$, consistent with
the bias in Figure~\ref{fig:prop_inf}, and the constraints are also
significantly broader with $\sigma_{\Delta_{\log M_*}}{\sim}0.25 - 0.3$ dex.
Comparing $\mu_{\Delta_{\theta}}$ and $\sigma_{\Delta_{\theta}}$ from
spectrophotometry versus from only photometry, we confirm that including
spectra significantly improves the accuracy and tightens the $\log\avgsfr$
constraints.
For $\avgsfr$ below $\log\avgsfr < -1$ dex, including spectra reduces the bias
${\sim}1$ dex --- an order of magnitude.

We find no significant correlation between the accuracy and precision of
$\avgsfr$ with spectral or photometric SNR.
However, there is a more significant color dependence where we overestimate
$\log\avgsfr$ by $\mu_{\Delta_{\log\avgsfr}}{>}0.5$ dex for the reddest galaxies
($g-r > 1.5$ and $r-z> 0.6$).
The constraints for these galaxies are also significantly less precise:
$\sigma_{\Delta_{\log\avgsfr}} \sim 0.5$ dex.
The bias is also apparent in Figure~\ref{fig:etas_msfr}: there is significant
bias in the inferred for quiescent galaxies where we overestimate $\avgsfr$.
$\avgsfr$ is also slightly underestimated for the most massive ($M_* >
10^{11}M_\odot$) star-forming galaxies.
These biases are consequences of our SPS model priors.
$\avgsfr$ is a derived quantity; hence, the uninformative priors we impose on
SPS parameters induce non-uniform priors on them.
Our SPS model imposes a prior on $\log \overline{\rm SSFR}_{\rm 1 Gyr}$
that is skewed towards the peaks at $\sim$-10.4 dex
(Appendix~\ref{sec:model_priors}, Figure~\ref{fig:model_prior}).
Consequently, the posterior overestimates $\avgsfr$ at low $\avgsfr$ (red,
quiescent galaxies) and underestimates $\avgsfr$ at the highest $\avgsfr$. \\

% log Z_MW
\noindent \underline{\emph{Inferred $\log\zmw$}}:
Unlike in Figure~\ref{fig:prop_inf}, $\eta_\Delta$ in Figure~\ref{fig:etas}
clearly reveals the accuracy and precision of the posteriors on $\log\zmw$.
We find that $\mu_{\Delta_{\theta}}$ depends significantly on the true $\zmw$:
inferred $\log\zmw$ is overestimated by ${\sim}0.2$ dex below $\log\zmw <
-2$ dex and slightly underestimated at the highest $\log\zmw > -1.6$ dex.
$\sigma_{\Delta_\theta} \sim 0.15$ dex is uniform throughout the $\zmw$ range.
Similar to $\avgsfr$, the bias in inferred $\zmw$ is a consequence of our SPS
model priors.
The prior skews $\log\zmw$ constraints towards the peak of the prior at
$\log\zmw\sim-1.5$.
Figure~\ref{fig:etas} also includes $\eta_\Delta$ for posteriors derived from
photometry alone (orange), which demonstrates that including DESI spectra
substantially improves the accuracy of the $\log\zmw$ constraints.
Spectra reduces the overall bias on $\zmw$ by $\sim$0.3 dex.
The improvement comes from the likelihood contribution from DESI spectra
reducing the relative contribution of the prior on the posterior.

This is also why we find that the posteriors overestimate $\log\zmw$ at
$r_{\rm fiber} > 20$ in Figure~\ref{fig:eta_photo}.
These correspond to mock observations with low spectral SNR where the
contribution of the likelihood from the spectra is reduced and the prior on
$\log\zmw$ has a larger effect.
The color dependence of $\mu_{\Delta_\theta}$ for $\zmw$ in
Figure~\ref{fig:eta_photo} is also a consequence of this spectral SNR
dependence; so is the $M_*-{\rm SFR}$ dependence in Figure~\ref{fig:etas_msfr}.
If we exclude galaxies with low spectral SNR, both the color and $M_*-{\rm
SFR}$  dependences are substantially reduced: for $r_{\rm fiber} < 20$
galaxies, we infer $\log\zmw$ with $\mu_{\Delta_\theta}<0.15$ dex and
$\sigma_{\Delta_\theta}\sim0.1$ (Figure~\ref{fig:etas}; black dot-dashed).
The posteriors on $\zmw$ further underscore the constraining power of DESI
spectra. \\

% t_age, MW
\noindent \underline{\emph{Inferred $\tage$}}:
Figure~\ref{fig:etas} confirms that we derive unbiased and precise constraints
on $\tage$ out to $\tage < 8$ Gyr.
Below this limit, we infer $\tage$ with $\sigma_{\Delta_\theta}{\sim}0.5$ Gyr.
For galaxies with older stellar populations above this limit, the log-spaced
$\tlb$ binning in our SPS model (Section~\ref{sec:sps}) expectedly
underestimates $\tage$ constraints and produces larger uncertainties
($\sigma_{\Delta_{\tage}} \gtrsim 1$ Gyr).
Meanwhile, we find no significant SNR or color dependence in
Figure~\ref{fig:eta_photo}.
At $r - z > 0.6$, $\tage$ is underestimated, but this is driven by the
correlation between $r-z$ and true $\tage$: the simulated galaxies with $r - z
> 0.6$ in our sample have overall older stellar populations.
In Figure~\ref{fig:etas_msfr}, we do not find a clear $M_*-{\rm SFR}$
dependence; however, $|\mu_{\Delta_{\tage}}|$ is larger and constraints are
significantly less precise for galaxies with older stellar populations below
the star-forming sequence.  \\

\noindent \underline{\emph{Inferred $\tauism$}}:
Lastly, we find that both the accuracy and precision of our $\tauism$ depend
significant only on the true $\tauism$ value.
The inferred constraints increasingly underestimate $\tauism$ with lower
precision for greater $\tauism$.
The bias is due to discrepancies between the dust prescriptions of SPS model
and the mock observations.
First, we use a dust prescription with a different attenuation curve in the SPS
model than in the forward model.
This places a strict limit on how accurately we can derive $\tauism$.
We intentially introduce this discrepancy since we do not know the ``true''
attenuation curve of observed galaxies in practice.
Another reason for the biased $\tauism$ constraints is that we only attenuate
the stellar emission in the disk component of the simulated galaxies and not
the bulge component (Section~\ref{sec:sed}).
The true $\tauism$ is the optical depth for the disk component while our
$\tauism$ constraints correspond to the optical depth of dust attenuation
for the entire galaxies, a quantity that will be lower than the true $\tauism$
depending on how much the bulge contributes to the SED.
Given these discrepancies, in this work we are primarily testing whether the
{\sc PROVABGS} SPS modeling can successfully marginalize over the effect of
dust and derive robust constraints on the other galaxy properties.

Nevertheless, we find no significant SNR or color dependence on the accuracy
and precision of $\tauism$ constraints (Figure~\ref{fig:eta_photo}).
Furthermore, we find unbiased and precise $\tauism$ constraints for all galaxies
except star-forming galaxies above $M_* > 10^{11}M_\odot$ where we underestimate
$\tauism$.
Massive star-forming galaxies in this regime mainly have $\tauism > 1$.
In Figure~\ref{fig:etas}, we present a more apples-to-apples comparison of the
$\tauism$ constraints, where we present $\eta_\Delta$ for only galaxies without
bulge contributions (black dotted).
For these galaxies, the bias in our $\tauism$ constraints is reduced and
$\mu_{\Delta_\theta}<0.5$ throughout the $\tauism$ range.
Our constraints are still biased, however, due to the discrepant attenuation
curves.
We emphasize that the primary goal of dust prescription in our SPS model is to
marginalize out the effect of dust.
Based on the accuracy and precision of the constraints on other galaxy
properties, the {\sc PROVABGS} SPS model achieves this objective.


\section{Theoretical Foundations}
\label{sec:Theoretical_Foundations}
In this experiment the Planck constant $h$ was determined. This is a physical constant that relates the frequency of a photon to the energy it carries. This section summarizes the theory and formulas necessary to understand the following experiments on ultrasound in section \ref{sec:Evaluation}.

%-------------------------------------------------------------------------------------------
\subsection{Electromagnetic Radiation}
\label{subsec:Electromagnetic_Radiation}
The various effects that occur during the propagation and interaction of electromagnetic radiation with material objects can be classified into wave and particle phenomena:

\textbf{Wave Phenomena:} Interference and diffraction are described by the wave theory of electromagnetic radiation. From this point of view, the radiation occurs in the form of electromagnetic waves, which can be represented by a continuous wave function \cite{light_quantum}.

\begin{equation}
c = \lambda\cdot f
\label{eq:wave_length_frequency}
\end{equation}
where:
\begin{multicols}{2}
	\begin{center}
		\begin{conditions}
			c & speed of light in $\,^{\text{m}}\!/_{\text{s}}$ \\
			\lambda & wave length in m
		\end{conditions}
		\begin{conditions}
			f & frequency in Hz
		\end{conditions}
	\end{center}
\end{multicols}

\textbf{Particle Phenomena:} Emission and absorption are described by the quantum theory of electromagnetic radiation. From this point of view, the radiation occurs in the form of photon current $\gamma$ (also called light quantum), which interacts with single atoms, electrons etc. in individual quantum processes. This is subject to chance, which is why only probability statements can be made \cite{light_quantum}.

\begin{equation}
E_\gamma = h\cdot f = h\cdot\frac{c}{\lambda}
\label{eq:energy_particle}
\end{equation}
where:
\begin{multicols}{2}
	\begin{center}
		\begin{conditions}
			E_\gamma & photon energy in J \\
			h & Planck constant in J$\cdot$s \\
			f & frequency in Hz
		\end{conditions}
		\begin{conditions}
			c & speed of light in $\,^{\text{m}}\!/_{\text{s}}$ \\
			\lambda & wave length in m
		\end{conditions}
	\end{center}
\end{multicols}

Energy and impulse exchange between radiation and matter can only take place in such quanta. Equation \ref{eq:energy_particle} shows that the magnitude is essentially determined by the Planck constant $h$ (also known as Planck's quantum of action) \cite{light_quantum}.

Since the 20\textsuperscript{th} May 2019 the value of the Planck constant $h$ is exactly
\begin{equation}
h = 6.626\ 070\ 15 \cdot 10^{-34}\ \si{J}\cdot\si{s}.
\label{eq:plank_constant}
\end{equation}
The value of the Planck constant $h$ has been fixed due to the redefinition of the kilogram \cite{planck_constant}.

The two illustrative models are in principle incompatible. On the one hand the wave, the most smudgy thing there is. On the other hand the particle, the most concentrated thing there is. The solution to this dilemma is known as wave-particle duality, which is a concept in quantum mechanics. It expresses the inability to fully describe the behavior of quantum-scale objects with the classical concepts \flqq wave\frqq\ or \flqq particle\frqq\ \cite{light_quantum, wave_particle_duality}.

\newpage
%-------------------------------------------------------------------------------------------
\subsection{Photoelectric Effect}
\label{subsec:Photoelectric_Effect}
The photoelectric effect is the absorption of light quanta by atoms, molecules or solids, in which the photon disappears and transfers part of its energy to an electron. In the case of atoms and molecules, free electrons with kinetic energy $E_k = E_\gamma - E_B$ are formed in the first moment, which can then attach themselves to other particles. $E_B$ is the binding energy of an electron. However, the atoms involved in the process are much heavier, so the energy of these electrons can be neglected. In the case of interaction with solids, a distinction is made between the outer photoelectric effect and the inner photoelectric effect \cite{light_quantum}.

%-------------------------------------------------------------------------------------------
\subsubsection{Outer Photoelectric Effect}
\label{subsubsec:Outer_Photoelectric_Effect}
The light quanta knock photoelectrons out of the surface of metals, metal oxides and semiconductors. To release an electron, its binding energy has to be expended. This binding energy is called the electron work function $W_a$. The photo energy $E_\gamma$ must be at least equal to the electron work function $W_a$ for this effect to occur. The process takes in a thin surface layer place, which corresponds to the penetration depth of the photons. Therefore, the photoelectrons suffer different energy losses and leave the surface with variable kinetic energy \cite{light_quantum}.

\begin{equation}
\widehat{E}_k = E_\gamma - W_a = h\cdot f - W_a
\label{eq:outer_photoelectric_effect}
\end{equation}
where:
\begin{multicols}{2}
	\begin{center}
		\begin{conditions}
			\widehat{E}_k & max. kinetic energy in eV \\
			E_\gamma & photon energy in eV \\
			W_a & electron work function in eV
		\end{conditions}
		\begin{conditions}
			h & Planck constant in J$\cdot$s \\
			f & frequency in Hz
		\end{conditions}
	\end{center}
\end{multicols}

Equation \ref{eq:outer_photoelectric_effect} shows the calculation of the maximum value of this kinetic energy. The electron work function is a surface property and only material-specific at extremely high purity. Absorbed contaminants such as gases, oxide films and other impurities can change the value significantly.Layers used to convert radiation into a photoelectron stream are called photocathodes. If such a layer is combined with a multiplier (resulting in a photomultiplier) a very sensitive radiation detector is obtained \cite{light_quantum}.

%-------------------------------------------------------------------------------------------
\subsubsection{Inner Photoelectric Effect}
\label{subsubsec:Inner_Photoelectric_Effect}
The light quanta that penetrate a semiconductor prodce additional charge carriers. It can be distinguished between photoconductors and photodiodes \cite{light_quantum}.

\textbf{Photoconductors:} When irradiated, the charge carrier density and thus the conductivity increase. This is why they are sometimes also called photo resistors \cite{light_quantum}.

\textbf{Photodiodes:} In the region of the p-n junction, the absorbed photons generate electron-hole pairs. Without an external source, the p-side is positively charged and the n-side is negatively charged, resulting in a photovoltage. This photovoltag can be as high as the diffusion voltage $U_d$. A corresponding current flows under load. Solar cells use this element operation. If an external voltage is applied in the reverse direction, a photocurrent flows in this direction. This current is proportional to the incident radiant power. This diode operation is used for photodetectors. The described processes only take place when the photon energy exceeds a material-specific threshold value, which is the release of an electron bound to the crystal lattice \cite{light_quantum}.

\newpage
%-------------------------------------------------------------------------------------------
\subsection{Counter-Field Method (Millikan)}
\label{subsec:Countervailing_Field_Method}
The counter-field method can be used to determine the kinetic energy of the photoelectrons. Figure \ref{fig:millikan} displays this graphically. The photocathode $K$ to be investigated and the anode $A$, which serves as a collector for the photoelectrons, are located in an evacuated glass bulb. The electrons triggered by monochromatic light of wavelength $\lambda$ have a maximum kinetic energy as shown in equation \ref{eq:outer_photoelectric_effect} \cite{light_quantum}.

\begin{figure}[H]
	\centering
	\includegraphics[scale=2]{millikan}
	\caption{This figure shows how the counter-field method is used to determine the kinetic energy of the photoelectrons. The voltage $U$ is increased until the current $I_{ph}$ reaches zero. As soon as the current $I_{ph} = 0$, the voltage $U$ must be equal to the voltage $U_{KA}$ \cite{light_quantum}.}
	\label{fig:millikan}
\end{figure}

If the voltage between anode and cathode is positive, the electrons are still accelerated and the full photocurrent flows, determined by the incident radiation power. If an increasing countervoltage $U$ is applied, fewer and fewer electrons reach the anode until the photocurrent finally disappears at the critical countervoltage $U_o$. Due to the material-dependent contact potential $U_c$ that is present even without an external voltage between cathode and anode, the following equation \ref{eq:millikan} applies for zero photocurrent \cite{light_quantum}.

\begin{equation}
\widehat{E}_k = e\cdot (U_o - U_c)
\label{eq:millikan}
\end{equation}
where:
\begin{multicols}{2}
	\begin{center}
		\begin{conditions}
			\widehat{E}_k & max. kinetic energy in eV \\
			e & elementary charge ($\approx 1.602\cdot 10^{-19}\ \si{C}$)
		\end{conditions}
		\begin{conditions}
			U_o & critical counter-voltage in V \\
			U_c & contact potential in V
		\end{conditions}
	\end{center}
\end{multicols}

\newpage
%-------------------------------------------------------------------------------------------
\subsection{Light-Emitting Diode (LED)}
\label{subsec:light-emitting_diode}
The luminous emission of LEDs is caused by the fact that electrons pass from the conduction energy band to the valence energy band. This means that the electrons change from a higher to a lower energy state. In a regular diode this energy is dissipated as heat. In the case of a light-emitting diode, on the other hand, it is mostly released as light. Figure \ref{fig:led} shows this graphically. This process is the reversal process to the inner photoelectric effect \cite{light_quantum}.

The relationship between the photon energy and the characteristic curve of an LED is given by equation \ref{eq:led}. The diffusion voltage $U_d$ depends on the material, its doping and the geometric structure of the diode. Due to the fact, that light emitting diodes are highly doped, the Fermi energies are close to the band edges and $e\cdot U_d$ is approximately equal to the band gap $E_g$ (usually a little bit smaller). $U_d$ roughly corresponds to the threshold voltage $U_K$ of the characteristic curve. Therefore, equation \ref{eq:led_threshold} can be used as an approximation for the measurable threshold voltage and the wavelength of the emission of an LED \cite{light_quantum}.

\begin{equation}
e\cdot U_K \approx E_\gamma
\label{eq:led}
\end{equation}
thus:
\begin{equation}
U_K \approx \frac{h}{e}\cdot\frac{c}{\lambda}
\label{eq:led_threshold}
\end{equation}
where:
\begin{multicols}{2}
	\begin{center}
		\begin{conditions}
			U_K & LED threshold voltage in V \\
			E_\gamma & photon energy in eV \\
			e & elementary charge ($\approx 1.602\cdot 10^{-19} \si{C}$)
		\end{conditions}
		\begin{conditions}
			h & Planck constant in J$\cdot$s \\
			c & speed of light in $\,^{\text{m}}\!/_{\text{s}}$ \\
			\lambda & wave length in m
		\end{conditions}
	\end{center}
\end{multicols}

\begin{figure}[H]
	\centering
	\includegraphics[scale=1.2]{led}
	\caption{Graphical representation of the inner workings of an LED. The p-n junction emits light when electrons cross it. The free electrons move from the conduction band to the valence energy band (lower energy level). To recombine the electrons and the holes, some portion of the energy is dissipated in the form of heat and light (release of photons) \cite{led}.}
	\label{fig:led}
\end{figure}


\chapter{Demo cases}
\section{2D cavity flow at $\text{Kn}=0.075$}
\label{sec_cavity}
This demonstrational case is provided in the \verb|demos| subdirectory of the dugksFoam source code package.
This case is a popular benchmark problem for validating numerical method for micro or rarefied gas flows.
It has been studied in Ref.~\cite{zhulh15} using this solver,
where you can find the detailed description of this problem.
We only mention some setting that need special attention for a new user.
The mesh file and setting have already been prepared in the case directory.
So you can run the dugksFoam directly.

The flow configuration is illustrated in Fig.~\ref{ldc}.
The walls are diffusive boundaries.
For such a simple geometry, you can use the \verb|blockMesh| shipped with the OpenFOAM to generate the structured mesh.
Refer to the cavity flow tenurial case in the \emph{OpenFOAM User's Guide} for the detailed usage of \verb|blockMesh|.
The initial temperautre filed is uniform 273K, and the wall temperature is also 273K.
In this case, the Knudsen number Kn is 0.075 based on the initial density filed and the cavity width $L$.
So the mean free path is 0.075m.
The initial density field input in the \verb|0/rho| file should be calculated from the mean free path provided the argon gas properties.
Refer to ~\cite{zhulh15} for the related formulations.
We also provide a simple Python script named \verb|para.py| in the case's directory to compute the related parameters.
You can run it by \verb|python para.py|.

The discrete velocities used are $28\times28$ half-range Gauss-Hermite quadrature points.
The files \verb|constant/Xis| and \verb|constant/weights| can be generated by
\begin{verbatim}
    setDV.py GH 337.196399395 28
\end{verbatim}
where 28 is the number of discrete velocity in each direction, and 337.196399395 stands for the most probable speed of argon gas molecular at $T=273$K.
Refer to Sec.~\ref{sec_dv} for more details about settings of discrete velocities.

Fig.~\ref{ldc_UT} show some of the results of this case.
You can also compare the results with those in \cite{zhulh15} in detail.

\begin{figure}
  \centering
  % Requires \usepackage{graphicx}
  \includegraphics[width=0.4\textwidth]{img/ldc.pdf}
  \caption{Lid-driven cavity flow}\label{ldc}
\end{figure}

\begin{figure}[htbp]
\centering
\subfloat[]{\includegraphics[width=0.48\textwidth]{img/temperature.png}} ~
\subfloat[]{\includegraphics[width=0.48\textwidth]{img/U.png}}
\caption{
Results of the cavity flow case. (a) Temperature contours and heat flux. (b) Velocity magnitude and streamlines.
}\label{ldc_UT}
\end{figure}

% Local Variables:
% TeX-master: "dugksFoam"
% mode: latex
% mode: flyspell
% End:


    \filetitle{estimate}{Estimate model parameters by optimising selected objective function}{model/estimate}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
[PEst,Pos,Cov,Hess,M,V,Delta,PDelta] = estimate(M,D,Range,Est,...)
[PEst,Pos,Cov,Hess,M,V,Delta,PDelta] = estimate(M,D,Range,Est,SPr,...)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{M} {[} model {]} - Model object.
\item
  \texttt{D} {[} struct \textbar{} cell {]} - Input database or datapack
  from which the measurement variables will be taken.
\item
  \texttt{Range} {[} struct {]} - Date range.
\item
  \texttt{Est} {[} struct {]} - Database with the list of paremeters
  that will be estimated, and the parameter prior specifications (see
  below).
\item
  \texttt{SPr} {[} empty \textbar{} systempriors {]} - System priors
  object, \href{systempriors/Contents}{\texttt{systempriors}}.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\item
  \texttt{PEst} {[} struct {]} - Database with point estimates of
  requested parameters.
\item
  \texttt{Pos} {[} poster {]} - Posterior,
  \href{poster/Contents}{\texttt{poster}}, object; this object also
  gives you access to the value of the objective function at optimum or
  at any point in the parameter space, see the
  \href{poster/eval}{\texttt{poster/eval}} function.
\item
  \texttt{Cov} {[} numeric {]} - Approximate covariance matrix for the
  estimates of parameters with slack bounds based on the asymptotic
  Fisher information matrix (not on the Hessian returned from the
  optimisation routine).
\item
  \texttt{Hess} {[} cell {]} - \texttt{Hess\{1\}} is the total hessian
  of the objective function; \texttt{Hess\{2\}} is the contributions of
  the priors to the hessian.
\item
  \texttt{M} {[} model {]} - Model object solved with the estimated
  parameters (including out-of-likelihood parameters and common variance
  factor).
\end{itemize}

The remaining three output arguments, \texttt{V}, \texttt{Delta},
\texttt{PDelta}, are the same as the
\href{model/loglik}{\texttt{model/loglik}} output arguments of the same
names.

\paragraph{Options}\label{options}

\begin{itemize}
\item
  \texttt{'chkSstate='} {[} \texttt{true} \textbar{}
  \emph{\texttt{false}} \textbar{} cell {]} - Check steady state in each
  iteration; works only in non-linear models.
\item
  \texttt{'evalFrfPriors='} {[} \emph{\texttt{true}} \textbar{}
  \texttt{false} {]} - In each iteration, evaluate frequency response
  function prior density, and include it to the overall objective
  function to be optimised.
\item
  \texttt{'evalLik='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - In each iteration, evaluate likelihood (or another data based
  criterion), and include it to the overall objective function to be
  optimised.
\item
  \texttt{'evalPPriors='} {[} \emph{\texttt{true}} \textbar{}
  \texttt{false} {]} - In each iteration, evaluate parameter prior
  density, and include it to the overall objective function to be
  optimised.
\item
  \texttt{'evalSPriors='} {[} \emph{\texttt{true}} \textbar{}
  \texttt{false} {]} - In each iteration, evaluate system prior density,
  and include it to the overall objective function to be optimised.
\item
  \texttt{'filter='} {[} cell \textbar{} \emph{empty} {]} - Cell array
  of options that will be passed on to the Kalman filter including the
  type of objective function; see help on
  \href{model/filter}{\texttt{model/filter}} for the options available.
\item
  \texttt{'initVal='} {[} \texttt{model} \textbar{}
  \emph{\texttt{struct}} \textbar{} struct {]} - If \texttt{struct} use
  the values in the input struct \texttt{Est} to start the iteration; if
  \texttt{model} use the currently assigned parameter values in the
  input model, \texttt{M}.
\item
  \texttt{'maxIter='} {[} numeric \textbar{} \emph{\texttt{500}} {]} -
  Maximum number of iterations allowed.
\item
  \texttt{'maxFunEvals='} {[} numeric \textbar{} \emph{\texttt{2000}}
  {]} - Maximum number of objective function calls allowed.
\item
  \texttt{'noSolution='} {[} \emph{\texttt{'error'}} \textbar{}
  \texttt{'penalty'} {]} - Specifies what happens if solution or steady
  state fails to solve in an iteration: \texttt{'error='} stops the
  execution with an error message, \texttt{'penalty='} returns an
  extremely low value of the likelihood.
\item
  \texttt{'optimSet='} {[} cell \textbar{} \emph{empty} {]} - Cell array
  used to create the Optimization Toolbox options structure; works only
  with the option \texttt{'optimiser='} \texttt{'default'}.
\item
  \texttt{'refresh='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  {]} - Refresh dynamic links in each iteration.
\item
  \texttt{'solve='} {[} \emph{\texttt{true}} \textbar{} \texttt{false}
  \textbar{} cellstr {]} - Re-compute solution in each iteration; you
  can specify a cell array with options for the \texttt{solve} function.
\item
  \texttt{'optimiser='} {[} \emph{\texttt{'default'}} \textbar{}
  \texttt{'pso'} \textbar{} cell \textbar{} function\_handle {]} -
  Minimisation procedure.

  \begin{itemize}
  \item
    \texttt{'default'}: The Optimization Toolbox function
    \texttt{fminunc} or \texttt{fmincon} will be called depending on the
    presence or absence of lower and/or upper bounds.
  \item
    \texttt{'pso'}: The Particle Swarm Optimizer will be called; use the
    option \texttt{'pso='} to specify further options to control the
    optimizer (see Options for Particle Swarm Optimizer below).
  \item
    function\_handle or cell: Enter a function handle to your own
    optimisation procedure, or a cell array with a function handle and
    additional input arguments (see below).
  \end{itemize}
\item
  \texttt{'sstate='} {[} \texttt{true} \textbar{} \emph{\texttt{false}}
  \textbar{} cell \textbar{} function\_handle {]} - Re-compute steady
  state in each iteration; you can specify a cell array with options for
  the \texttt{sstate} function, or a function handle whose behaviour is
  described below.
\item
  \texttt{'tolFun='} {[} numeric \textbar{} \emph{\texttt{1e-6}} {]} -
  Termination tolerance on the objective function.
\item
  \texttt{'tolX='} {[} numeric \textbar{} \emph{\texttt{1e-6}} {]} -
  Termination tolerance on the estimated parameters.
\end{itemize}

\paragraph{Options for Particle Swarm
Optimizer}\label{options-for-particle-swarm-optimizer}

The following options can be specified through the main option
\texttt{'optimset='} when \texttt{'optimiser=pso'}.

\begin{itemize}
\item
  \texttt{'cognitiveAttraction='} {[} numeric \textbar{}
  \emph{\texttt{0.5}} {]} - Scalar between \texttt{0} and \texttt{1} to
  control the relative attraction to the best location a particle can
  remember.
\item
  \texttt{'constrBoundary='} {[} \texttt{absorb} \textbar{}
  \emph{\texttt{reflect}} \textbar{} \texttt{soft} {]} - Controls the
  way imposed constraints are handled when violated.

  \begin{itemize}
  \item
    \texttt{'soft'}: Particles are allowed to travel outside the bounds
    but get bad fitness function (likelihood) values when they do;
  \item
    \texttt{'reflect'}: Particle velocity is changed such that when the
    particle encounters the bound its velocity is changed to effectively
    make it bounce off of the boundary;
  \item
    \texttt{'absorb'}: Particles hit the bound and stay at the bound
    until attracted elsewhere because its velocity is set to zero.
  \end{itemize}
\item
  \texttt{'display='} {[} \texttt{'off'} \textbar{} \texttt{'final'}
  \textbar{} \emph{\texttt{'iter'}} {]} - Level of display in order of
  increasing verbosity; \texttt{'iter'} will only produce output at most
  \texttt{'updateInterval='} seconds.
\item
  \texttt{'fitnessLimit='} {[} numeric \textbar{} \emph{\texttt{-Inf}}
  {]} - Algorithm will terminate when a function value this low is
  encountered.
\item
  \texttt{'generations='} {[} numeric \textbar{} \emph{\texttt{1000}}
  {]} - Positive integer describing the maximum length of swarm
  evolution.
\item
  \texttt{'hybridFcn='} {[} \texttt{true} \textbar{}
  \emph{\texttt{false}} \textbar{} \texttt{'fmincon'} \textbar{}
  \texttt{'fminunc'} \textbar{} cell {]} - Run a second stage
  optimization after PSO (only available with the Optimization Tbx
  installed):

  \begin{itemize}
  \item
    \texttt{false}: No second stage optimization, run the particle swarm
    only.
  \item
    \texttt{true}: After PSO, run either \texttt{fminunc} or
    \texttt{fmincon}, the Optimization Toolbox routines, depending on
    the presence or absence of lower and upper bounds on estimated
    parameters.
  \item
    \texttt{'fminunc'}, \texttt{'fmincon'}: After PSO, run the specified
    Optimization Toolbox routine.
  \item
    cell: A cell array in which the first argument specifies the
    function as previously and the second argument contains the options
    structure for that function; for instance
    \texttt{\{@fmincon,optimset('Display','iter')\}}.
  \end{itemize}
\item
  \texttt{'includeInitialValue='} {[} \emph{\texttt{true}} \textbar{}
  \texttt{false} {]} - Include the initial vector of parameters in the
  initial population.
\item
  \texttt{'initialPopulation=}' {[} numeric \textbar{} \emph{empty} {]}
  - An NPar-by-NPop array containing the initial distribution of
  particles, where NPar is the number of estimated parameters, and NPop
  is the size of population. If empty, a population will be created
  containing the initial parameter vector and the rest of the particles
  will be randomly generated according to \texttt{'popInitRange='}. Use
  the option \texttt{'includeInitialValue=' false} oo exclude the
  initial value from the initial population so that the entire
  population is randomly generated.
\item
  \texttt{'socialAttraction='} {[} numeric \textbar{}
  \emph{\texttt{1.25}} {]} - Positive scalar to control the relative
  attraction of each particle to the best location they have heard about
  from other particles.
\item
  \texttt{'plotFcns='} {[} cell \textbar{} \emph{empty} {]} - Cell array
  of function handles to functions which accept
  \texttt{(options,state,flag)} values as input arguments. The only
  built-in general-purpose plotting function is
  \texttt{@optim.scoreDiversity}.
\item
  \texttt{'populationSize='} {[} numeric \textbar{} \emph{\texttt{40}}
  {]} - Positive integer which determines the number of particles in the
  swarm.
\item
  \texttt{'popInitRange='} {[} numeric \textbar{} \emph{empty} {]} - A
  2-by-NPar array which sets the range over which the initial population
  will be distributed, where NPar is the number of estimated parameters,
  or a 2-by-1 array with the range for all parameters. If empty and
  \texttt{'PopInitRange='} is not set, the upper and lower bounds will
  be used if both are finite. If either of the bounds are infinite, the
  range will be \texttt{{[}0;1{]}}.
\item
  \texttt{'stallGenLimit='} {[} numeric \textbar{} \emph{\texttt{100}}
  {]} - Maximum number of swarm iterations which result in no
  improvement in the fitness function (likelihood) value before the
  algorithm terminates.
\item
  \texttt{'timeLimit='} {[} numeric \textbar{} \emph{\texttt{Inf}} {]} -
  Maximum running time in seconds.
\item
  \texttt{'tolCon='} {[} numeric \textbar{} \emph{\texttt{1e-6}} {]} -
  Largest tolerated constraint violation.
\item
  \texttt{'tolFun='} {[} numeric \textbar{} \emph{\texttt{1e-6}} {]} -
  Function tolerance; when the change in the best fitness function value
  (likelihood) improvement per generation falls below this value the
  algorithm will terminate.
\item
  \texttt{'velocityLimit='} {[} numeric \textbar{} \emph{\texttt{Inf}}
  {]} - Positive scalar to bound particle intertia from above.
\item
  \texttt{'updateInterval='}* {[} numeric \textbar{} \texttt{5} {]} -
  Minimum length of time in seconds which must pass before new command
  window output will be produced.
\item
  \texttt{'useParallel='} {[} \texttt{true} \textbar{}
  \emph{\texttt{false}} {]} - Use a \texttt{parfor} loop which requires
  you already have a \texttt{matlabpool} open. Overhead is slightly
  higher for constrained problems than unconstrained problems.
\end{itemize}

\paragraph{Description}\label{description}

In the input parameter database, \texttt{E}, you can provide the
following four specifications for each parameter:

\begin{verbatim}
E.parameter_name = {start,lower,upper,logprior}
\end{verbatim}

where \texttt{start} is the value from which the numerical optimisation
will start, \texttt{lower} is the lower bound, \texttt{upper} is the
upper bound, and \texttt{logprior} is a function handle expected to
return the log of the prior density. You can use the
\href{logdist/Contents}{\texttt{logdist}} package to create function
handles for some of the basic prior distributions.

You can use \texttt{NaN} for \texttt{start} if you wish to use the value
currently assigned in the model object. You can use \texttt{-Inf} and
\texttt{Inf} for the bounds, or leave the bounds empty or not specify
them at all. You can leave the prior distribution empty or not specify
it at all.

\subparagraph{User-supplied optimisation (minimisation)
routine}\label{user-supplied-optimisation-minimisation-routine}

You can supply a function handle to your own minimisation routine
through the option \texttt{'optimiser='}. This routine will be used
instead of the Optim Tbx's \texttt{fminunc} or \texttt{fmincon}
functions. The user-supplied function is expected to take at least five
input arguments and return three output arguments:

\begin{verbatim}
[PEst,ObjEst,Hess] = yourminfunc(F,P0,PLow,PHigh,OptimSet)
\end{verbatim}

with the following input arguments:

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{F} is a function handle to the function minimised;
\item
  \texttt{P0} is a 1-by-N vector of initial parameter values;
\item
  \texttt{PLow} is a 1-by-N vector of lower bounds (with \texttt{-Inf}
  indicating no lower bound);
\item
  \texttt{PHigh} is a 1-by-N vector of upper bounds (with \texttt{Inf}
  indicating no upper bounds);
\item
  \texttt{OptimSet} is a cell array with name-value pairs entered by the
  user through the option \texttt{'optimSet='}. This option can be used
  to modify various settings related to the optimisation routine, such
  as tolerance, number of iterations, etc. Of course, you may simply
  ignore it and leave this input argument unused;
\end{itemize}

and the following output arguments:

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{PEst} is a 1-by-N vector of estimated parameters;
\item
  \texttt{ObjEst} is the value of the objective function at optimum;
\item
  \texttt{Hess} is a N-by-N approximate Hessian matrix at optimum.
\end{itemize}

If you need to use extra input arguments in your minimisation function,
enter a cell array instead of a plain function handle:

\begin{verbatim}
{@yourminfunc,Arg1,Arg2,...}
\end{verbatim}

In that case, the optimiser will be called the following way:

\begin{verbatim}
[PEst,ObjEst,Hess] = yourminfunc(F,P0,PLow,PHigh,Opt,Arg1,Arg2,...)
\end{verbatim}

\subparagraph{User-supplied steady-state
solver}\label{user-supplied-steady-state-solver}

You can supply a function handle to your own steady-state solver (i.e.~a
function that finds the steady state for given parameters) through the
\texttt{'sstate='} option.

The function is expected to take one input argument, the model object
with newly assigned parameters, and return at least two output
arguments, the model object with a new steady state (or balanced-growth
path) and a success flag. The flag is \texttt{true} if the steady state
has been successfully computed, and \texttt{false} if not:

\begin{verbatim}
[M,Success] = mysstatesolver(M)
\end{verbatim}

It is your responsibility to add the growth characteristics if some of
the model variables drift over time. In other words, you need to take
care of the imaginary parts of the steady state values in the model
object returned by the solver.

Alternatively, you can also run the steady-state solver with extra input
arguments (with the model object still being the first input argument).
In that case, you need to set the option \texttt{'sstate='} to a cell
array with the function handle in the first cell, and the other input
arguments afterwards, e.g.

\begin{verbatim}
'sstate=',{@mysstatesolver,1,'a',X}
\end{verbatim}

The actual function call will have the following form:

\begin{verbatim}
[M,Success] = mysstatesolver(M,1,'a',X)
\end{verbatim}

\paragraph{Example}\label{example}


\chapter[\protect\module{pygsl.testing} ---  Modules in Testing]
{\protect\module{pygsl.testing} \\ Modules in Testing}
\label{cha:statistics-module}

\declaremodule{standard}{pygsl.testing}

\moduleauthor{Pierre Schnizer}{schnizer@users.sourceforge.net}
Modules in this package are often reimplementations of an original package
with significant change to the original. The current rng implementation, for
example, started its life here.  The sf module implemented here will supersede
the sf package in one of the next releases. Concerning the other modules the
usage is encouraged for tests
to see if they work, but use them with caution in your production code!

\section[\protect\module{pygsl.testing.sf} --- Special UFuncs]
{\protect\module{pygsl.testing.sf} \\ Special Functions as UFuncs}

\declaremodule{standard}{pygsl.testing.sf}
\moduleauthor{Pierre Schnizer}{schnizer@users.sourceforge.net}

This chapter provides mainly \numpy{} UFuncs over the special functions. This means
that all input variable can be arrays, and the UFunc will evaluate the gsl
function for all its inputs. It is meant to replace the sf module later;
please use it and find out if it is useful for you.
Only the python specific part is described here. For a general description of
the function please see the GSL Reference document.

\section{UFuncs}
\label{sec:ufuncs}
These UFuncs allow to evaluate an array of doubles or an array of floats
typically. Note that the return values of the functions ending with an _e are
not turned to exceptions. Instead the error codes are returned as an separate
array. So if you are interested in them you have to do check the error code
yourself.

\input{providedufuncs.tex}

\section{Ordinary Functions}

The following array functions have been wrapped. These are supposingly faster
than the equivalent functions from above.
\begin{funcdesc}{bessel_In_array}{...}\index{bessel_In_array}
\end{funcdesc}
\begin{funcdesc}{bessel_Jn_array}{...}\index{bessel_Jn_array}
\end{funcdesc}
\begin{funcdesc}{bessel_Kn_array}{...}\index{bessel_Kn_array}
\end{funcdesc}
\begin{funcdesc}{bessel_Kn_scaled_array}{...}\index{bessel_Kn_scaled_array}
\end{funcdesc}
\begin{funcdesc}{bessel_Yn_array}{...}\index{bessel_Yn_array}
\end{funcdesc}
\begin{funcdesc}{bessel_il_scaled_array}{...}\index{bessel_il_scaled_array}
\end{funcdesc}
\begin{funcdesc}{bessel_jl_array}{...}\index{bessel_jl_array}
\end{funcdesc}
\begin{funcdesc}{bessel_jl_steed_array}{...}\index{bessel_jl_steed_array}
\end{funcdesc}
\begin{funcdesc}{bessel_kl_scaled_array}{...}\index{bessel_kl_scaled_array}
\end{funcdesc}
\begin{funcdesc}{bessel_yl_array}{...}\index{bessel_yl_array}
\end{funcdesc}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "ref"
%%% End:


    \filetitle{subsref}{Subscripted reference for model and systemfit objects}{model/subsref}

	\paragraph{Syntax for retrieving object with subset of
parameterisations}\label{syntax-for-retrieving-object-with-subset-of-parameterisations}

\begin{verbatim}
M(Inx)
\end{verbatim}

\paragraph{Syntax for retrieving parameters or steady-state
values}\label{syntax-for-retrieving-parameters-or-steady-state-values}

\begin{verbatim}
M.Name
\end{verbatim}

\paragraph{Syntax to retrieve a std deviation or a cross-correlation of
shocks}\label{syntax-to-retrieve-a-std-deviation-or-a-cross-correlation-of-shocks}

\begin{verbatim}
M.std_ShockName
M.corr_ShockName1__ShockName2
\end{verbatim}

Note that a double underscore is used to separate the names of shocks in
correlation coefficients.

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{M} {[} model \textbar{} systemfit {]} - Model or systemfit
  object.
\item
  \texttt{Inx} {[} numeric \textbar{} logical {]} - Inx of requested
  parameterisations.
\item
  \texttt{Name} - Name of a variable, shock, or parameter.
\item
  \texttt{ShockName1}, \texttt{ShockName2} - Name of a shock.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}


\documentclass[a4paper,12pt]{article}
\usepackage{lmodern}
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{pst-coil}
% https://www.ctan.org/pkg/pst-solides3d
\usepackage{pst-solides3d}

\pagestyle{empty}
\title{Hello World!}
\author{Author's Name}

\begin{document}
\maketitle
\thispagestyle{empty}

\section{PStricks Picture}

\begin{pspicture}(-5,-4)(5,4)
\psgrid[subgriddiv=1,griddots=10]
\psset{unit=1mm,linewidth=.25mm,hatchwidth=.2,hatchsep=1}

\rput(10,10){

\psline{->}(-20,0)(40,0)
\psline{->}(0,-30)(0,40)
\uput[ul](40,0){$x$}
\uput[dr](0,40){$y$}
\uput[ur](0,0){$O$}

\psset{linewidth=.5mm}
\pscircle(10,0){20}
\psarc[linestyle=dashed,dash=3 2](15,0){15}{0}{180}
\psarc[fillstyle=solid,fillcolor=lightgray](-5,0){5}{0}{180}

\pscircle{1}
\psframe[fillstyle=vlines,linecolor=white,linewidth=0](-3,-3)(3,-5)
\psline(-.5,-.5)(-3,-3)(3,-3)(.5,-.5)

\rput(5,20){ \psframe*[framearc=.5,linecolor=gray](0,0)(10,8) }
\rput{90}(30,0){
    \pscircle{1}	\psline(-.5,-.5)(-2,-2)(2,-2)(.5,-.5)
    \psframe[fillstyle=vlines,linecolor=white,linewidth=0](-3,-3)(3,-5)
    \pscircle(0,-2.5){.5} \psline(-3,-3)(3,-3)
}

% with pst-plot (functions given with reverse polish notation):
\parametricplot[linestyle=dotted,plotpoints=200,arrows=->]{0}{540}{%
% -15*exp(-.002*t)*cos(t) + 15,  15*exp(-.002*t)*(-.002*cos(t)-sin(t))
    2.71828 .002 t mul neg exp -15 mul t cos mul 15 add	%
    2.71828 -.002 t mul exp 15 mul t cos -.002 mul t sin sub mul
}
% with pst-coil:
\pscoil[coilwidth=2,coilarm=2](10,-20)(10,-30)
\rput(10,-30){
    \psframe[fillstyle=hlines,linecolor=white,linewidth=0](-3,0)(3,-2)
    \psline(-3,0)(3,0)
}
} %rput(10,10)

\rput(-10,-30){

\psset{viewpoint=1000 2000 1000,Decran=2500,lightsrc=0 100 100,linewidth=.1}
\axesIIID[linewidth=.2,linecolor=green,arrowsize=5pt,arrowinset=0,
	axisemph={\color{green}},labelsep=8pt](0,0,0)(40,40,35)

\psLineIIID[linecolor=red](20,0,0)(20,25,0)(20,25,30)(20,25,0)(0,25,0)

\psset{r=1,ngrid=4 10,linecolor=gray,action=none}
\psset{solidmemory}
\psSolid[object=cylindre,h=30,name=bAD,fillcolor=gray!50](20,0,0)
\psSolid[object=cylindre,h=25,name=bDE,fillcolor=gray!50,RotX=-90](20,0,30)
\psSolid[object=cylindre,h=20,name=bEB,fillcolor=gray!50,RotY=-90](20,25,30)
\psSolid[object=cylindre,h=30,name=bBC,fillcolor=gray!50](0,25,0)
\psSolid[object=fusion,action=draw**,base=bAD bDE bEB bBC]
\composeSolid

\psset{action=draw,linecolor=red}

\psLineIIID[linecolor=blue,linewidth=.7]{->}(20,0,0)(30,10,-10)
\psLineIIID(30,0,0)(30,10,0)(30,10,-10)(30,10,0)(20,10,0)
\uput[ul](-22,-20){$F_1$}
\psLineIIID[linecolor=blue,linewidth=.7]{<-}(20,0,30)(20,0,40)
\uput[ur](-18,30){$M_2$}
\psLineIIID[linecolor=blue,linewidth=.7]{->}(20,25,30)(30,25,30)
\uput[dr](-15,13){$F_3$}
\psLineIIID[linecolor=blue,linewidth=.7]{->}(0,25,30)(0,10,30)
\uput[u](10,20){$F_2$}
\psLineIIID[linecolor=blue,linewidth=.7]{->}(0,25,0)(5,20,10)
\psLineIIID(5,25,0)(5,20,0)(5,20,10)(5,20,0)(0,20,0)
\uput[u](5,0){$M_1$}

} %rput(-10,-10)
\end{pspicture}

\section{So long...}
... and thank you for the fish!

\end{document}