Esempio n. 1
0
        public void Perform(FullLine[] data)
        {
            float n = data.Length;
            float Sx = data.Sum(x => x.m);
            float Sy = data.Sum(x => x.c);
            float Sxx = data.Sum(x => x.m * x.m);
            float Syy = data.Sum(x => x.c * x.c);
            float Sxy = data.Sum(x => x.m * x.c);

            B = ((n * Sxy) - (Sx * Sy)) /
                ((n * Sxx) - (Sx * Sx));
            A = (Sy / n) - (B * Sx / n);
        }
Esempio n. 2
0
        internal OLSRegression GetBoardRegression()
        {
            List<FullLine> fullLines = new List<FullLine>();

            foreach (LineSegment2D lineSegment in VertLines)
            {
                // Set lowest point as p1
                var p1 = lineSegment.P1;
                var p2 = lineSegment.P2;
                if (p1.Y > p2.Y)
                {
                    p2 = lineSegment.P1;
                    p1 = lineSegment.P2;
                }

                // Calculate crossing of x-axis (call it c)
                float m = (float)(p2.X - p1.X) / (float)(p2.Y - p1.Y);
                float c = (float)p1.X - ((float)p1.Y * m);

                FullLine fullLine = new FullLine(m, c);
                fullLines.Add(fullLine);
            }

            OLSRegression olsRegression = new OLSRegression();
            olsRegression.Perform(fullLines.ToArray());

            return olsRegression;
        }