Exemplo n.º 1
0
        public Generic2dInterpolator(double[][] x, double[] y, double[][] z, Interpolator1DType xType, Interpolator1DType yType)
        {
            _y     = y;
            _xType = xType;
            _yType = yType;

            _yInterps = new IInterpolator1D[_y.Length];
            for (var i = 0; i < _yInterps.Length; i++)
            {
                _yInterps[i] = InterpolatorFactory.GetInterpolator(x[i], z[i], _yType);
            }
        }
Exemplo n.º 2
0
        public Generic2dInterpolator(double[] x, double[] y, double[,] z, Interpolator1DType xType, Interpolator1DType yType)
        {
            _x     = x;
            _y     = y;
            _z     = z;
            _xType = xType;
            _yType = yType;

            _yInterps = new IInterpolator1D[_y.Length];
            for (var i = 0; i < _yInterps.Length; i++)
            {
                _yInterps[i] = InterpolatorFactory.GetInterpolator(_x, _z.GetRow(i), _yType);
            }
        }
Exemplo n.º 3
0
        public static IInterpolator1D Regress(double[] Xs, double[] Ys, int nSegments)
        {
            var nSamples          = Xs.Length;
            var x                 = new double[nSegments + 1];
            var y                 = new double[nSegments + 1];
            var samplesPerSegment = nSamples / nSegments;

            for (var i = 0; i < nSegments; i++)
            {
                var sampleXs = Xs.Skip(i * samplesPerSegment).Take(samplesPerSegment).ToArray();
                var sampleYs = Ys.Skip(i * samplesPerSegment).Take(samplesPerSegment).ToArray();
                var lr       = LinearRegression.LinearRegressionVector(sampleXs, sampleYs);
                var xLo      = sampleXs.First();
                var xHi      = sampleXs.Last();
                var yLo      = lr.Alpha + lr.Beta * xLo;
                var yHi      = lr.Alpha + lr.Beta * xHi;

                if (i == 0)
                {
                    x[0] = xLo;
                    y[0] = yLo;
                    x[1] = xHi;
                    y[1] = yHi;
                }
                else
                {
                    var xD        = sampleXs.Select(q => q - xLo).ToArray();
                    var yD        = sampleYs.Select(q => q - yLo).ToArray();
                    var lr2       = LinearRegression.LinearRegressionNoIntercept(xD, yD);
                    var yHiBetter = xD.Last() * lr2.Beta + yLo;
                    x[i + 1] = xHi;
                    y[i + 1] = yHiBetter;
                }
            }
            return(InterpolatorFactory.GetInterpolator(x, y, Interpolator1DType.Linear));
        }
Exemplo n.º 4
0
 public LinearHazzardInterpolator(double[] xs, double[] hs)
 {
     _xs           = xs;
     _hs           = hs;
     _linearInterp = InterpolatorFactory.GetInterpolator(xs, hs, Interpolator1DType.LinearFlatExtrap);
 }