Use of sparse matrix absorption in animal breeding

Summary - Although the capacity of modern computers is increasing dramatically so too are the complexity of models that animal breeders employ, with the result that we still find computers limiting. This paper demonstrates the employment of linked lists for sparse matrix manipulations and their use in a number of relevant applications. animal breeding - prediction of genetic merits - numerical methods - sparse matrix Résumé - Utilisation en génétique animale de l’absorption dans des matrices creuses. Malgré l’accroissement de capacité des ordinateurs, la complexité également croissante des modèles employés en génétique animale nécessite le raffinement des méthodes numériques. Cet article explique l’utilisation de listes liées pour manipuler de très grandes matrices creuses, et illustre leur usage dans différents types d’application dans le cadre de l’évaluation des reproducteurs: absorption d’effets fixes, inversion de matrices, estimations de composantes de la variance par le maximum de vraisemblance.


INTRODUCTION
As the capacity of modern computers increases so does the quantity of data and the complexity of models that animal geneticists wish to use in their analyses. In the early years of computing when main memory was a major limitation, a variety of techniques were developed to utilise efficiently that memory which was available (Bunch and Rose, 1976). This paper illustrates the use of one of these techniqueslinked liststo store sparse matrices and eliminate (absorb) equations. Examples are given of how this technique can be useful.

TYPICAL MODELS
Linear models that are commonly used by animal geneticists have qualities that lend themselves to efficient methods of storage. Consider the model: where y is a vector of observations; X and Z are incidence matrices; b is a vector of fixed effects; u is a vector of random animal (or sire) effects; and e is a vector of random residuals. Animals (sires) are related.
The mixed model equations (Henderson, 1974) are where G is the covariance matrix of u, and R is a covariance matrix of residuals.
For a univariate analysis G = 7 A for some, where A is the numerator relationship matrix. be the mixed model array. Because Q is symmetric it is only necessary to store the upper (or lower) triangle. This means that more equations can be stored in the memory. When an animal model (or reduced animal model) is employed, then Q is very sparse.

LINKED LISTS
A linked list consists of a list of elements linked together by pointers to their physical locations. The physical location of the first element in the row is stored and every element has associated with it a pointer to the location in the memory of the next element in the sequence. The pointer associated with the last element in the list is zero. Knuth (1968) provided a detailed explanation of linked lists. When using FORTRAN 3 vectors are required to store a matrix in this wayone for the element (a u ), one for the column (J) and one for the pointer to the next element. A scalar (NUSED) is used to point to the last occupied location in these vectors. As the list is being built, new elements are stored in the next available location in these vectors but the order of the row is maintained by adjusting the pointers (illustrated in Table I).
Because matrices such as Q and G-1 are sparse, they lend themselves to this form of storage. To store a matrix of order N the first N elements in the storage vectors are reserved for the first element in each row. Each row forms its own linked list. Because they are symmetrical, it is possible to store the upper (or lower) triangle only -thus the first (last) element in any row is the diagonal.
Consider the simple linear model where A and B are systematic effects with 2 classes each. Assign the effects A1, A2, B1 and B2 to equations (1) to (4) respectively and the right-hand side to equation (5). Reserve the first 5 elements in the vectors for the first (diagonal) element in each row. Store the address of the last occupied location (5) in the scalar NUSED.
The mechanics of using a linked list are illustrated by 3 records shown in Table II. Each record generates 6 contributions to the upper triangle. Each of these is either an addition to an existing element or a new element. In both cases, it is necessary to follow the sequence of pointers along the particular row until either the element is found, or an element which lies to the right of the current contribution is found, or the end of the row is found. If the element is found in the list then the current contribution is added to it. If the element is new then it is stored in the next available location and the pointers (in the row and to the last occupied location) are adjusted accordingly. A simple algorithm to do this is shown in the Appendix.
The matrix Q derived from the 3 records in Table II is   Table III illustrates the status of the linked list after each record has been processed. If iteration (e.g. Gauss-Seidel) is to be the only manipulation involving Q, then the vectors containing the coefficients and column identities can be sorted after building Q and the pointers associated with the first N elements can be used to store the number of elements in each row. However, to implement absorption, the pointer vector must be maintained.

ABSORPTION OF EQUATIONS
Absorption or gaussian elimination is described in Smith and Graser (1986). If the sparsity of the matrix is to be preserved, as is desirable for a linked list to be useful, then it is important to choose pivots so that new elements do not proliferate. Gill and Murray (1974) suggest choosing rows with the least number of off-diagonal elements first.
As each row is absorbed, the space it occupied is released and can be made available to new elements that are created in other rows. Before absorbing any equations, it is useful to link the unoccupied space in the vectors into a separate linked list. As space is released, it can be added to the list of free space for reuse. Because the elements in the row are already connected by pointers, the complete row can be placed at the start of the list of free space by modifying the pointers at the end of the row and at the start of the free space. If backward substitution is to be implemented then the row should be written as an exterior file.
After absorbing the first row of Q and its linked list representation is shown in Table IV. There is no need to zero the column and coefficient vectors from the row being absorbed; when this space is reused they will be assigned new values. During elimination of each row of Q, it is possible to design the algorithm so that subsequent rows and elements within rows are modified sequentially; redundant searching through Q can and should be avoided. If the selected pivot is zero, then the row can be regarded as having been preabsorbed. An algorithm to absorb equations in this manner is shown in the Appendix. For large problems, it is possible and desirable to divide Q into 2 parts: an exterior file and a linked list. Absorption of a row entails: reading the row from the exterior file; merging the input with the linked list; and absorbing the row in the linked list. When the linked list is full, it can be merged with the exterior file so as to create a new exterior file. This clears the vectors for a new iteration.

APPLICATIONS
All the following examples have the form of manipulating a matrix by absorbing U row by row to give Row by row absorption is equivalent to repeated application of the formula for W * , where U is a scalar (the pivot) and T is a column vector.

1) Sparse matrix inversion
For example, find E-1 given the positive definite and symmetric matrix of E. Set U = Enxn T = Inxn W = Onxn then W* = -E -1 Sometimes only the diagonal of E-1 may be required, in which case the calculation and storage of off-diagonal elements of E-1 can be neglected.
2) Estimation of (co)variance components by maximum likelihood (ML) or restricted maximum likelihood (REML) Many of the arrays in this section can be found in Searle (1979 (1987).
To evaluate L we note that where I UI is the determinant of one of the largest non-singular submatrices of U; and I UI is evaluated by the product of the non-zero pivots.
To implement a derivative-free search sometimes we need rank(X) which is the number of non-zero pivots minus the order of G-1 .

3) Calculating the exact A-' for sub-populations
When a sire model is used it is possible to build A-' for the full pedigree of the sires and then absorb all female relatives. Some sires may be absorbed as well if they are not part of the subpopulation. Partition A-' into 2 parts: animals to be absorbed in U, and animals that are to remain in W. The W * is the exact inverse relationship matrix for the remaining selected animals. Experience has shown that absorption seems to create many elements that are essentially zero. Linked-list absorption works well when these zero elements are released from storage, particularly from a row before it is absorbed.

4) Conducting secondary absorptions
Sometimes it is necessary to absorb 2 groups of factors out of the model. The model used by Smith (1987) included 2765 effects representing contemporary groups, 2611 1 fixed sire effects and 539 random sires. Rows representing contemporary groups were absorbed as the data were read. Then rows representing fixed sires were absorbed in a reasonable time using sparse matrix techniques. The absorption of the fixed-sire effects would have been impossible using matrix inversion.
The order used for the secondary absorption was determined by the size of the diagonals after the primary absorption. Rows with smaller diagonals were absorbed first. This order is opposite to the usual practice, however, it minimizes the creation of non-zero elements and hence preserves the efficient use of memory. Use of the traditional approach would have been as impossible as matrix inversion.

5) Partial absorption prior to iteration
Sometimes it may be advisable to absorb some equations prior to iteration, such as is implicitly done using the reduced animal model (Quaas and Pollak, 1980). CONCLUSION Some of the applications we have described may not be practical. For example, evaluating V-1 , P and Z'PZ may be beyond current computing capabilities even with a linked list. However, some of the applications (e.g., evaluating L, constructing A-1 for sub-populations, and secondary absorptions) are realistic and have been tested on real data structures. Without linked lists these applications may not be feasible.
A common misconception is that evaluating Q-1 is about as difficult as absorbing all rows of Q. For non-sparse matrices, inversion requires 3 times the work of absorption. For sparse matrices the comparison is typically much more extreme. Inversion can be prohibitive even with a linked list, while absorption of the same matrix may be a relatively simple operation.