Mathematical folds with Tesser
We should now understand how to use folds to calculate parallel implementations of simple algorithms. Hopefully, we should also have some appreciation for the ingenuity required to find efficient solutions that will perform the minimum number of iterations over the data.
Fortunately, the Clojure library Tesser (https://github.com/aphyr/tesser) includes implementations for common mathematical folds, including the mean, standard deviation, and covariance. To see how to use Tesser, let's consider the covariance of two fields from the IRS dataset: the salaries and wages, A00200
, the unemployment compensation, A02300
.
Calculating covariance with Tesser
We encountered covariance in Chapter 3, Correlation, as a measure of how two sequences of data vary together. The formula is reproduced as follows:
A covariance fold is included in tesser.math
. In the following code, we'll include tesser.math
as m
and tesser.core
as t
:
(defn ex-5-17 [] (let [data (into [] (load-data...