0 Vote(s) - 0 Average 1 2 3 4 5 Release Linear Regression Yamato OMA Joined: Dec 2010 Posts: 2,309 Reputation: 106 06-17-2013, 16:21 (This post was last modified: 06-17-2013, 16:21 by Yamato.) 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: Spoiler (Click to View) Code: ```x = [ ]; x[0] = 0; x[1] = 50; x[2] = 100; y= [ ]; y[0] = -30; y[1] = 50; y[2] = 0; wait 1; self iPrintLnBold( RegLine( x, y, 30 ) );``` Thanks for reading The following 3 users say Thank You to Yamato for this post:3 users say Thank You to Yamato for this post Nekochan /* No comment. */ Joined: Jan 2011 Posts: 3,272 Reputation: 121 06-17-2013, 17:01 ?screenshot please? C++/Obj-C developer. Neko engine wip Steam: Click   • Yamato OMA Joined: Dec 2010 Posts: 2,309 Reputation: 106 06-17-2013, 17:16 (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: 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   • surtek Virtual Wizard Joined: Nov 2010 Posts: 2,003 Reputation: 38 06-17-2013, 20:38 I think you have used this for your garbage gun. The gun that shoots garbage on favela (video) . The following 1 user says Thank You to surtek for this post:1 user says Thank You to surtek for this post Yamato OMA Joined: Dec 2010 Posts: 2,309 Reputation: 106 06-17-2013, 20:49 (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   •

Forum Jump:

Users browsing this thread: 1 Guest(s)