public void DataSetManipulationsTest() { UncertainMeasurement <double> d1 = new UncertainMeasurement <double>(3.0, new UncertainValue(2.0, 1.0)); UncertainMeasurement <double> d2 = new UncertainMeasurement <double>(-3.0, new UncertainValue(2.0, 1.0)); UncertainMeasurement <double> d3 = new UncertainMeasurement <double>(3.0, new UncertainValue(-2.0, 1.0)); Assert.IsTrue(d1 != null); UncertainMeasurement <double>[] data = new UncertainMeasurement <double>[] { d1, d2 }; UncertainMeasurementSample set = new UncertainMeasurementSample(); set.Add(data); Assert.IsFalse(set.Contains(d3)); Assert.IsTrue(set.Count == data.Length); set.Add(d3); Assert.IsTrue(set.Contains(d3)); Assert.IsTrue(set.Count == data.Length + 1); set.Remove(d3); Assert.IsFalse(set.Contains(d3)); Assert.IsTrue(set.Count == data.Length); set.Clear(); Assert.IsTrue(set.Count == 0); }
public void Bug6162() { // When UncertianMeasurementSample.FitToPolynomial used Cholesky inversion of (A^T A), this inversion // would fail when roundoff errors would made the matrix non-positive-definite. We have now changed // to QR decomposition, which is more robust. //real data double[] X_axis = new double[] { 40270.65625, 40270.6569444444, 40270.6576388888, 40270.6583333332, 40270.6590277776, 40270.659722222, 40270.6604166669, 40270.6611111113, 40270.6618055557, 40270.6625000001 }; double[] Y_axis = new double[] { 246.824996948242, 246.850006103516, 245.875, 246.225006103516, 246.975006103516, 247.024993896484, 246.949996948242, 246.875, 247.5, 247.100006103516 }; UncertainMeasurementSample DataSet = new UncertainMeasurementSample(); for (int i = 0; i < 10; i++) { DataSet.Add(X_axis[i], Y_axis[i], 1); } UncertainMeasurementFitResult DataFit = DataSet.FitToPolynomial(3); BivariateSample bs = new BivariateSample(); for (int i = 0; i < 10; i++) { bs.Add(X_axis[i], Y_axis[i]); } PolynomialRegressionResult bsFit = bs.PolynomialRegression(3); foreach (Parameter p in bsFit.Parameters) { Console.WriteLine(p); } }
public void FitDataToFunctionTest() { // create a data set from a nonlinear function /* * Interval r = Interval.FromEndpoints(-3.0, 5.0); * double[] c = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; * Function<double, double> fv = delegate(double x) { * return (3.0 * Math.Cos(2.0 * Math.PI * x / 2.0 - 1.0)); * }; * Function<double, double> fu = delegate(double x) { * return (0.1 + 0.1 * Math.Abs(x)); * }; * DataSet set = CreateDataSet(r, fv, fu, 20, 2); */ UncertainMeasurementSample set = new UncertainMeasurementSample(); set.Add(new UncertainMeasurement <double>(1.0, 1.0, 0.1)); set.Add(new UncertainMeasurement <double>(2.0, 0.7, 0.1)); set.Add(new UncertainMeasurement <double>(3.0, 0.0, 0.1)); set.Add(new UncertainMeasurement <double>(4.0, -0.7, 0.1)); set.Add(new UncertainMeasurement <double>(5.0, -1.0, 0.1)); set.Add(new UncertainMeasurement <double>(6.0, -0.7, 0.1)); set.Add(new UncertainMeasurement <double>(7.0, 0.0, 0.1)); set.Add(new UncertainMeasurement <double>(8.0, 0.7, 0.1)); set.Add(new UncertainMeasurement <double>(9.0, 1.0, 0.1)); // fit it to a parameterized fit function /* * Function<double[], double, double> ff = delegate(double[] p, double x) { * return (p[0] * Math.Cos(2.0 * Math.PI / p[1] + p[2])); * }; */ Func <double[], double, double> ff = delegate(double[] p, double x) { //Console.WriteLine(" p[0]={0}, x={1}", p[0], x); return(p[1] * Math.Cos(x / p[0] + p[2])); //return (x / p[0]); }; FitResult fit = set.FitToFunction(ff, new double[] { 1.3, 1.1, 0.1 }); Console.WriteLine(fit.Parameter(0)); Console.WriteLine(fit.Parameter(1)); Console.WriteLine(fit.Parameter(2)); }
private UncertainMeasurementSample CreateDataSet(double[] xs, Func <double, double> fv, Func <double, double> fu, int seed) { UncertainMeasurementSample set = new UncertainMeasurementSample(); Random rng = new Random(seed); foreach (double x in xs) { double ym = fv(x); double ys = fu(x); NormalDistribution yd = new NormalDistribution(ym, ys); double y = yd.InverseLeftProbability(rng.NextDouble()); UncertainMeasurement <double> point = new UncertainMeasurement <double>(x, y, ys); set.Add(point); } return(set); }
private UncertainMeasurementSample CreateDataSet(Interval r, Func <double, double> fv, Func <double, double> fu, int n, int seed) { UncertainMeasurementSample set = new UncertainMeasurementSample(); UniformDistribution xd = new UniformDistribution(r); Random rng = new Random(seed); for (int i = 0; i < n; i++) { double x = xd.InverseLeftProbability(rng.NextDouble()); double ym = fv(x); double ys = fu(x); NormalDistribution yd = new NormalDistribution(ym, ys); double y = yd.InverseLeftProbability(rng.NextDouble()); //Console.WriteLine("{0}, {1}", x, new UncertainValue(y, ys)); UncertainMeasurement <double> point = new UncertainMeasurement <double>(x, y, ys); set.Add(point); } return(set); }
public void Bug6162() { // When UncertianMeasurementSample.FitToPolynomial used Cholesky inversion of (A^T A), this inversion // would fail when roundoff errors would made the matrix non-positive-definite. We have now changed // to QR decomposition, which is more robust. //real data double[] X_axis = new double[] { 40270.65625, 40270.6569444444, 40270.6576388888, 40270.6583333332, 40270.6590277776, 40270.659722222, 40270.6604166669, 40270.6611111113, 40270.6618055557, 40270.6625000001 }; double[] Y_axis = new double[] { 246.824996948242, 246.850006103516, 245.875, 246.225006103516, 246.975006103516, 247.024993896484, 246.949996948242, 246.875, 247.5, 247.100006103516 }; UncertainMeasurementSample DataSet = new UncertainMeasurementSample(); for (int i = 0; i < 10; i++) DataSet.Add(X_axis[i], Y_axis[i], 1); //for (int i = 0; i < 10; i++) DataSet.Add(X_axis[i] - 40270.0, Y_axis[i] - 247.0, 1); FitResult DataFit = DataSet.FitToPolynomial(3); for (int i = 0; i < DataFit.Dimension; i++) Console.WriteLine("a" + i.ToString() + " = " + DataFit.Parameter(i).Value); BivariateSample bs = new BivariateSample(); for (int i = 0; i < 10; i++) bs.Add(X_axis[i], Y_axis[i]); FitResult bsFit = bs.PolynomialRegression(3); for (int i = 0; i < bsFit.Dimension; i++) Console.WriteLine(bsFit.Parameter(i)); }