• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Release] Linear Regression
#1
Hi

I was searching for stuff to do a new tutorial about and I suddenly found this on an unfinished mod, I cant remember the use I was going to give to it.

The function creates a linear regression from 2 arrays, one of the x values of some points and another one of the y values of those points, once its created it evaluates it in one point.

Code:
RegLine( x, y, point )
{
    x2 = 0;
    xt = 0;
    yt = 0;
    xy = 0;
    for( i = 0; i < x.size; i ++ )
    {
        x2 += ( x[i] * x[i] );
        yt  += y[i];
        xt  += x[i];
        xy += ( x[i] * y[i] );
    }
    b = ( x.size * xy - xt * yt ) / ( x.size * x2 - xt * xt );
    a = ( yt - b * xt ) / x.size;
    result = b * point + a;
    return result;
}

Example of use:

Thanks for reading OMA
  Reply
#2
?screenshot please?
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
  Reply
#3
(06-17-2013, 17:01)SailorMoon Wrote: ?screenshot please?

I dont have the game installed, but this will show you pretty easily what does this do:

[Image: 400px-Linear_regression.svg.png]

There are some points ( coordinates x and y ), and this function gives you the point of the line that goes in the middle of them. The squared distance from the point to the line in average is minimum. Maybe wikipedia can help you to understand it better, my english sucks a bit at explaining this Confused
  Reply
#4
I think you have used this for your garbage gun. The gun that shoots garbage on favela (video) .
  Reply
#5
(06-17-2013, 20:38)surtek Wrote: I think you have used this for your garbage gun. The gun that shoots garbage on favela (video) .

No, I didnt used it for anything. I found it in a file inside an unfinished mod in which I was messing up with hud stuff, but I dont really know for what did I needed this, is not threaded anywhere in the mod Undecided
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)