Go to Post A Guru teaching batteries at Exide: "Do not draw your power from up here, by your terminals. You must reach down deep into your plates and pull the energy from your entire being! You must prove yourself worthy to be FIRST power cells!" - KenWittlief [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-06-2015, 20:23
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,086
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
calling all "R Statistical Package" gurus


Given m-by-n matrix [A], (m>n), and m-by-1 column vector [b] for the overdetermined system of linear equations

[A][x] = [b],

What is the recommended way to use R to find the n-by-1 column vector [x] which minimizes the L1 norm of [b]-[A][x] ?

aka minx |[b]-[A][x]|1, aka Least Absolute Deviation (LAD) ?


  #2   Spotlight this post!  
Unread 18-06-2015, 21:41
faust1706's Avatar
faust1706 faust1706 is offline
Registered User
FRC #1706 (Ratchet Rockers)
Team Role: College Student
 
Join Date: Apr 2012
Rookie Year: 2011
Location: St Louis
Posts: 498
faust1706 is infamous around these partsfaust1706 is infamous around these parts
Re: calling all "R Statistical Package" gurus

This paper might be of use to you.

I have personally used rgenoud, but my code for it is sitting on the desktop in my lab at university and wouldn't be much use to you because it maximize the cost function described in this paper.
__________________
"You're a gentleman," they used to say to him. "You shouldn't have gone murdering people with a hatchet; that's no occupation for a gentleman."

Last edited by faust1706 : 18-06-2015 at 22:16.
  #3   Spotlight this post!  
Unread 18-06-2015, 22:54
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,639
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: calling all "R Statistical Package" gurus

Whew. I somehow managed to get an MS in physics without taking a single linear algebra course (I don't know how, and I don't advise it!). When I've had this sort of problem since entering the workforce, I just trusted MATLAB to figure out the best method.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
  #4   Spotlight this post!  
Unread 18-06-2015, 23:44
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,086
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: calling all "R Statistical Package" gurus

Quote:
Originally Posted by GeeTwo View Post
Whew. I somehow managed to get an MS in physics without taking a single linear algebra course (I don't know how, and I don't advise it!). When I've had this sort of problem since entering the workforce, I just trusted MATLAB to figure out the best method.
I already have an Octave (Matlab) script that does this. This thread is about the recommended way to do it using R.


  #5   Spotlight this post!  
Unread 19-06-2015, 13:45
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,086
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: calling all "R Statistical Package" gurus



I found this statement:
Quote:
Package quantreg contains variations of simplex and of interior point routines ( nlrq(), crq()). It provides an interface to L1 regression in the R code of function rq(). [SPLP, LP, IPM]
... at this webpage:

http://cran.r-project.org/web/views/Optimization.html



I also found this statement:
Quote:
Koenker's quantile regression package quantreg contains L1 (aka LAD, least absolute deviations)-regression as a special case
... at this webpage:

http://cran.cnr.berkeley.edu/web/views/Robust.html


Attached is a zip file containing an [A] matrix and [b] column vector in CSV format. Would some kind R guru please show how to use the above method to do L1 regression on the attached data? (see original post in this thread)



Attached Files
File Type: zip A and b.zip (1.2 KB, 12 views)
  #6   Spotlight this post!  
Unread 21-06-2015, 10:19
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,086
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: calling all "R Statistical Package" gurus

Quote:
Originally Posted by Ether View Post
Given m-by-n matrix [A], (m>n), and m-by-1 column vector [b] for the overdetermined system of linear equations

[A][x] = [b],

What is the recommended way to use R to find the n-by-1 column vector [x] which minimizes the L1 norm of [b]-[A][x] ?

I found an elegant one-line-of-source-code fast-executing solution.

I knew R should be able to do this.

In terms of code simplicity (using tested and stable publicly available supported free libraries) I would rank R at the top of the list (for this particular problem), tied for first place with Python. In second place is AMPL. Matlab/Octave is a distant third.

PM me if you're interested.


PS: I haven't looked into SciLab yet. How about LabVIEW?? Any takers?


Last edited by Ether : 21-06-2015 at 20:07.
  #7   Spotlight this post!  
Unread 23-06-2015, 10:47
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,086
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: calling all "R Statistical Package" gurus

Quote:
Originally Posted by Ether View Post
I would rank R at the top of the list (for this particular problem)
I should add the following qualifier: the above is true for small datasets (like analyzing one event). For larger datasets (like doing world OPR for an entire season's worth of events), not so much.


Quote:
Originally Posted by Ether View Post
Matlab/Octave is a distant third.
Matlab/Octave has good support for sparse matrices to effectively process larger datasets.


  #8   Spotlight this post!  
Unread 23-06-2015, 22:09
Rachel Lim Rachel Lim is offline
Registered User
FRC #1868 (Space Cookies)
Team Role: Student
 
Join Date: Sep 2014
Rookie Year: 2014
Location: Moffett Field
Posts: 252
Rachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond reputeRachel Lim has a reputation beyond repute
Re: calling all "R Statistical Package" gurus

Quote:
Originally Posted by Ether View Post
In terms of code simplicity (using tested and stable publicly available supported free libraries) I would rank R at the top of the list (for this particular problem), tied for first place with Python. In second place is AMPL. Matlab/Octave is a distant third.
Is the difference just with how easy it is to write the code / input the data, or do they do the calculations differently? If the latter is true, would different CAS programs fall into a few different groups, or would they all do the calculations differently?
  #9   Spotlight this post!  
Unread 23-06-2015, 22:26
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,086
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: calling all "R Statistical Package" gurus


R uses the rq() function in the quantreg package which does quantile regression. It converts the problem to SDP and solves it. If you set the tau parameter of rq() to 50%, it will do L1 regression.

Python has a convex optimization package that contains a function for L1 regression. You don't have to know how to setup the problem, just pass it your A & b data.

AMPL is a modeling language which allows you to state the problem as a constrained minimization, and then AMPL expands it into a linear program format that can be passed to your linear solver of choice.

Octave has glpk, the GNU Linear Programming kit. You have to manually code the problem as a linear program and then pass it to glpk() for solution.

Matlab has the linprog() function which does the same thing as Octave's glpk(). It also has the CVX package, which allows you to use Matlab as a modeling language, but it is not intended for large problems.


Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi