commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garrett Kane <gk...@us.ibm.com>
Subject Re: [MATH] Kalman Filter
Date Thu, 26 Jul 2012 17:12:00 GMT

The code I am using (copied from the apache commons page on the kalman
filter) is:
public class Kalman {
	void main(){
		System.out.println("BEGINNING");
		double constantVoltage = 10d;
		double measurementNoise = 0.1d;
		double processNoise = 1e-5d;

		// A = [ 1 ]
		RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d });
		// B = null
		RealMatrix B = null;
		// H = [ 1 ]
		RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d });
		// x = [ 10 ]
		RealVector x = new ArrayRealVector(new double[]
{ constantVoltage });
		// Q = [ 1e-5 ]
		RealMatrix Q = new Array2DRowRealMatrix(new double[]
{ processNoise });
		// P = [ 1 ]
		RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 1d });
		// R = [ 0.1 ]
		RealMatrix R = new Array2DRowRealMatrix(new double[]
{ measurementNoise });
		System.out.println("anywhere");
		ProcessModel pm = new DefaultProcessModel(A, B, Q, x, P0);
		MeasurementModel mm = new DefaultMeasurementModel(H, R);
		KalmanFilter filter = new KalmanFilter(pm, mm);
		System.out.println("there");
		// process and measurement noise vectors
		RealVector pNoise = new ArrayRealVector(1);
		RealVector mNoise = new ArrayRealVector(1);
		System.out.println("here");
		RandomGenerator rand = new JDKRandomGenerator();
		// iterate 60 steps
		for (int i = 0; i < 60; i++) {
			System.out.println("beginning");
			filter.predict();

			System.out.println("after Predict");
			// simulate the process
			pNoise.setEntry(0, processNoise * rand.nextGaussian());

			System.out.println("after setEntry");
			// x = A * x + p_noise
			x = A.operate(x).add(pNoise);

			System.out.println("after adding pNoise");
			// simulate the measurement
			mNoise.setEntry(0, measurementNoise * rand.nextGaussian
());

			System.out.println("after 2nd setEntry");
			// z = H * x + m_noise
			RealVector z = H.operate(x).add(mNoise);

			System.out.println("after adding mNoise");
			filter.correct(z);

			System.out.println("after correct");
			double voltage = filter.getStateEstimation()[0];
			System.out.println("at the end");
		}
	}
}

Here is a (very small) sample of the output.  full output is over 1100
lines.
EXP_INT_TABLE_A=
    {
        +0.0d,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        Double.NaN,
        +1.2167807682331913E-308d,
        +3.3075532478807267E-308d,
        +8.990862214387203E-308d,
    };
EXP_INT_TABLE_B=
    {
        +0.0d,
        Double.NaN,
        Double.NaN,
        Double.NaN,
    };
LN_MANT
    {
        {+0.0d,                   +0.0d,                   }, // 0
        {+9.760860120877624E-4d,  -3.903230345984362E-11d, }, // 1
        {+0.0019512202125042677d, -8.124251825289188E-11d, }, // 2
        {+0.0029254043474793434d, -1.8374207360194882E-11d,}, // 3
        {+0.0038986406289041042d, -2.1324678121885073E-10d,}, // 4
        {+0.004870930686593056d,  -4.5199654318611534E-10d,}, // 5
        {+0.00584227591753006d,   -2.933016992001806E-10d, }, // 6
        {+0.006812678650021553d,  -2.325147219074669E-10d, }, // 7
        {+0.007782140746712685d,  -3.046577356838847E-10d, }, // 8
        {+0.008750664070248604d,  -5.500631513861575E-10d, }, // 9
  {+0.6916812658309937d,    -2.9535446262017846E-9d, }, // 1021
        {+0.6921701431274414d,    -2.2153227096187463E-9d, }, // 1022
        {+0.6926587820053101d,    -1.943473623641502E-9d,  }, // 1023
    };
SINE_TABLE_A=
    {
        +0.0d,
        +0.1246747374534607d,
        +0.24740394949913025d,
        +0.366272509098053d,


The output contains A and B tables for sine, cosine, and tangent. The A
tables seem to be on the numerical scale of SINE_TABLE_A, and the B tables
are on the scale of E-8 or so.


From:	Gilles Sadowski <gilles@harfang.homelinux.org>
To:	user@commons.apache.org,
Date:	07/26/2012 11:54
Subject:	Re: [MATH] Kalman Filter



On Thu, Jul 26, 2012 at 11:21:09AM -0400, Garrett Kane wrote:
>
>
> I am having trouble understanding the output of the Kalman Filter in math
> 3.0 is there anyone who can explain to me what the various trigonometric,
> exp, and lp_mant tables in the console output are used for? my eventual
> goal is to feed output from this filter into a graphing engine to compare
> real/predicted data but obviously I need to understand the output first.
> Thanks
> -Garrett

http://markmail.org/message/a2r45shfg7w2iw7f


Regards,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message