473,670 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Robust statistics and optimmization from Python

I use Python to generate a huge amount of data in a .csv file which I
then process using Excel. In particular, I use Excel's solver to solve
a number of non-linear equation, and then regress the results of
hundreds of calls to Solver against a set of known values, enabling me
to calibrate my model. This is a pain: i'd much rather perform all the
computations in Python and improve on Excels' regression as well.

Questions:
1. Is there a way to perform (or make a call to) a non-linear
optimization from Python?
2. Do Python packages for robust statistics (robust regression in
particular) exist. If so, which one would you recommend/

Thanks, as always, in advance for the guidance

Thomas Philips

Aug 29 '05 #1
4 3901
tk****@hotmail. com wrote:
I use Python to generate a huge amount of data in a .csv file which I
then process using Excel. In particular, I use Excel's solver to solve
a number of non-linear equation, and then regress the results of
hundreds of calls to Solver against a set of known values, enabling me
to calibrate my model. This is a pain: i'd much rather perform all the
computations in Python and improve on Excels' regression as well.

Questions:
1. Is there a way to perform (or make a call to) a non-linear
optimization from Python?
Look at scipy. http://www.scipy.org

In [1]: from scipy import optimize

In [2]: optimize?
....
Optimization Tools
=============== ===

A collection of general-purpose optimization routines.

fmin -- Nelder-Mead Simplex algorithm
(uses only function calls)
fmin_powell -- Powell's (modified) level set method (uses only
function calls)
fmin_cg -- Non-linear (Polak-Rubiere) conjugate gradient
algorithm
(can use function and gradient).

fmin_bfgs -- Quasi-Newton method (can use function and gradient)
fmin_ncg -- Line-search Newton Conjugate Gradient (can use
function, gradient and hessian).
leastsq -- Minimize the sum of squares of M equations in
N unknowns given a starting estimate.

Constrained Optimizers (multivariate)

fmin_l_bfgs_b -- Zhu, Byrd, and Nocedal's L-BFGS-B constrained
optimizer
(if you use this please quote their papers --
see help)

fmin_tnc -- Truncated Newton Code originally written by
Stephen Nash and
adapted to C by Jean-Sebastien Roy.

fmin_cobyla -- Contrained Optimization BY Linear Approximation
2. Do Python packages for robust statistics (robust regression in
particular) exist. If so, which one would you recommend/


Offhand, I can't think of any, but it's easy enough to do maximum
likelihood with Laplacians and the functions above. If you find suitable
FORTRAN or C code that implements a particular "robust" algorithm, it
can probably wrapped for scipy relatively easily.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Aug 29 '05 #2
Robert Kern wrote:

<snip>
If you find suitable
FORTRAN or C code that implements a particular "robust" algorithm, it
can probably wrapped for scipy relatively easily.


An alternative would be to call R (a free statistical package) from
Python, using something like the R/SPlus - Python Interface at
http://www.omegahat.org/RSPython/ . Many statistical algorithms,
including those for robust statistics, have been implemented in R,
usually by wrapping C or Fortran 77 code.

Aug 29 '05 #3
use R. it's pretty highend, and there is an interface for python.

Aug 29 '05 #4
be*******@aol.c om wrote:
Robert Kern wrote:

<snip>
If you find suitable
FORTRAN or C code that implements a particular "robust" algorithm, it
can probably wrapped for scipy relatively easily.

An alternative would be to call R (a free statistical package) from
Python, using something like the R/SPlus - Python Interface at
http://www.omegahat.org/RSPython/ .


Unless you really want to call Python from R (as opposed to calling R
from Python), I strongly suggest that you use RPy (http://rpy.sf.net)
rather than RSPython. RPy is much easier to install and use and far less
buggy than RSPython.
Many statistical algorithms,
including those for robust statistics, have been implemented in R,
usually by wrapping C or Fortran 77 code.


Yup, and if you really don't like the extra dependency or extra memory
requirements of R and RPy, it is often possible to port the R code back
to Python (or Numeric Python), with some effort.

Tim C

Aug 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5359
by: Alberto Vera | last post by:
Hello: Is it possible to make "ping" from Python and get statistics like using command prompt from Windows? How Can I capture them into variables? Thanks Pinging XXXX.XXXX.XXXX.XXXX with 32 bytes of data:
2
1263
by: Roberto | last post by:
Hi there, I know that surely depend on how robust is my script just wondering if anyone is using this in production. Thanks, Rob -- Roberto Federici
4
2493
by: Anand Pillai | last post by:
Hi Folks (posting after a loooong time...) I have been contracted by an Indian publisher to author an introductory text book on Python. As a part of the introductory chapter, I thought it would be a good idea to present a number, a round-about figure on the approximate *actual* usage of Python out there in number of developers and/or installations.
9
2117
by: Paddy McCarthy | last post by:
Frustrated at being prevented from using Python at work I went gunning for Perl. Time to roll out some useless Google statistics to make me feel better Google Phrase count ------------- ----- "prefer perl to python" 26 "prefers perl to python" 0
1
4498
by: Gabriel Zachmann | last post by:
For some reason, I would like to have some statistics about how often Python is used in the *scientific* communities (such as astronomy, genetics, electrical engineering, ...), as opposed to C++ or Java or other "common" programming languages. I know about TIOBE's Programming Community Index, and Francois Labelle's statistics from sourceforge. Any pointers or insights will be highly appreciated
2
2437
by: F. Petitjean | last post by:
I have written a script to find the modules which export the largest number of names. The gc.getreferrers(*objs) function gives also an idea of the dependencies between the modules. The code (statsmod.py) : #!/usr/bin/env python # -*- coding: latin-1 -*- """
8
5120
by: Jan Danielsson | last post by:
Hello all, I wanted to plot some statistics, so I wrote a simple wxPython class to do it. Then I realized that I would like to draw bar graphs, so I added that too. Since I'm a complete Python newbie, I haven't done much of it the "Python way", I suspect. So, I'm wondering if someone would like to show me some of the tricks I should have used.
17
14073
by: Felix | last post by:
Dear Sql Server experts: First off, I am no sql server expert :) A few months ago I put a database into a production environment. Recently, It was brought to my attention that a particular query that executed quite quickly in our dev environment was painfully slow in production. I analyzed the the plan on the production server (it looked good), and then tried quite a few tips that I'd gleaned from reading newsgroups. Nothing worked....
17
5067
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also identifying memory leaks. The application in question is the Mozilla Web Browser. I also have had similar tasks before in the compiler construction area. And it is easy to come up with many more examples, where such kind of statistics can be very...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.