-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Example showing how to write a least-squares polynomial fit in Julia #3325
Conversation
enough that it may be used as a pedogogical example of how to write a Julia program. This example follows the discussion on Wikipedia: http://en.wikipedia.org/wiki/Linear_least_squares_%28mathematics%29
This seems a little elaborate. I'd also like to make clear to newcomers that least-squares fitting in Julia should be done using the GLM package. |
Hi John, Fair enough, but my goal is to create free-standing examples which can I created a few of these examples last year after talking to Alan E. You guys can choose. But please let me know if you want more of these Cheers, Stuart On Fri, 7 Jun 2013, John Myles White wrote:
|
I started out writing a comment on all the things that are bad about this example but decided not to post it because it sounded too confrontational. One thing I particularly value about the Julia community is the cordiality. I appreciate your desire to contribute an example. However, Julia is a programming language for technical computing and doing technical computing well involves choosing good algorithms and being aware of the stability, accuracy and speed of different approaches. Nowhere is this more important than in numerical linear algebra. Simply creating the model matrix, X, and getting the coefficients as
will choose a much better algorithm (QR decomposition with column pivoting) than what you have chosen (LU decomposition of a symmetric, positive-definite matrix). And it is much simpler. The second point is that polynomial regression using powers of x as columns of the model matrix is a notoriously ill-conditioned problem. If you really want to do polynomial regression it would be better to form an orthogonal polynomial basis. The example does not illustrate good programming practice nor does it illustrate good algorithm choice. I would recommend against including it. |
Fair enough. I'll see if I can polish up the example and the Thanks Stuart On Fri, 7 Jun 2013, dmbates wrote:
|
Thanks Stuart, this is nicely presented. I can't comment on the math, but from my perspective there is only one problem, which is the program structure. This code should define at least one function that encapsulates the thing being computed. That way we can see what the core algorithm is and what its inputs are, separated from setting up the example problem being solved and the printing code. One of the biggest problems you see all the time in (mostly) matlab code is this style of doing everything at the top level in scripts. |
Thanks. I can change the example to encapsulate two fcns:
Depending upon how you like the examples presented, I can then either I'll take a look at the numerical issues raised by dmbates and do Cheers, Stuart On Fri, 7 Jun 2013, Jeff Bezanson wrote:
|
If you want to show polynomial regression using powers you could show some of the in-built mechanisms for creating matrices.
|
On a slightly different note, we have a lot of cleanup to do on our existing examples. Some are perhaps not good examples, some no longer work, etc. Issue #2598 is tracking the cleaning up of examples. @brorson It would be great if you can help out with that effort. One specific task is also to add all the examples to the tests, so that we ensure they are always working. The second thing that would be useful would be to document the code better, and perhaps even include the examples in the manual. The shootout benchmark in |
Hi Viral, Yup, getting a nice set of examples together is part of the plan, as Another thing I envision doing is writing up some "case studies" or Let me see if I can figure out how to adopt issue 2598 in GitHub. I Cheers, Stuart On Fri, 7 Jun 2013, Viral B. Shah wrote:
|
Thanks Stuart. This sounds really exciting - really looking forward to this. |
I have written a simple program which performs least squares fitting. This is meant to be a stand-alone example of how to use Juila to solve a simple, but not trivial mathematical problem. it is aimed at Julia beginners. I envision this could become a classroom example of how to use Julia.
This example follows the methods discussed on Wikipedia:
http://en.wikipedia.org/wiki/Linear_least_squares_%28mathematics%29