# Test Data

It is hard to compare different programs and benchmarks.

With Least Squares techniques in cave surveying, the problem is made worse because everybody seems to have differing ideas of how weighting is supposed to operate.

However, all is not lost. It is not hard to set up some basic tests for programs where, for example, all the weights cancel. This allows some reasonable testing to be done.

For the sake of having SOME format for the examples, the format below is:

```From  To    Distance    Angle from North    Angle from Horizontal

Angles are in degrees.

A "#" starts a comment.

For example:

A     B    10.0         90.0     0.0   # This is an east shot.
B     C    10.0          0.0     0.0   # This is a north shot.
D     E    10.0          0.0    90.0   # Straight up.
```

We will also assume that the origin is at station "A". (However that is indicated in the program being tested.)

Because some programs allow the generated matrices to be shown, the matrices for some of the simple examples are given.

# Test one

For a normal adjustment of observations, it is necessary for at least one point to be tied down to keep the problem matrix from being singular.

```# Test one.
# We have the convention in these tests of tying point A to the origin.
A B 10.0 90.0 0.0  # Shot one (S1)
# This should generate for S1 = [ 10.0 0.0 0.0 ]'
# The result of this test should be:
# A = [   0.0   0.0   0.0 ]'
# B = [  10.0   0.0   0.0 ]'
# ALL weights in this specific least squares problem cancel, so this is
# the result totally independent of the weighting the program uses.
```

Failure notes:

If the program does the LS adjustment without pinning some point down, it then builds the following problem (ignoring weights)

```   [ -1 1 ] [ A ] = [ Shot one]
[ B ]
Which forms the normal equations:
[ -1 ] [ -1 1 ] [ A ] = [ -1 ] [ S1 ]
[  1 ]          [ B ]   [  1 ]
Which would form the final problem of:
[ 1 -1 ] [ A ] = [ -S1 ]
[-1  1 ] [ B ]   [  S1 ]
Which is
1) Singular, so it can't be really solved.
2) The only case where the setup changes the size of the right
hand matrix, which is a degenerate case almost nobody is
going to have considered.
If the program does weighting, then the final problem matrix is going
to be singular also.

If the A point is correctly tied down to the origin,
then the problem looks like:
[  1 0 ] [ A ]  = [ 0 ]
[ -1 1 ] [ B ]    [ shot one ]
And the LS solution looks more or less like:
[ 1 -1 ] [  1 0 ] [ A ] = [ 1 -1 ] [ A tie (origin) ]
[ 0  1 ] [ -1 1 ] [ B ]   [ 0  1 ] [ Shot one ]
or
[  2 -1 ] [ A ] = [ -S1 ]
[ -1  1 ] [ B ] = [  S1 ]

for programs doing a full 3d adjustment (without weights) the
final problem should look like
[  2  0  0   -1  0  0  ]  [ Ax ] = [ -10.0 ]
[  0  2  0    0 -1  0  ]  [ Ay ]   [   0.0 ]
[  0  0  2    0  0 -1  ]  [ Az ]   [   0.0 ]
[                      ]  [    ]   [       ]
[ -1  0  0    1  0  0  ]  [ Bx ]   [  10.0 ]
[  0 -1  0    0  1  0  ]  [ By ]   [   0.0 ]
[  0  0 -1    0  0  1  ]  [ Bz ]   [   0.0 ]
(The spacing is just for readability.  The matrixes are just 6x6, 1x6, 1x6.)

In the case where the program (incorrectly) handles the problem as three
independent problems (one in x, one in y, and one in z) you expect the
matrices to look like:
[ +  - ] [ A ] = [ * ]   (Without knowing the weighting details,
[ -  + ] [ B ]   [ * ]    no more explicit form can be given)

Full 3d but with no weights:
[  2  0  0   -1  0  0  ]  [ Ax ] = [ -10.0 ]
[  0  2  0    0 -1  0  ]  [ Ay ]   [   0.0 ]
[  0  0  2    0  0 -1  ]  [ Az ]   [   0.0 ]
[                      ]  [    ]   [       ]
[ -1  0  0    1  0  0  ]  [ Bx ]   [  10.0 ]
[  0 -1  0    0  1  0  ]  [ By ]   [   0.0 ]
[  0  0 -1    0  0  1  ]  [ Bz ]   [   0.0 ]

The full 3d matrix with full 3d weights by matrix partitioning.
[ W0+W1   -W1  ] [ A ] = [ W0*0 - W1*S1 ] = [ - W1 ]
[   -W1   +W1  ] [ B ]   [      + W1*S2 ]   [ + W1 ]

The full 3d solution with full weights is harder to show the form of
if one doesn't know the weights.  But one can say the form is:
(* means possibly non zero. + means positive, - means negative)
[  +  *  *    -  *  *  ]  [ Ax ] = [ * ]
[  *  +  *    *  -  *  ]  [ Ay ]   [ * ]
[  *  *  +    *  *  -  ]  [ Az ]   [ * ]
[                      ]  [    ]   [   ]
[  -  *  *    +  *  *  ]  [ Bx ]   [ * ]
[  *  -  *    *  +  *  ]  [ By ]   [ * ]
[  *  *  -    *  *  +  ]  [ Bz ]   [ * ]
If the weights can possibly represent a physical problem.
The matrix should be symmetric.
```

# Test two

In order to avoid the LS problem from being mathematically meaningless, at least one point in each floating section has to be tied down.

```# Test two.
# We have the convention in these tests of tying point A to the origin.
A B 10.0 90.0 0.0  # Shot one (S1)
C D 10.0  0.0 0.0  # shot two (S2)
# This should generate for S1 = [ 10.0  0.0 0.0 ]'
# This should generate for S2 = [  0.0 10.0 0.0 ]'
# As it sits, this survey SHOULD generate an error. (Since the second
# shot is in a floating section.) The problem as stated is not
# solvable.   If, however point C is tied to [ 20.0 0 0 ] Then
# the result of this test should be:
# A = [  0.0   0.0  0.0 ]'
# B = [ 10.0   0.0  0.0 ]'
# C = [ 20.0   0.0  0.0 ]'
# D = [ 20.0  10.0  0.0 ]'
# ALL weights in this specific squares problem cancel, so this is the result
# totally independent of the weighting the program uses.
```

Failure notes:

If no points are tied down, then the problem is misformed as in the previous test. If only one point is tied down, then the resulting matrix is singular. If the problem is set up correctly (with the tie down assumptions made above) the setup is:

```[  1  0  0  0 ] [ A ] = [ Tie-A (origin) ]
[ -1  1  0  0 ] [ B ]   [ S1 ]
[  0  0  1  0 ] [ C ]   [ Tie-C ]
[  0  0 -1  1 ] [ D ]   [ S2 ]
(This would be better solved as two independent problems, but
we'll do the setup anyway.)
The least squares problem is now:
[  1 -1  0  0 ] [  1  0  0  0 ] [ A ] = [  1 -1  0  0 ] [ 0     ]
[  0  1  0  0 ] [ -1  1  0  0 ] [ B ]   [  0  1  0  0 ] [ S1    ]
[  0  0  1 -1 ] [  0  0  1  0 ] [ C ]   [  0  0  1 -1 ] [ Tie-C ]
[  0  0  0  1 ] [  0  0 -1  1 ] [ D ]   [  0  0  0  1 ] [ S2    ]
which is:
[  2 -1  0  0 ] [ A ] = [  0   - S1 ]
[ -1  1  0  0 ] [ B ]   [        S1 ]
[  0  0  2 -1 ] [ C ]   [ TieC - S2 ]
[  0  0 -1  1 ] [ D ]   [  S2       ]

For independent but weighted X,Y,Z, the matrices should look like:
[  + - 0 0 ] [ A ] = [ * ]
[  - + 0 0 ] [ B ]   [ * ]
[  0 0 + - ] [ C ]   [ * ]
[  0 0 - + ] [ D ]   [ * ]

For full 3d solution, but no weights, it should look like:
[  2  0  0  -1  0  0   0  0  0   0  0  0 ]  [ Ax ] = [ -10.0 ]
[  0  2  0   0 -1  0   0  0  0   0  0  0 ]  [ Ay ]   [   0.0 ]
[  0  0  2   0  0 -1   0  0  0   0  0  0 ]  [ Az ]   [   0.0 ]
[                                        ]  [    ]   [       ]
[ -1  0  0   1  0  0   0  0  0   0  0  0 ]  [ Bx ]   [  10.0 ]
[  0 -1  0   0  1  0   0  0  0   0  0  0 ]  [ By ]   [   0.0 ]
[  0  0 -1   0  0  1   0  0  0   0  0  0 ]  [ Bz ]   [   0.0 ]
[                                        ]  [    ]   [       ]
[  0  0  0   0  0  0   2  0  0  -1  0  0 ]  [ Cx ]   [  20.0 ]
[  0  0  0   0  0  0   0  2  0   0 -1  0 ]  [ Cy ]   [ -10.0 ]
[  0  0  0   0  0  0   0  0  2   0  0 -1 ]  [ Cz ]   [   0.0 ]
[                                        ]  [    ]   [       ]
[  0  0  0   0  0  0  -1  0  0   1  0  0 ]  [ Dx ]   [   0.0 ]
[  0  0  0   0  0  0   0 -1  0   0  1  0 ]  [ Dy ]   [  10.0 ]
[  0  0  0   0  0  0   0  0 -1   0  0  1 ]  [ Dz ]   [   0.0 ]

Full 3d weights, with matrix partitioning:
[ W0+W1 -W1   0    0  ] [A] = [ W0*0 - W1*S1 +   0   +   0   ] = [-W1*S1       ]
[   -W1 +W1   0    0  ] [B]   [   0  + W1*S1 +   0   +   0   ]   [+W1*S1       ]
[   0    0  WT+W2 -W2 ] [C]   [   0  +   0   + WT*ST - W2*S2 ]   [      -W2*S2 ]
[   0    0    -W2 +W2 ] [D]   [   0  +   0   +   0   + W2*S2 ]   [+WT*ST+W2*S2 ]

For full 3d weights the problem looks like:
[  + * *  - * *  0 0 0  0 0 0 ]  [ Ax ] = [ * ]
[  * + *  * - *  0 0 0  0 0 0 ]  [ Ay ]   [ * ]
[  * * +  * * -  0 0 0  0 0 0 ]  [ Az ]   [ * ]
[                             ]  [    ]   [   ]
[  - * *  + * *  0 0 0  0 0 0 ]  [ Bx ]   [ * ]
[  * - *  * + *  0 0 0  0 0 0 ]  [ By ]   [ * ]
[  * * -  * * +  0 0 0  0 0 0 ]  [ Bz ]   [ * ]
[                             ]  [    ]   [   ]
[  0 0 0  0 0 0  + * *  - * * ]  [ Cx ]   [ * ]
[  0 0 0  0 0 0  * + *  * - * ]  [ Cy ]   [ * ]
[  0 0 0  0 0 0  * * +  * * - ]  [ Cz ]   [ * ]
[                             ]  [    ]   [   ]
[  0 0 0  0 0 0  - * *  + * * ]  [ Dx ]   [ * ]
[  0 0 0  0 0 0  * - *  * + * ]  [ Dy ]   [ * ]
[  0 0 0  0 0 0  * * -  * * + ]  [ Dz ]   [ * ]
It should have gone without saying that the left hand
matrix is symmetric.
```

# Test Three

The least squares solution to a problem is the "closest" consistent problem to the given data. In the case of a connected survey that has no loops, the solution is identically the same as the given data. (Independent of any weights, since the weights all cancel.)

```# Test three.
# We have the convention in these tests of tying point A to the origin.
A B 10.0 90.0  0.0  # Shot one (S1)
B C 10.0  0.0  0.0  # Shot two (S2)
C D 10.0  0.0 90.0  # Shot three (S3)
# --- This should generate the shots:
# S1 = [ 10.0   0.0   0.0 ]'
# S2 = [  0.0  10.0   0.0 ]'
# S3 = [  0.0   0.0  10.0 ]'
# --- This data has the solution:
# A = [   0.0   0.0   0.0 ]'
# B = [  10.0   0.0   0.0 ]'
# C = [  10.0  10.0   0.0 ]'
# D = [  10.0  10.0  10.0 ]'
# ALL weights in this specific squares problem cancel, so this is the result
# totally independent of whatever weighting the program uses.
```

Failure notes:

The setup for this problem is:

```  [  1  0  0  0 ] [ A ] = [  0 ]
[ -1  1  0  0 ] [ B ]   [ S1 ]
[  0 -1  1  0 ] [ C ]   [ S2 ]
[  0  0 -1  1 ] [ D ]   [ S3 ]
The unweighted least squares setup is:
[  1 -1  0  0 ] [  1  0  0  0 ] [ A ] = [  1 -1  0  0 ] [  0 ]
[  0  1 -1  0 ] [ -1  1  0  0 ] [ B ]   [  0  1 -1  0 ] [ S1 ]
[  0  0  1 -1 ] [  0 -1  1  0 ] [ C ]   [  0  0  1 -1 ] [ S2 ]
[  0  0  0  1 ] [  0  0 -1  1 ] [ D ]   [  0  0  0  1 ] [ S3 ]
Which reduces to:
[  2 -1  0  0 ] [ A ] = [  0 -S1 ]
[ -1  2 -1  0 ] [ B ]   [  S1-S2 ]
[  0 -1  2 -1 ] [ C ]   [  S2-S3 ]
[  0  0 -1  1 ] [ D ]   [  S3    ]

For independent, but weighted X, Y, Z, the setup should look like:
[  +  -  0  0 ] [ A ] = [ * ]
[  -  +  -  0 ] [ B ]   [ * ]
[  0  -  +  - ] [ C ]   [ * ]
[  0  0  -  + ] [ D ]   [ * ]

For full 3d without weights, the setup should look like:
[  2  0  0   -1  0  0    0  0  0   0  0  0  ] [ Ax ] = [ -10.0 ]
[  0  2  0    0 -1  0    0  0  0   0  0  0  ] [ Ay ]   [   0.0 ]
[  0  0  2    0  0 -1    0  0  0   0  0  0  ] [ Az ]   [   0.0 ]
[                                           ] [    ]   [       ]
[ -1  0  0    2  0  0   -1  0  0   0  0  0  ] [ Bx ]   [  10.0 ]
[  0 -1  0    0  2  0    0 -1  0   0  0  0  ] [ By ]   [ -10.0 ]
[  0  0 -1    0  0  2    0  0 -1   0  0  0  ] [ Bz ]   [   0.0 ]
[                                           ] [    ]   [       ]
[  0  0  0   -1  0  0    2  0  0  -1  0  0  ] [ Cx ]   [   0.0 ]
[  0  0  0    0 -1  0    0  2  0   0 -1  0  ] [ Cy ]   [  10.0 ]
[  0  0  0    0  0 -1    0  0  2   0  0 -1  ] [ Cz ]   [ -10.0 ]
[                                           ] [    ]   [       ]
[  0  0  0    0  0  0   -1  0  0   1  0  0  ] [ Dx ]   [   0.0 ]
[  0  0  0    0  0  0    0 -1  0   0  1  0  ] [ Dy ]   [   0.0 ]
[  0  0  0    0  0  0    0  0 -1   0  0  1  ] [ Dz ]   [  10.0 ]

Full 3d with weights, matrix partitioned:
[ W0+W1  -W1       0     0  ] [ A ] = [ WO*S0 - W1*S1 +   0   +   0   ]
[   -W1  +W1+W2  -W2     0  ] [ B ]   [   0   + W1*S1 - W2*S2 +   0   ]
[   0       -W2  +W2+W3  0  ] [ C ]   [   0   +   0   + W2*S2 - W3*S3 ]
[   0       0       -W3 +W3 ] [ D ]   [   0   +   0   +   0   + W4*S4 ]

For full 3d with weights, without partitioning the setup is:
[  +  *  *    -  *  *    0  0  0   0  0  0  ] [ Ax ] = [ * ]
[  *  +  *    *  -  *    0  0  0   0  0  0  ] [ Ay ]   [ * ]
[  *  *  +    *  *  -    0  0  0   0  0  0  ] [ Az ]   [ * ]
[                                           ] [    ]   [   ]
[  -  *  *    +  *  *    -  *  *   0  0  0  ] [ Bx ]   [ * ]
[  *  -  *    *  +  *    *  -  *   0  0  0  ] [ By ]   [ * ]
[  *  *  -    *  *  +    *  *  -   0  0  0  ] [ Bz ]   [ * ]
[                                           ] [    ]   [   ]
[  0  0  0    -  *  *    +  *  *   -  *  *  ] [ Cx ]   [ * ]
[  0  0  0    *  -  *    *  +  *   *  -  *  ] [ Cy ]   [ * ]
[  0  0  0    *  *  -    *  *  +   *  *  -  ] [ Cz ]   [ * ]
[                                           ] [    ]   [   ]
[  0  0  0    0  0  0    -  *  *   +  *  *  ] [ Dx ]   [ * ]
[  0  0  0    0  0  0    *  -  *   *  +  *  ] [ Dy ]   [ * ]
[  0  0  0    0  0  0    *  *  -   *  *  +  ] [ Dz ]   [ * ]
```

# Go to ...

```This page is http://www.cc.utah.edu/~nahaj/cave/survey/intro/testdata.html