
Auxiliary Functions for Caching Statistics of Parts/Topics
**********************************************************

datastat_*:  Cache and manipulate sufficient statistics of data
===========
These methods recursively update cached sufficient statistics as data
points are added or removed from mixture components, compute predictive 
likelihoods, and estimate or sample parameters given data.  Each function
has a switch statement choosing among several supported datatypes
(a class hierarchy would have been cleaner, but turned out too slow).

The related dataparam_* methods work with parameters generated from these
cached statistics by estimation or sampling.

type=discrete:  Multinomial with finite Dirichlet prior
--------------
Internal: dtype=1
Hyperparameters:
- numfeature: Number of discrete categories appearing in data
- dirweight:  Equal weight assigned to each category by Dirichlet prior
Data format:
- datass(1,ii) is a positive integer in {1,...,numfeature}
Cached statistics:
- classqq(:,cc) is a numfeature-dimensional vector giving the posterior
  mass of each category (dirweight plus number of observed instances)

type=gaussian:  Multivariate Gaussian with normal-inverse-Wishart prior
--------------
Internal: dtype=2
Hyperparameters:
- emean:  Prior expectation for Gaussian mean (Dx1 vector)
- cmean:  Confidence (pseudodata) for prior mean (positive scalar)
- ecovar: Prior expectation for Gaussian covariance (DxD matrix)
- ccovar: Confidence (pseudodata) for prior covariance (positive scalar)
Data format:
- datass(:,ii) is a Dx1 vector of real numbers
Cached statistics:
- classqq(1:D,cc) is the sum of all observed data, plus a rescaled 
  multiple of the expected data mean
- classqq(D+1:end-1,cc) is a vectorized Cholesky decomposition of the
  sum of outer products of all observed data, plus a rescaled 
  multiple of the expected data covariance
- classqq(end,cc) is a Gaussian normalization constant, related to the
  posterior covariance's log-det, which is cached for efficiency

type=diagonalgaussian:  Diagonal Gaussian with normal-inverse-chi2 priors
----------------------
Internal: dtype=3
Hyperparameters:
- emean:  Prior expectation for Gaussian mean (Dx1 vector)
- cmean:  Confidence (pseudodata) for prior mean (positive scalar)
- ecovar: Prior expectation for Gaussian variances (Dx1 or DxD diagonal)
- ccovar: Confidence (pseudodata) for prior variances (positive scalar)
Data format:
- datass(:,ii) is a Dx1 vector of real numbers
Cached statistics:
- classqq(1:D,cc) is the sum of all observed data, plus a rescaled 
  multiple of the expected data mean
- classqq(D+1:2*D,cc) is the square root of the sum of squares of all
  observed data, plus a rescaled multiple of the expected data variance
- classqq(2*D+1,cc) is a Gaussian normalization constant, related to the
  posterior covariance's log-det, which is cached for efficiency

type=zeromeangaussian:  Zero-mean multivariate Gaussian with inverse-Wishart prior
----------------------
Internal: dtype=4
Hyperparameters:
- ecovar: Prior expectation for Gaussian covariance (DxD matrix)
- ccovar: Confidence (pseudodata) for prior covariance (positive scalar)
Data format:
- datass(:,ii) is a Dx1 vector of real numbers
Cached statistics:
- classqq(1:D^2,cc) is a vectorized Cholesky decomposition of the
  sum of outer products of all observed data, plus a rescaled 
  multiple of the expected data covariance
- classqq(D^2+1,cc) is a Gaussian normalization constant, related to the
  posterior covariance's log-det, which is cached for efficiency

type=zeromeandiagonalgaussian:  Zero-mean diagonal Gaussian with inverse-chi2 priors
------------------------------
Internal: dtype=5
Hyperparameters:
- ecovar: Prior expectation for Gaussian variances (Dx1 or DxD diagonal)
- ccovar: Confidence (pseudodata) for prior variances (positive scalar)
Data format:
- datass(:,ii) is a Dx1 vector of real numbers
Cached statistics:
- classqq(1:D,cc) is the square root of the sum of squares of all
  observed data, plus a rescaled multiple of the expected data variance
- classqq(D+1,cc) is a Gaussian normalization constant, related to the
  posterior covariance's log-det, which is cached for efficiency


transtat_*:  Cache and manipulate sufficient statistics of transformations
===========
These methods recursively update cached sufficient statistics as 
transformations are added or removed from mixture components, 
compute predictive likelihoods, and estimate or sample parameters.
Each function has a switch statement choosing among several supported 
transformation types, which are constrained zero-mean for identifiability.

The related tranparam_* methods work with parameters generated from these
cached statistics by estimation or sampling.

type=zeromeangaussian:  Multivariate Gaussian with inverse-Wishart prior
----------------------
Internal: ttype=1
Hyperparameters:
- ecovar: Prior expectation for Gaussian covariance (DxD matrix)
- ccovar: Confidence (pseudodata) for prior covariance (positive scalar)
Transformation format:
- tranrr(:,tt) is a Dx1 vector of real numbers
Cached statistics:
- classpp(1:D^2,cc) is a vectorized Cholesky decomposition of the
  sum of outer products of all observed data, plus a rescaled 
  multiple of the expected data covariance
- classpp(D^2+1,cc) is a Gaussian normalization constant, related to the
  posterior covariance's log-det, which is cached for efficiency

type=zeromeandiagonalgaussian:  Diagonal Gaussian with inverse-chi2 priors
------------------------------
Internal: ttype=2
Hyperparameters:
- ecovar: Prior expectation for Gaussian variances (Dx1 or DxD diagonal)
- ccovar: Confidence (pseudodata) for prior variances (positive scalar)
Transformation format:
- tranrr(:,tt) is a Dx1 vector of real numbers
Cached statistics:
- classpp(1:D,cc) is the square root of the sum of squares of all
  observed data, plus a rescaled multiple of the expected data variance
- classpp(D+1,cc) is a Gaussian normalization constant, related to the
  posterior covariance's log-det, which is cached for efficiency


trandata_*:  Compute transformation marginals given multiple datapoints
===========
Helper methods used for blocked Gibbs sampling of the global cluster 
assignment for a given table, and that table's corresponding transformation.
Compute marginal likelihoods of data, integrating over transformations,
and posterior distributions of transformations given data.

