Mercurial > hg > jslab
comparison src/samer/models/GaussianStatsOnline.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
3 * All rights reserved. | |
4 * | |
5 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
6 * without even the implied warranty of MERCHANTABILITY or | |
7 * FITNESS FOR A PARTICULAR PURPOSE. | |
8 */ | |
9 | |
10 package samer.models; | |
11 import samer.core.*; | |
12 import samer.maths.*; | |
13 import samer.core.types.*; | |
14 | |
15 /** | |
16 Similar to GaussianStats: | |
17 Collect statistics about a vector: accumulates | |
18 sums and sums of products, then computes mean | |
19 and covariance. | |
20 | |
21 This is NOT a model! Computing energies and probabilities | |
22 directly from the first and second moments is horrible, since | |
23 you need the inverse of the covariance matrix. You could, | |
24 however, use this to train a Gaussian model. | |
25 | |
26 BUT uses a moving average with a learning rate to track changes | |
27 */ | |
28 | |
29 public class GaussianStatsOnline extends GaussianStats | |
30 { | |
31 VDouble rate1,rate2; | |
32 | |
33 public GaussianStatsOnline(VVector vec) throws Exception | |
34 { | |
35 super(vec); | |
36 rate1 = new VDouble("mean.rate",0.0001); | |
37 rate2 = new VDouble("cov.rate",0.0001); | |
38 sumx.addSaver(); | |
39 count=1; // should stay that way. | |
40 } | |
41 | |
42 public void reset() { super.reset(); count=1; } | |
43 public void dispose() { rate2.dispose(); rate1.dispose(); super.dispose(); } | |
44 public void run() | |
45 { | |
46 double r; | |
47 | |
48 r=rate1.value; | |
49 for (int i=0; i<n; i++) _sumx[i] += r*(x[i]-_sumx[i]); | |
50 | |
51 r=rate2.value; | |
52 for (int i=0; i<n; i++) { | |
53 double [] a=_sumxx[i]; | |
54 double k=x[i]; | |
55 for (int j=0; j<=i; j++) { | |
56 a[j] += r*(k*x[j]-a[j]); | |
57 } | |
58 } | |
59 sumx.changed(); | |
60 sumxx.changed(); | |
61 } | |
62 } | |
63 |