view src/samer/models/GaussianStatsOnline.java @ 5:b67a33c44de7

Remove some crap, etc
author samer
date Fri, 05 Apr 2019 21:34:25 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.models;
import  samer.core.*;
import  samer.maths.*;
import  samer.core.types.*;

/**
	Similar to GaussianStats:
		Collect statistics about a vector: accumulates
		sums and sums of products, then computes mean
		and covariance.
	
		This is NOT a model! Computing energies and probabilities
		directly from the first and second moments is horrible, since
		you need the inverse of the covariance matrix. You could,
		however, use this to train a Gaussian model.

	BUT uses a moving average with a learning rate to track changes 
 */

public class GaussianStatsOnline extends GaussianStats
{
	VDouble	rate1,rate2;

	public GaussianStatsOnline(VVector vec) throws Exception
	{
		super(vec);
		rate1 = new VDouble("mean.rate",0.0001);
		rate2 = new VDouble("cov.rate",0.0001);
		sumx.addSaver();
		count=1; // should stay that way.
	}

	public void reset() { super.reset(); count=1; }
	public void dispose() { rate2.dispose(); rate1.dispose(); super.dispose(); }
	public void run()
	{
		double r;
		
		r=rate1.value;
		for (int i=0; i<n; i++) _sumx[i] += r*(x[i]-_sumx[i]);
		
		r=rate2.value;
		for (int i=0; i<n; i++) {
			double  [] a=_sumxx[i];
			double  k=x[i];
			for (int j=0; j<=i; j++) {
				a[j] += r*(k*x[j]-a[j]);
			}
		}
		sumx.changed();
		sumxx.changed();
	}
}