test_class.declarator: log = LoggerFactory.getLogger(KalmanVectorFilterTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger log = LoggerFactory.getLogger(KalmanVectorFilterTest.class);
test_class.type: Logger
test_class.var_name: log
test_class.file: contrib/src/test/java/macrobase/analysis/stats/kalmanfilter/KalmanVectorFilterTest.java
test_class.identifier: KalmanVectorFilterTest
test_case.body: @Test
      public void runTest() throws Exception {
          MacroBaseConf conf = new MacroBaseConf()
                  .set(MacroBaseConf.RANDOM_SEED, 4)
                  .set(MacroBaseConf.DATA_LOADER_TYPE, "CSV_LOADER")
                  .set(MacroBaseConf.CSV_COMPRESSION, CSVIngester.Compression.GZIP)
                  .set(MacroBaseConf.CSV_INPUT_FILE, "src/test/resources/data/2gaussians-500points.csv.gz")
                  .set(MacroBaseConf.METRICS, "XX, YY")
                  .set(MacroBaseConf.ATTRIBUTES, "");
          List<Datum> data = Drainer.drainIngest(conf);
          assertEquals(500, data.size());
  
          KalmanVectorFilter f = new KalmanVectorFilter(new ArrayRealVector(2), 1e-6, 1.);
  
          List<Datum> oneCluster = data.subList(201, 500);
          List<RealVector> filtered = oneCluster.stream().map(d -> f.step(d.metrics(), 1)).collect(Collectors.toList());
          List<Datum> unfilteredlast10 = oneCluster.subList(oneCluster.size() - 10, oneCluster.size());
          List<RealVector> filteredlast10 = filtered.subList(filtered.size() - 10, filtered.size());
          double filteredMax = filteredlast10.stream().mapToDouble(d -> d.getEntry(0)).max().getAsDouble();
          double filteredMin = filteredlast10.stream().mapToDouble(d -> d.getEntry(0)).min().getAsDouble();
          double unfilteredMax = unfilteredlast10.stream().mapToDouble(d -> d.metrics().getEntry(0)).max().getAsDouble();
          double unfilteredMin = unfilteredlast10.stream().mapToDouble(d -> d.metrics().getEntry(0)).min().getAsDouble();
          assert filteredMax < unfilteredMax;
          assert filteredMin > unfilteredMin;
      }
test_case.class_method_signature: KalmanVectorFilterTest.runTest()
test_case.full_signature: @Test public void runTest()
test_case.identifier: runTest
test_case.invocations: set set set set set set drainIngest assertEquals size subList collect map stream step metrics toList subList size size subList size size getAsDouble max mapToDouble stream getEntry getAsDouble min mapToDouble stream getEntry getAsDouble max mapToDouble stream getEntry metrics getAsDouble min mapToDouble stream getEntry metrics
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void runTest()
focal_class.declarator: log = LoggerFactory.getLogger(KalmanVectorFilter.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(KalmanVectorFilter.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: qScale
focal_class.modifier: protected
focal_class.original_string: protected double qScale;
focal_class.type: double
focal_class.var_name: qScale
focal_class.declarator: rScale
focal_class.modifier: protected
focal_class.original_string: protected double rScale;
focal_class.type: double
focal_class.var_name: rScale
focal_class.declarator: H
focal_class.modifier: private final
focal_class.original_string: private final RealMatrix H;
focal_class.type: RealMatrix
focal_class.var_name: H
focal_class.declarator: state
focal_class.modifier: protected
focal_class.original_string: protected RealMatrix state;
focal_class.type: RealMatrix
focal_class.var_name: state
focal_class.declarator: cov
focal_class.modifier: protected
focal_class.original_string: protected RealMatrix cov;
focal_class.type: RealMatrix
focal_class.var_name: cov
focal_class.file: contrib/src/main/java/macrobase/analysis/stats/kalmanfilter/KalmanVectorFilter.java
focal_class.identifier: KalmanVectorFilter
focal_class.class_method_signature: KalmanVectorFilter.KalmanVectorFilter(RealVector startLoc, double qScale)
focal_class.full_signature: public  KalmanVectorFilter(RealVector startLoc, double qScale)
focal_class.identifier: KalmanVectorFilter
focal_class.modifiers: public
focal_class.parameters: (RealVector startLoc, double qScale)
focal_class.signature:  KalmanVectorFilter(RealVector startLoc, double qScale)
focal_class.class_method_signature: KalmanVectorFilter.KalmanVectorFilter(RealVector startLoc, double qScale, double rScale)
focal_class.full_signature: public  KalmanVectorFilter(RealVector startLoc, double qScale, double rScale)
focal_class.identifier: KalmanVectorFilter
focal_class.modifiers: public
focal_class.parameters: (RealVector startLoc, double qScale, double rScale)
focal_class.signature:  KalmanVectorFilter(RealVector startLoc, double qScale, double rScale)
focal_class.class_method_signature: KalmanVectorFilter.reset(RealVector startLoc)
focal_class.full_signature: public void reset(RealVector startLoc)
focal_class.identifier: reset
focal_class.modifiers: public
focal_class.parameters: (RealVector startLoc)
focal_class.return: void
focal_class.signature: void reset(RealVector startLoc)
focal_class.class_method_signature: KalmanVectorFilter.measure(RealMatrix state)
focal_class.full_signature: protected RealVector measure(RealMatrix state)
focal_class.identifier: measure
focal_class.modifiers: protected
focal_class.parameters: (RealMatrix state)
focal_class.return: RealVector
focal_class.signature: RealVector measure(RealMatrix state)
focal_class.class_method_signature: KalmanVectorFilter.step(RealVector observation, int time)
focal_class.full_signature: public RealVector step(RealVector observation, int time)
focal_class.identifier: step
focal_class.modifiers: public
focal_class.parameters: (RealVector observation, int time)
focal_class.return: RealVector
focal_class.signature: RealVector step(RealVector observation, int time)
focal_method.body: public RealVector step(RealVector observation, int time) {
          // Create g = [t^2 / 2, t]^T matrix
          RealVector g = new ArrayRealVector(2);
          g.setEntry(0, 0.5 * time * time);
          g.setEntry(1, time);
          RealMatrix Q = g.outerProduct(g).scalarMultiply(qScale);
          RealMatrix R = MatrixUtils.createRealIdentityMatrix(1).scalarMultiply(rScale);
          R = R.scalarMultiply(time * time);
  
          RealMatrix F = MatrixUtils.createRealIdentityMatrix(2);
          F.setEntry(0, 1, time);
  
          RealMatrix priorNextState = F.multiply(state);
          RealMatrix priorNextCov = F.multiply(cov).multiply(F.transpose()).add(Q); // F * cov * F^T + Q
  
          RealVector measurementResidual = observation.subtract(measure(priorNextState)); // row vector
          RealMatrix residualCovariance = H.multiply(priorNextCov).multiply(H.transpose()).add(R);
          RealMatrix kalmanGain = priorNextCov.multiply(H.transpose()).multiply(AlgebraUtils.invertMatrix(residualCovariance));
          // kalmanGain should be a 1x2 matrix
          state = priorNextState.add(kalmanGain.getColumnVector(0).outerProduct(measurementResidual));
          cov = MatrixUtils.createRealIdentityMatrix(2).subtract(kalmanGain.multiply(H)).multiply(priorNextCov);
  
          return measure(state);
      }
focal_method.class_method_signature: KalmanVectorFilter.step(RealVector observation, int time)
focal_method.full_signature: public RealVector step(RealVector observation, int time)
focal_method.identifier: step
focal_method.invocations: setEntry setEntry scalarMultiply outerProduct scalarMultiply createRealIdentityMatrix scalarMultiply createRealIdentityMatrix setEntry multiply add multiply multiply transpose subtract measure add multiply multiply transpose multiply multiply transpose invertMatrix add outerProduct getColumnVector multiply subtract createRealIdentityMatrix multiply measure
focal_method.modifiers: public
focal_method.parameters: (RealVector observation, int time)
focal_method.return: RealVector
focal_method.signature: RealVector step(RealVector observation, int time)