还有一些变形的线性回归,比如说幂次,对数等

    public class ShRegExponential
    {
        public double A
        {
            get
            {
                return Math.Pow(Math.E, this.RegLinear.B);
            }
        }

        public double B
        {
            get
            {
                return this.RegLinear.A;
            }
        }

        public double R2
        {
            get
            {
                return this.RegLinear.R2;
            }
        }

        private double[] OriginX = null;
        private double[] OriginY = null;
        private ShRegLinear RegLinear = null;
        public ShRegExponential()
        {
            // Y = a * POW(e, b * X)
            this.RegLinear = new ShRegLinear();
        }

        //  外面应该剔除无效值以后再传进来,里面不做判断
        public void SetOriginData(double[] x, double[] y)
        {
            this.OriginX = x;
            this.OriginY = y;
        }

        public bool CalculateRegression()
        {
            if (this.OriginX == null || this.OriginX.Length < 3 ||
                    this.OriginY == null || this.OriginX.Length != this.OriginY.Length)
                return false;

            List<double> x = new List<double>();
            List<double> y = new List<double>();
            for (int i = 0; i < this.OriginY.Length; i++)
            {
                if (this.OriginY[i] > 0)
                {
                    x.Add(this.OriginX[i]);
                    y.Add(Math.Log(this.OriginY[i]));
                }
            }

            this.RegLinear.SetOriginData(x.ToArray(), y.ToArray());
            return this.RegLinear.CalculateRegression();
        }

        public double CalculateValue(double x)
        {
            return (this.A * Math.Pow(Math.E, this.B * x));
        }

        public double[] GetResult()
        {
            double[] result = new double[]
            {
                this.A,
                this.B,
            };
            return result;
        }

        public double GetR2()
        {
            return this.R2;
        }
    }

    public class ShRegPower
    {
        public double A
        {
            get
            {
                return Math.Pow(Math.E, this.RegLinear.B);
            }
        }

        public double B
        {
            get
            {
                return this.RegLinear.A;
            }
        }

        public double R2
        {
            get
            {
                return this.RegLinear.R2;
            }
        }

        private double[] OriginX = null;
        private double[] OriginY = null;
        private ShRegLinear RegLinear = null;
        public ShRegPower()
        {
            // Y = a * POW(X, b)
            this.RegLinear = new ShRegLinear();
        }

        //  外面应该剔除无效值以后再传进来,里面不做判断
        public void SetOriginData(double[] x, double[] y)
        {
            this.OriginX = x;
            this.OriginY = y;
        }

        public bool CalculateRegression()
        {
            if (this.OriginX == null || this.OriginX.Length < 3 ||
                    this.OriginY == null || this.OriginX.Length != this.OriginY.Length)
                return false;

            List<double> x = new List<double>();
            List<double> y = new List<double>();
            for (int i = 0; i < this.OriginX.Length; i++)
            {
                if (this.OriginX[i] > 0 && this.OriginY[i] > 0)
                {
                    x.Add(Math.Log(this.OriginX[i]));
                    y.Add(Math.Log(this.OriginY[i]));
                }
            }

            this.RegLinear.SetOriginData(x.ToArray(), y.ToArray());
            return this.RegLinear.CalculateRegression();
        }

        public double CalculateValue(double x)
        {
            return this.A * Math.Pow(x, this.B);
        }

        public double[] GetResult()
        {
            double[] result = new double[]
            {
                this.A,
                this.B,
            };
            return result;
        }

        public double GetR2()
        {
            return this.R2;
        }
    }

    public class ShRegLog
    {
        public double A
        {
            get
            {
                return this.RegLinear.B;
            }
        }

        public double B
        {
            get
            {
                return this.RegLinear.A;
            }
        }

        public double R2
        {
            get
            {
                return this.RegLinear.R2;
            }
        }

        private double[] OriginX = null;
        private double[] OriginY = null;
        private ShRegLinear RegLinear = null;
        public ShRegLog()
        {
            // Y = a + b * log(X)
            this.RegLinear = new ShRegLinear();
        }

        //  外面应该剔除无效值以后再传进来,里面不做判断
        public void SetOriginData(double[] x, double[] y)
        {
            this.OriginX = x;
            this.OriginY = y;
        }

        public bool CalculateRegression()
        {
            if (this.OriginX == null || this.OriginX.Length < 3 ||
                    this.OriginY == null || this.OriginX.Length != this.OriginY.Length)
                return false;

            List<double> x = new List<double>();
            List<double> y = new List<double>();
            for (int i = 0; i < this.OriginX.Length; i++)
            {
                if (this.OriginX[i] > 0)
                {
                    x.Add(Math.Log(this.OriginX[i]));
                    y.Add(this.OriginY[i]);
                }
            }

            this.RegLinear.SetOriginData(x.ToArray(), y.ToArray());
            return this.RegLinear.CalculateRegression();
        }

        public double CalculateValue(double x)
        {
            return this.A + this.B * Math.Log(x);
        }

        public double[] GetResult()
        {
            double[] result = new double[]
            {
                this.A,
                this.B,
            };
            return result;
        }

        public double GetR2()
        {
            return this.R2;
        }
    }