\section{Test models}
\label{models}
Since the size of a model is not limited, there are infinitely many models. So it's clearly impossible to test the software with all possible models. Instead the testing should be done by using a representative subset of all the models. 

This section defines some models to be used for testing the software. Each model should be tested with no missing values and with missing values.

\subsection{Semantically correct models}

This section represents models which can be used when testing the Generator and also the Fortran program it produces. 

\subsubsection{The simple bird model}

Model description:

\begin{verbatim}
REAL alpha ~ continuous_uniform(-1.0, 1.0)

ENTITY square, "squares.txt"
{
    INTEGER northerness(1)	
}

ENTITY bird, ""
{

}

ENTITY squarebird, "observations.txt", combines(square, bird)
{
    REAL p = EXP(alpha * northerness) / (1 + EXP(alpha * northerness))
    INTEGER x ~ user_bernoulli(p)
    INTEGER obs(*) ~ user_defined_points(x)
}
\end{verbatim}

Proposal distributions and strategies:

\begin{verbatim}
?? proposal distributions

? alpha
continuous_uniform(-1.0, 1.0)

? x
discrete_uniform(0, 1)
\end{verbatim}

\newpage
Initial values:
\begin{verbatim}
?? initial values

? alpha
0.5

? x 1:21 1:4
0 0 1 1
0 0 1 1
0 0 1 1
1 0 1 1
1 0 1 1
1 0 1 1
1 0 1 1
0 0 1 1
0 0 1 0
0 0 0 0
1 0 0 0
1 0 1 0
0 0 1 1
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0
0 0 1 0
0 0 1 1
\end{verbatim}

The data for obs is the same matrix as the initial values of x.

Expected results when running the Fortran program: Alpha is negative.

\subsubsection{The simple bird model with spatial dependence}

Model description:

\begin{verbatim}
REAL alpha ~ continuous_uniform(-1.0, 1.0)

ENTITY square, "squares.txt"
{
    INTEGER northerness(1)	
}

ENTITY bird, ""
{

}
\end{verbatim}

\newpage
\begin{verbatim}
ENTITY squarebird, "observations.txt", combines(square, bird)
{
    INTEGER q = SUM(&x)
    REAL p = EXP(alpha * northerness) / (1 + EXP(alpha * northerness))
    INTEGER x ~ user_bernoulli(p)
    INTEGER obs(*) ~ user_defined_points(x)
}
\end{verbatim}

Other input files stay the same.

Expected results when running the Fortran program: Alpha is negative.

\subsubsection{The lip cancer model}

Model description:

\begin{verbatim}
REAL alpha ~ user_normal(0, 100)
REAL sigma ~ user_gamma(1, 1)

ENTITY county, "tests/cancer/lips.data", "tests/cancer/lips.neighbours"
{
	REAL x(3)
	REAL expected(2)
	REAL n = COUNT(&b)
	REAL q = SUM(&b)
	REAL t = q/n
	REAL b ~ user_normal(t, n)
	REAL mu = EXP(LOG(expected) + alpha * x / 10 + sigma * b)
	INTEGER obs(1) ~ poisson(mu)
}
\end{verbatim}

Proposal distributions and strategies:

\begin{verbatim}
?? proposal distributions

? alpha
user_normal(0, 10) RW

? sigma
continuous_uniform(0.001, 5)

? b
continuous_uniform(-10.0, 10.0)
\end{verbatim}

Expected results when running the Fortran program: alpha is 0.37 +/- 0.11, sigma is 0.69 +/- 0.12.

\newpage
\subsubsection{The bird model}

Model description:
\begin{verbatim}
REAL alpha ~ user_gamma(0.25, 0.5)
REAL tau ~ continuous_uniform(0.5, 10)
REAL gamma ~ continuous_uniform(-1.0, 1.0)

ENTITY species, "species.data" 
{
    REAL a ~ user_normal(alpha, tau)
    INTEGER waterbird(1)
}

ENTITY cell, "gridcell.data", "neighbours.data"
{
    REAL q = SUM(&x)
    REAL waterpercentage(4)
    INTEGER researchgrade(7)
    INTEGER centeredcoordinate(3)
}

ENTITY observations, "obs.data", combines (cell, species)
{
    REAL p = EXP(waterbird*a*waterpercentage + gamma*centeredcoordinate + 0.25 * q)
    /(1 +  EXP(waterbird*a*waterpercentage + gamma*centeredcoordinate + 0.25 * q))
    # 0.25 could be any other constant. defines spatial weighting.

    INTEGER x ~ user_bernoulli(p)
    INTEGER observation(*) ~ user_defined_points2(x, researchgrade)
}
\end{verbatim}

Proposal distributions and strategies, initial values and expected results were not given.

\subsection{Other models}

This section describes modes which have no sensible semantics but can be used when testing the Generator. These models are useful because it is possible for them to contain whatever dependencies that are useful for testing purposes while semantically correct models are more restricted.

\subsubsection{A model with all kinds of stochastic dependencies}

This model includes all possible stochastic dependencies as a single-parameter version, that is, each distribution has only one parameter.

\newpage
Model description:
\begin{verbatim}
# 1) global parameter with no dependencies
INTEGER a1 ~ user_dist_1(3)

# 2) a2 -> b2, both global
INTEGER a2 ~ user_dist_2(4)
INTEGER b2 ~ user_dist_2-(a2)

# 3) one-dim parameter with no dependencies
ENTITY e3, ""
{
    INTEGER a3 ~ user_dist_3(5)
}

# 4) a4 -> b4, a4 global and b4 one-dim
INTEGER a4 ~ user_dist_4(6)
ENTITY e4, ""
{
    INTEGER b4 ~ user_dist_4-(a4)
}

# 5) a5 -> b5, both one-dim
ENTITY e5, ""
{
    INTEGER a5 ~ user_dist_5(7)
    INTEGER b5 ~ user_dist_5-(a5)
}

# 6) two-dim parameter with no dependencies
ENTITY e6y, "" 
{
}
ENTITY e6x, "" 
{ 
}
ENTITY e6, "", combines(e6y, e6x)
{
    INTEGER a6 ~ user_dist_6(5)
}

# 7) a7 -> b7, a7 global and b7 two-dim
INTEGER a7 ~ user_dist_7(8)
ENTITY e7y, "" 
{
}
ENTITY e7x, "" 
{
}
ENTITY e7, "", combines(e7y, e7x)
{
    INTEGER b7 ~ user_dist_7-(a7)
}

# 8) a8 -> b8, a8 one-dim and b8 two-dim (case y)
ENTITY e8y, "" 
{
    INTEGER a8 ~ user_dist_8(9)
}
ENTITY e8x, "" 
{
}
ENTITY e8, "", combines(e8y, e8x)
{
    INTEGER b8 ~ user_dist_8-(a8)
}

# 9) a9 -> b9, a9 one-dim and b9 two-dim (case x)
ENTITY e9y, "" 
{
}
ENTITY e9x, "" 
{
    INTEGER a9 ~ user_dist_9(10)
}
ENTITY e9, "", combines(e9y, e9x)
{
    INTEGER b9 ~ user_dist_9-(a9)
}

# 9) a10 -> b10, both two-dim
ENTITY e10y, "" 
{
}
ENTITY e10x, "" 
{
}
ENTITY e10, "", combines(e10y, e10x)
{
    INTEGER a10 ~ user_dist_10(10)
    INTEGER b10 ~ user_dist_10-(a10)
}
\end{verbatim}

\subsubsection{A model with all kinds of functional non-spatial dependencies}

This model includes all possible combinations of functional and stochastic dependencies but no spatial dependencies. It is a single-parameter version, that is, each distribution has only one parameter.

Model description:
\begin{verbatim}
# 1) a1 - - > b1
REAL a1 ~ user_dist_1(1)
REAL b1 = a1 + 1
\end{verbatim}

\newpage

\begin{verbatim}
# 2) a2 - - > b2 ----> c2
REAL a2 ~ user_dist_2(2)
REAL b2 = a2 - 2
REAL c2 ~ user_dist_2-(b2)

# 4) | a4 - - > b4 | 
ENTITY e4, ""
{
    REAL a4 ~ user_dist_4(4)
    REAL b4 = a4 / 4
}

# 5) | a5 - - > b5 ----> c5 |
ENTITY e5, ""
{
    REAL a5 ~ user_dist_2(5)
    REAL b5 = EXP(a5) 
    REAL c5 ~ user_dist_5-(b5)
}
    
# 7) | | a7 - - > b7 | |
ENTITY e7y, "" 
{
}
ENTITY e7x, "" 
{
}
ENTITY e7, "", combines(e7y, e7x)
{
    REAL a7 ~ user_dist_7(7)
    REAL b7 = a7 ** 2
}

# 8) | | a8 - - > b8 ----> c8 | | 
ENTITY e8y, "" 
{
}
ENTITY e8x, "" 
{
}
ENTITY e8, "", combines(e8y, e8x)
{
    REAL a8 ~ user_dist_2(8)
    REAL b8 = EXP(a8) 
    REAL c8 ~ user_dist_8-(b8)
}
    
# 10) a10 - - > | b10 ----> c10 |
REAL a10 ~ user_dist_10(10)
ENTITY e10, ""
{
    REAL b10 = SIN(a10)
    REAL c10 ~ user_dist_10-(b10)
}

# 12) a12 - - > b12 ----> | c12 |
REAL a12 ~ user_dist_12(12)
REAL b12 = 3 - a12
ENTITY e12, ""
{
    REAL c12 ~ user_dist_12-(b12)
}

# 14) | a14 - - > b14 ----> | c14 | | case y
ENTITY e14y, ""
{
    REAL a14 ~ user_dist_14(14) 
    REAL b14 = 18 / a14
}
ENTITY e14x, "" 
{ 
}
ENTITY e14, "", combines(e14y, e14x)
{
    REAL c14 ~ user_dist_14-(b14)
}

# 16) | a16 - - > b16 ----> | c16 | | case x
ENTITY e16y, "" 
{ 
}
ENTITY e16x, ""
{
    REAL a16 ~ user_dist_16(16) 
    REAL b16 = 18 / a16
}
ENTITY e16, "", combines(e16y, e16x)
{
    REAL c16 ~ user_dist_16-(b16)
}

# 18) | a18 - - > | b18 ----> c18 | | case y
ENTITY e18y, ""
{
    REAL a18 ~ user_dist_18(18)
}
ENTITY e18x, ""
{
}
ENTITY e18, "", combines(e18y, e18x)
{
    REAL b18 = a18
    REAL c18 ~ user_dist_18-(b18)
}

# 20) | a20 - - > | b20 ----> c20 | | case x
ENTITY e20y, ""
{
}
ENTITY e20x, ""
{
    REAL a20 ~ user_dist_20(20)
}
ENTITY e20, "", combines(e20y, e20x)
{
    REAL b20 = a20
    REAL c20 ~ user_dist_20-(b20)
}

# 22) a22 - - > | | b22 ----> c22 | |
REAL a22 ~ user_dist_22(22)
REAL b22 = 5 * a22
ENTITY e22y, ""
{
}
ENTITY e22x, ""
{
}
ENTITY e22, "", combines(e22y, e22x)
{
    REAL c22 ~ user_dist_22-(b22)
}

# 24) a24 - - > | b24 ----> | c24 | | case y
REAL a24 ~ user_dist_24(24)
ENTITY e24y, ""
{
    REAL b24 = a24 + 1**2
}
ENTITY e24x, ""
{
}
ENTITY e24, "", combines(e24y, e24x)
{
    REAL c24 ~ user_dist_24-(b24)
}

# 26) a26 - - > | b26 ----> | c26 | | case x
REAL a26 ~ user_dist_26(26)
ENTITY e26y, ""
{
}
ENTITY e26x, ""
{
    REAL b26 = a26 + 1**2
}
ENTITY e26, "", combines(e26y, e26x)
{
    REAL c26 ~ user_dist_26-(b26)
}
\end{verbatim}

\newpage
\textbf{Models with all kinds of spatial dependencies}

Since a model can include only one spatial entity, the different test cases must be different models.

Model description (simple1):
\begin{verbatim}
# simple, functional spatial variable and the referenced one
# one-dimensional
ENTITY simple01 , "" , "tests/model_all_spat/file.txt" {
INTEGER dep01 ~ discrete_uniform(0, 1)
INTEGER s01 = SUM(& dep01) 
}
\end{verbatim}

Model description (simple2):
\begin{verbatim}
ENTITY s , "", "tests/model_all_spat/file.txt" {
}
ENTITY n , "" {
}
# two-dimensional (spatial = Y)
ENTITY simple02 , "" , combines(s, n) {
INTEGER dep02 ~ discrete_uniform(0, 1)
INTEGER s02 = SUM(& dep02) 
}
# two-dimensional (spatial = X)
ENTITY simple03 , "" , combines(n, s) {
INTEGER dep03 ~ discrete_uniform(0, 1)
INTEGER s03 = SUM(& dep03) 
}
\end{verbatim}

Model description (cross1):
\begin{verbatim}
# cross, two functional spatial variables, COUNT and SUM, referencing 
# different stochastic variables, one-dimensional:

ENTITY cross01 , "" , "tests/model_all_spat/file.txt" {
INTEGER depsc01 ~ discrete_uniform(0, 1)
REAL depcc01 ~ continuous_uniform(0, 1)
REAL sc01 = SUM(& depsc01) 
REAL cc01 = COUNT(& depcc01) 
}
\end{verbatim}

Model description (cross2):
\begin{verbatim}
ENTITY s , "", "tests/model_all_spat/file.txt" {
}
\end{verbatim}
\newpage
\begin{verbatim}
ENTITY n , "" {
}
# two-dimensional (spatial = Y)
ENTITY cross02 , "" , combines(s, n) {
INTEGER depsc02 ~ discrete_uniform(0, 1)
REAL depcc02 ~ continuous_uniform(0, 1)
REAL sc02 = SUM(& depsc02) 
REAL cc02 = COUNT(& depcc02) 
}
# two-dimensional (spatial = X)
ENTITY cross03 , "" , combines(n, s) {
INTEGER depsc03 ~ discrete_uniform(0, 1)
REAL depcc03 ~ continuous_uniform(0, 1)
REAL sc03 = SUM(& depsc03) 
REAL cc03 = COUNT(& depcc03) 
}
\end{verbatim}

Model description (dia1):
\begin{verbatim}
# dia, the diamond-shaped structure, 
# two functional spatial variables, COUNT and SUM, referencing the same
# stochastic variable, and a functional average variable

# one-dimensional
ENTITY dia01 , "" , "tests/model_all_spat/file.txt" {
INTEGER depd01 ~ discrete_uniform(0, 1)
REAL sd01 = SUM(& depd01) 
REAL cd01 = COUNT(& depd01) 
REAL avg1 = sd01 / cd01
}
\end{verbatim}

Model description (dia2):
\begin{verbatim}
ENTITY s , "", "tests/model_all_spat/file.txt" {
}
ENTITY n , "" {
}
# two-dimensional (spatial = Y)
ENTITY dia02 , "" , combines(s, n) {
INTEGER depd02 ~ discrete_uniform(0, 1)
INTEGER sd02 = SUM(& depd02) 
INTEGER cd02 = COUNT(& depd02) 
REAL avg2 = REAL(sd02) / cd02
}

# two-dimensional (spatial = X)
ENTITY dia03 , "" , combines(n, s) {
INTEGER depd03 ~ discrete_uniform(0, 1)
INTEGER sd03 = SUM(& depd03) 
INTEGER cd03 = COUNT(& depd03) 
REAL avg3 = REAL(sd03) / cd03
}
\end{verbatim}

Model description (crossc1):
\begin{verbatim}
# crossc, two functional spatial SUM variables referencing 
# different stochastic variables, and an 
# combining functional variable

# one-dimensional
ENTITY crossc01 , "" , "tests/model_all_spat/file.txt" {
INTEGER depscc01 ~ discrete_uniform(0, 1)
REAL depscc02 ~ continuous_uniform(0, 1)
REAL scc01 = SUM(& depscc01) 
REAL scc02 = SUM(& depscc02)
REAL comb1 = scc01 + scc02
}
\end{verbatim}

Model description (crossc2):
\begin{verbatim}
ENTITY s , "", "tests/model_all_spat/file.txt" {
}
ENTITY n , "" {
}
#two-dimensional (spatial = Y)
ENTITY crossc02 , "" , combines(s, n) {
INTEGER depscc03 ~ discrete_uniform(0, 1)
REAL depscc04 ~ continuous_uniform(0, 1)
REAL scc03 = SUM(& depscc03) 
REAL scc04 = SUM(& depscc04) 
REAL comb2 = scc03 + scc04
}
# two-dimensional (spatial = X)
ENTITY crossc03 , "" , combines(n, s) {
INTEGER depscc05 ~ discrete_uniform(0, 1)
REAL depscc06 ~ continuous_uniform(0, 1)
REAL scc05 = SUM(& depscc05) 
REAL scc06 = COUNT(& depscc06) 
REAL comb3 = scc05 + scc06
}
\end{verbatim}
