|
Java example source code file (ConstantVoltageExample.java)
The ConstantVoltageExample.java Java example source code/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with this * work for additional information regarding copyright ownership. The ASF * licenses this file to You under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law * or agreed to in writing, software distributed under the License is * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.apache.commons.math3.userguide.filter; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JComponent; import javax.swing.JPanel; import org.apache.commons.math3.filter.DefaultMeasurementModel; import org.apache.commons.math3.filter.DefaultProcessModel; import org.apache.commons.math3.filter.KalmanFilter; import org.apache.commons.math3.filter.MeasurementModel; import org.apache.commons.math3.filter.ProcessModel; import org.apache.commons.math3.linear.Array2DRowRealMatrix; import org.apache.commons.math3.linear.ArrayRealVector; import org.apache.commons.math3.linear.RealMatrix; import org.apache.commons.math3.linear.RealVector; import org.apache.commons.math3.random.RandomGenerator; import org.apache.commons.math3.random.Well19937c; import org.apache.commons.math3.userguide.ExampleUtils; import org.apache.commons.math3.userguide.ExampleUtils.ExampleFrame; import com.xeiam.xchart.Chart; import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.Series; import com.xeiam.xchart.SeriesLineStyle; import com.xeiam.xchart.SeriesMarker; import com.xeiam.xchart.XChartPanel; import com.xeiam.xchart.StyleManager.ChartType; import com.xeiam.xchart.StyleManager.LegendPosition; public class ConstantVoltageExample { public static class VoltMeter { private final double initialVoltage; private final double processNoise; private final double measurementNoise; private final RandomGenerator rng; private double voltage; public VoltMeter(double voltage, double processNoise, double measurementNoise, int seed) { this.initialVoltage = voltage; this.voltage = voltage; this.processNoise = processNoise; this.measurementNoise = measurementNoise; rng = new Well19937c(seed); } /** * Returns the real voltage without any measurement noise. * * @return the real voltage */ public double getVoltage() { return voltage; } public double getMeasuredVoltage() { return getVoltage() + rng.nextGaussian() * measurementNoise; } public void step() { // we apply only the process noise voltage = initialVoltage + rng.nextGaussian() * processNoise; } } /** constant voltage test */ public static void constantVoltageTest(Chart chart1, Chart chart2) { final double voltage = 1.25d; final double measurementNoise = 0.2d; // measurement noise (V) - std dev final double processNoise = 1e-5d; final VoltMeter voltMeter = new VoltMeter(voltage, processNoise, measurementNoise, 2); // the state transition matrix -> constant final RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d }); // the control matrix -> no control input final RealMatrix B = new Array2DRowRealMatrix(new double[] { 0d }); // the measurement matrix -> we measure the voltage directly final RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d }); // the initial state vector -> slightly wrong final RealVector x0 = new ArrayRealVector(new double[] { 1.45 }); // the process covariance matrix final RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise * processNoise }); // the initial error covariance -> assume a large error at the beginning final RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 0.1 }); // the measurement covariance matrix -> put the "real" variance RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise * measurementNoise }); final ProcessModel pm = new DefaultProcessModel(A, B, Q, x0, P0); final MeasurementModel mm = new DefaultMeasurementModel(H, R); final KalmanFilter filter = new KalmanFilter(pm, mm); final List<Number> xAxis = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java ConstantVoltageExample.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.