### Function Reference: `optimalleaforder`

statistics: leafOrder = optimalleaforder (tree, D)
statistics: leafOrder = optimalleaforder (…, Name, Value)

Compute the optimal leaf ordering of a hierarchical binary cluster tree.

The optimal leaf ordering of a tree is the ordering which minimizes the sum of the distances between each leaf and its adjacent leaves, without altering the structure of the tree, that is without redefining the clusters of the tree.

Required inputs:

- tree: a hierarchical cluster tree tree generated by the `linkage` function.
- D: a matrix of distances as computed by `pdist`.

Optional inputs can be the following property/value pairs:

- property ’Criteria’ at the moment can only have the value ’adjacent’, for minimizing the distances between leaves.
- property ’Transformation’ can have one of the values ’linear’, ’inverse’ or a handle to a custom function which computes S the similarity matrix.

optimalleaforder’s output leafOrder is the optimal leaf ordering.

Reference Bar-Joseph, Z., Gifford, D.K., and Jaakkola, T.S. Fast optimal leaf ordering for hierarchical clustering. Bioinformatics vol. 17 suppl. 1, 2001.

See also: dendrogram, linkage, pdist

Source Code: optimalleaforder

### Example: 1

     randn ("seed", 5)  # for reproducibility
     X = randn (10, 2);
     D = pdist (X);
     tree = linkage(D, 'average');
     optimalleaforder (tree, D, 'Transformation', 'linear')

    ans =

       10    8    3    5    9    7    2    4    6    1