samer@0: /* samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.models; samer@0: import samer.core.*; samer@0: import samer.maths.*; samer@0: import samer.core.types.*; samer@0: samer@0: /** samer@0: Similar to GaussianStats: samer@0: Collect statistics about a vector: accumulates samer@0: sums and sums of products, then computes mean samer@0: and covariance. samer@0: samer@0: This is NOT a model! Computing energies and probabilities samer@0: directly from the first and second moments is horrible, since samer@0: you need the inverse of the covariance matrix. You could, samer@0: however, use this to train a Gaussian model. samer@0: samer@0: BUT uses a moving average with a learning rate to track changes samer@0: */ samer@0: samer@0: public class GaussianStatsOnline extends GaussianStats samer@0: { samer@0: VDouble rate1,rate2; samer@0: samer@0: public GaussianStatsOnline(VVector vec) throws Exception samer@0: { samer@0: super(vec); samer@0: rate1 = new VDouble("mean.rate",0.0001); samer@0: rate2 = new VDouble("cov.rate",0.0001); samer@0: sumx.addSaver(); samer@0: count=1; // should stay that way. samer@0: } samer@0: samer@0: public void reset() { super.reset(); count=1; } samer@0: public void dispose() { rate2.dispose(); rate1.dispose(); super.dispose(); } samer@0: public void run() samer@0: { samer@0: double r; samer@0: samer@0: r=rate1.value; samer@0: for (int i=0; i