Exemplo n.º 1
0
 public void FromTwoPointsは2つの点から直線を求める(double x0, double y0, double x1, double y1, double expectedA,
     double expectedB)
 {
     var lf = new Linear(new Point(x0, y0), new Point(x1, y1));
     Assert.AreEqual(expectedA, lf.A);
     Assert.AreEqual(expectedB, lf.B);
 }
Exemplo n.º 2
0
 public void InverseFunctionは引数0の時0()
 {
     var lf = new Linear(0, 0);
     var f = lf.InverseFunction;
     Assert.AreEqual(0, f(1));
     Assert.AreEqual(0, f(2));
     Assert.AreEqual(0, f(3));
 }
Exemplo n.º 3
0
 public void InverseFunctionはFunctionの逆関数(double arg)
 {
     var lf = new Linear(2, 3);
     var f = lf.InverseFunction(lf.Function(arg));
     var g = lf.Function(lf.InverseFunction(arg));
     Assert.AreEqual(arg, f);
     Assert.AreEqual(arg, g);
 }
Exemplo n.º 4
0
        public void GetLeastSquareLineTest_Intercept()
        {
            var expected = new Linear(1.8993, 0);
            const double expectedR2 = 0.8653;

            var actual = Statistics.GetLeastSquaresLine(TestPoints(), 0.0);
            var actualR2 = Statistics.GetR2(actual, TestPoints());
            Assert.AreEqual(expected.A, actual.A, 0.001);
            Assert.AreEqual(expected.B, actual.B, 0.001);
            Assert.AreEqual(expectedR2, actualR2, 0.01);
        }
Exemplo n.º 5
0
        public void GetLeastSquareLineTest()
        {
            var expected = new Linear(1.4872, 13.762);
            const double expectedR2 = 0.9454;

            var actual = Statistics.GetLeastSquaresLine(TestPoints());
            var actualR2 = Statistics.GetR2(actual, TestPoints());
            Assert.AreEqual(expected.A, actual.A, 0.001);
            Assert.AreEqual(expected.B, actual.B, 0.001);
            Assert.AreEqual(expectedR2, actualR2, 0.01);
        }
Exemplo n.º 6
0
        public static double GetR2(Linear func, [NotNull] IEnumerable<Point> points)
        {
            if (points == null) throw new ArgumentNullException("points");

            var pointArray = points as Point[] ?? points.ToArray();
            if (!pointArray.Any())
                throw new ArgumentException("points");

            var f = func.Function;
            var a = pointArray.Sum(p => Math.Pow(p.Y - f(p.X), 2));
            var ave = pointArray.Average(p => p.Y);
            var b = pointArray.Sum(p => Math.Pow(p.Y - ave, 2));

            return !b.IsZero() ? 1.0 - (a/b) : 0.0;
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Saves the current set of spectrums in a CSV file.
        /// </summary>
        public static void SaveAsCsv([NotNull] double[][] spectrums, double realTime, double liveTime, Linear intoEnergy,
            [NotNull] string path)
        {
            if (spectrums == null) throw new ArgumentNullException("spectrums");

            var sb = new StringBuilder();
            sb.AppendLine("RT," + realTime);
            sb.AppendLine("LT," + liveTime);
            sb.AppendLine("CAL," + intoEnergy);

            foreach (var j in Enumerable.Range(0, NumOfChannels)) {
                var j1 = j;
                sb.AppendLine(Enumerable.Range(0, spectrums.Count())
                    .Select(i => spectrums[i][j1].ToString(CultureInfo.InvariantCulture))
                    .ConcatWithComma());
            }

            File.WriteAllText(path, sb.ToString());
        }
Exemplo n.º 8
0
        public void XPlotRegionTest()
        {
            var cr = new Region(0, 1000);
            var calibrated = new Region(3, 2003);
            var calibration = new Linear(2, 3);
            var sg = new SpectralGraph {
                XChannelRegion = cr,
                IsCalibrated = false,
                Calibration = calibration
            };

            Assert.AreEqual(cr, sg.XChannelRegion);
            Assert.AreEqual(cr, sg.XPlotRegion);

            sg.IsCalibrated = true;
            Assert.AreEqual(cr, sg.XChannelRegion);
            Assert.AreEqual(calibrated, sg.XPlotRegion);

            sg.Calibration = new Linear(3, 4);
            Assert.AreEqual(cr, sg.XChannelRegion);
            Assert.AreEqual(new Region(4, 3004), sg.XPlotRegion);

            sg.IsCalibrated = false;
            Assert.AreEqual(cr, sg.XChannelRegion);
            Assert.AreEqual(cr, sg.XPlotRegion);
        }
Exemplo n.º 9
0
 public void インスタンス生成_引数あり()
 {
     var lf = new Linear(2, 3);
     Assert.AreEqual(2, lf.A);
     Assert.AreEqual(3, lf.B);
     Assert.IsNotNull(lf.Function);
     Assert.IsNotNull(lf.InverseFunction);
 }
Exemplo n.º 10
0
 public void インスタンス生成()
 {
     var lf = new Linear();
     Assert.IsNotNull(lf.A);
     Assert.IsNotNull(lf.B);
     Assert.IsNotNull(lf.Function);
     Assert.IsNotNull(lf.InverseFunction);
 }
Exemplo n.º 11
0
 public void ToStringは右辺のみでこんな感じ(double a, double b, [NotNull] string expected)
 {
     var lf = new Linear(a, b);
     Assert.AreEqual(expected, lf.ToString());
 }
Exemplo n.º 12
0
 public void FunctionはAx_plus_Bのはず(double arg, double expected)
 {
     var lf = new Linear(2, 3);
     var f = lf.Function;
     Assert.AreEqual(expected, f(arg));
 }
Exemplo n.º 13
0
 public void FromTwoPointsは同じ点2つや傾き無限大なら傾きnaNを返す(double x0, double y0, double x1, double y1)
 {
     var lf = new Linear(new Point(x0, y0), new Point(x1, y1));
     Assert.AreEqual(new Linear(double.NaN, x0).A, lf.A);
 }
Exemplo n.º 14
0
 public void FromGradientAndPointは傾きと一点から直線を求める(double grad, double x, double y, double expectedA,
     double expectedB)
 {
     var lf = new Linear(grad, new Point(x, y));
     Assert.AreEqual(new Linear(expectedA, expectedB), lf);
 }