Comparisons of computation timing
I have run my codes (written in Python) in my Notebook (3 GB Ram, Dual- core CPU T4500 @ 2.3 GHz) and in my lab machine (11.57 GB Ram, i7-920 CPU @ 2.67 GHz). However, I have found execution time in Notebook 250.3 seconds, and in Lab machine 333.2 seconds. How is it possible? Good configuration machine performs slower??? I reran the codes, same finding whatsoever. I run Windows 7 in my laptop, and Ubuntu 11.04 in lab machine. Both are 64 bit. When I ran my simulation in Notebook, I also did some other stuffs; however for the case of lab machine I did nothing other than running simulation only. About the codes: Basically it simply solves some non-linear equations using "fsolve" along with some other calculations. I will appreciate if some one discusses about possible reasons? For fair comparisons, in both machines I ran exactly the same codes. My codes are not parallelized, is this the main reason i7 processes show slower performance? Thanks in advance, Akand -- http://mail.python.org/mailman/listinfo/python-list
Matlab equivalent syntax in Python
Can anyone please suggest me what will be the good way to use matlab equivalent of "profile clear, profile on, profile off, profile resume and profile viewer" in Python? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Matlab equivalent syntax in Python
On Nov 26, 12:37 am, Tim Roberts wrote: > Akand Islam wrote: > > >Can anyone please suggest me what will be the good way to use matlab > >equivalent of "profile clear, profile on, profile off, profile resume > >and profile viewer" in Python? > > Python has a number of ways of measuring elapsed time, including the > "timeit" module and the "trace" module. There's nothing that will display > the results in a pretty graph, so the answer depends on what you are after. > -- > Tim Roberts, [email protected] > Providenza & Boekelheide, Inc. Dear Tim Roberts, Thanks for your posting. Like, here is the following Matlab codes which I am trying to transform into Python. Here you will find "profile clear, profile on, profile off, profile resume, profile viewer, and drawnow" syntaxes. So, what will be these equivalents in Python? Regards, Akand === function x = amg_solve(GUI_HANDLES); amg_globals; str=get(GUI_HANDLES.panelText,'String'); %Check the source of the problem specification if PROB_SRC==USER_SPEC_FD %if the user finite difference matrix is to be used str=strcat(str,sprintf('\nInitializing Problem to User Specifications ')); str=strcat(str,sprintf('\nUSER: Please enter your input file name at the console...')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_usersetFD; %set up globals as the user has specified them elseif PROB_SRC==USER_SPEC_FEM %if the user finite element matrix is to be used str=strcat(str,sprintf('\nInitializing Problem to User Specifications ')); str=strcat(str,sprintf('\nUSER: Please enter your input file name at the console...')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_usersetFEM; %set up globals as the user has specified them elseif PROB_SRC==EXAMPLE1 %if example 1 is called for str=strcat(str,sprintf('\nInitializing Problem to Poisson Example ')); set(GUI_HANDLES.panelText,'String',str); drawnow; amg_example1; %set up globals for example 1 end profile clear; if SETUP_OPT==AT_ONCE %if user wishes to find all coarse grids up front % see "restrict.m" for what happens otherwise str=strcat(str,sprintf('\nCalling Setup Algorithm to Determine Coarse Grids ')); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile on; end amg_setup(1); %call setup algorithm if SHOW_PROFILE==YES profile off; end end INIT_RESID = norm(RHS - (A(1).matrix * X_Guess)); %get initial residual str=strcat(str,sprintf('\n2-Norm of Initial Residual is %d ', INIT_RESID)); set(GUI_HANDLES.panelText,'String',str); drawnow; x = X_Guess; cycleCount = 1; %count the number of AMG cycles executed while (cycleCount<=CYCLES) str=strcat(str,sprintf('\nStarting AMG Cycle Number %i... ', cycleCount)); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile resume; end x = amg_cycle(cycleCount,1,RHS,x); %execute as many AMG cycles if necessary if SHOW_PROFILE==YES profile off; end str=strcat(str,sprintf('\n2-Norm of Residual after AMG Cycle Number %i is %d ', cycleCount, norm(RH2(cycleCount,1; set(GUI_HANDLES.panelText,'String',str); drawnow; cycleCount=cycleCount+1; %incriment cycle count end FINAL_RESID = norm(RHS - (A(1).matrix * x)); %get initial residual str=strcat(str,sprintf('\nFinished... ')); set(GUI_HANDLES.panelText,'String',str); drawnow; if SHOW_PROFILE==YES profile viewer; end == -- http://mail.python.org/mailman/listinfo/python-list
Re: Matlab equivalent syntax in Python
On Nov 26, 3:50 pm, Cameron Simpson wrote: > On 26Nov2010 13:15, Akand Islam wrote: > | Thanks for your posting. Like, here is the following Matlab codes > | which I am trying to transform into Python. Here you > | will find "profile clear, profile on, profile off, profile resume, > | profile viewer, and drawnow" syntaxes. So, what will be these > | equivalents > | in Python? > > I would start by looking at the "profile" python module: > > http://docs.python.org/library/profile.html#module-profile > > Cheers, > -- > Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ > > Their are thre mistakes in this sentence. > - Rob Ray DoD#3 Dear Cameron Simpson, Thanks for co-operation. I have gone through the link, however, I am not much clear. Can you please show me some python syntaxes which contain Matlab like "profile on.., drawnow.." and so forth? Regards, Akand -- http://mail.python.org/mailman/listinfo/python-list
Re: Matlab equivalent syntax in Python
On Nov 27, 4:38 pm, Robert Kern wrote: > On 2010-11-26 18:23 , Akand Islam wrote: > > > > > > > > > > > On Nov 26, 3:50 pm, Cameron Simpson wrote: > >> On 26Nov2010 13:15, Akand Islam wrote: > >> | Thanks for your posting. Like, here is the following Matlab codes > >> | which I am trying to transform into Python. Here you > >> | will find "profile clear, profile on, profile off, profile resume, > >> | profile viewer, and drawnow" syntaxes. So, what will be these > >> | equivalents > >> | in Python? > > >> I would start by looking at the "profile" python module: > > >> http://docs.python.org/library/profile.html#module-profile > > >> Cheers, > >> -- > >> Cameron Simpson > >> DoD#743http://www.cskk.ezoshosting.com/cs/ > > >> Their are thre mistakes in this sentence. > >> - Rob Ray DoD#3 > > > Dear Cameron Simpson, > > Thanks for co-operation. I have gone through the link, however, I am > > not much clear. Can you please show me some python syntaxes which > > contain Matlab like "profile on.., drawnow.." and so forth? > > Perhaps you could explain what those MATLAB commands do. Not everyone here is > familiar with MATLAB. For the most part, an API like "profile on; profile off" > is inappropriate for the "profile" Python module. It profiles the times each > function call takes, not each line. Turning it on and off doesn't make much > sense. The API described in the above link is better for what it does. > > If you want to visualize the profile, you may want to try RunSnakeRun: > > http://www.vrplumber.com/programming/runsnakerun/ > > If you want line-by-line profiling, you may want to check out my package, > line_profiler: > > http://pypi.python.org/pypi/line_profiler/ > > Again, we don't turn it on and off like you might do in MATLAB. Just follow > the > directions and give up trying to find a correspondence with the MATLAB > commands. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco Dear Robert Kern, I do appreciate your reply. Surely I will dig through your package. -- Akand -- http://mail.python.org/mailman/listinfo/python-list
Sage's Python
In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- dev installed. When I give command from terminal "sage -f python-2.6.5.p8" to get sage's python it shows following message: No command 'sage' found, did you mean: Command 'save' from package 'atfs' (universe) Command 'page' from package 'tcllib' (universe) sage: command not found How can I get Sage's python to be worked so that I can import sage.all in python shell? Thanks in advance. --Akand -- http://mail.python.org/mailman/listinfo/python-list
Re: Sage's Python
On Dec 13, 4:33 pm, "Rhodri James" wrote: > On Fri, 10 Dec 2010 17:11:55 -, Akand Islam wrote: > > In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > > dev installed. When I give command from terminal "sage -f > > python-2.6.5.p8" to get sage's python it shows following message: > > > No command 'sage' found, did you mean: > > Command 'save' from package 'atfs' (universe) > > Command 'page' from package 'tcllib' (universe) > > sage: command not found > > > How can I get Sage's python to be worked so that I can import sage.all > > in python shell? > > The fact that you have no executable called "sage" suggests that you > haven't actually installed it yet. Check the Sage website, which has > plenty of documentation, and try to figure out where you left the path on > whichever method you used. > > -- > Rhodri James *-* Wildebeest Herder to the Masses Dear Rhodri James, Thanks for your response. But I have installed sage-4.6 as per instructions. Sage-4.6 folder is in my ~/Desktop, therefore, from ~/ Desktop/sage-4.6 I can initiate ./sage and can work with sage. -- Akand -- http://mail.python.org/mailman/listinfo/python-list
Re: Sage's Python
On Dec 14, 1:51 pm, Emile van Sebille wrote: > On 12/14/2010 10:27 AM Akand Islam said... > > > On Dec 13, 4:33 pm, "Rhodri James" > > wrote: > >> On Fri, 10 Dec 2010 17:11:55 -, Akand Islam wrote: > >>> In my system (Ubuntu 10.04) there are sage-4.6, python 2.6.5, tk8.5- > >>> dev installed. When I give command from terminal "sage -f > >>> python-2.6.5.p8" to get sage's python it shows following message: > > >>> No command 'sage' found, did you mean: > > This means that no sage command was found on your path. Check to be > sure that ~/Desktop is in your path. > > Emile Thanks Emile. -- Akand. -- http://mail.python.org/mailman/listinfo/python-list
adding "Print" menu in wxPython
To make a simple editor using wxPython, sample code is available in wxPython's tutorial page (http://wiki.wxpython.org/ WxHowtoSmallEditor). However, in addition I want to add "print" menu which will print the contents of editor (i.e. whatever written in editor). I will appreciate if someone please show me how to add printing option. Thanks, Akand -- http://mail.python.org/mailman/listinfo/python-list
Re: adding "Print" menu in wxPython
Thanks for your response. Actually I already know I have to create
"OnPrint" method followed by adding the menu named "Print" that calls
"OnPrint" method. But the problem I am facing is to implement it. Here
are the codes I am adding (from Tutorial) which make an editor and I
want to add printing option so that I can print whatever is written in
the editor. I will appreciate if you add coding with this file.
===
import wx
import os.path
class MainWindow(wx.Frame):
def __init__(self, filename='noname.txt'):
super(MainWindow, self).__init__(None, size=(400,200))
self.filename = filename
self.dirname = '.'
self.CreateInteriorWindowComponents()
self.CreateExteriorWindowComponents()
def CreateInteriorWindowComponents(self):
''' Create "interior" window components. In this case it is
just a
simple multiline text control. '''
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
def CreateExteriorWindowComponents(self):
''' Create "exterior" window components, such as menu and
status
bar. '''
self.CreateMenu()
self.CreateStatusBar()
self.SetTitle()
def CreateMenu(self):
fileMenu = wx.Menu()
for id, label, helpText, handler in \
[(wx.ID_ABOUT, '&About', 'Information about this program',
self.OnAbout),
(wx.ID_OPEN, '&Open', 'Open a new file', self.OnOpen),
(wx.ID_SAVE, '&Save', 'Save the current file',
self.OnSave),
(wx.ID_SAVEAS, 'Save &As', 'Save the file under a
different name',
self.OnSaveAs),
(None, None, None, None),
(wx.ID_EXIT, 'E&xit', 'Terminate the program',
self.OnExit)]:
if id == None:
fileMenu.AppendSeparator()
else:
item = fileMenu.Append(id, label, helpText)
self.Bind(wx.EVT_MENU, handler, item)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, '&File') # Add the fileMenu to the
MenuBar
self.SetMenuBar(menuBar) # Add the menuBar to the Frame
def SetTitle(self):
# MainWindow.SetTitle overrides wx.Frame.SetTitle, so we have
to
# call it using super:
super(MainWindow, self).SetTitle('Editor %s'%self.filename)
# Helper methods:
def defaultFileDialogOptions(self):
''' Return a dictionary with file dialog options that can be
used in both the save file dialog as well as in the open
file dialog. '''
return dict(message='Choose a file', defaultDir=self.dirname,
wildcard='*.*')
def askUserForFilename(self, **dialogOptions):
dialog = wx.FileDialog(self, **dialogOptions)
if dialog.ShowModal() == wx.ID_OK:
userProvidedFilename = True
self.filename = dialog.GetFilename()
self.dirname = dialog.GetDirectory()
self.SetTitle() # Update the window title with the new
filename
else:
userProvidedFilename = False
dialog.Destroy()
return userProvidedFilename
# Event handlers:
def OnAbout(self, event):
dialog = wx.MessageDialog(self, 'A sample editor\n'
'in wxPython', 'About Sample Editor', wx.OK)
dialog.ShowModal()
dialog.Destroy()
def OnExit(self, event):
self.Close() # Close the main window.
def OnSave(self, event):
textfile = open(os.path.join(self.dirname, self.filename),
'w')
textfile.write(self.control.GetValue())
textfile.close()
def OnOpen(self, event):
if self.askUserForFilename(style=wx.OPEN,
**self.defaultFileDialogOptions()):
textfile = open(os.path.join(self.dirname, self.filename),
'r')
self.control.SetValue(textfile.read())
textfile.close()
def OnSaveAs(self, event):
if self.askUserForFilename(defaultFile=self.filename,
style=wx.SAVE,
**self.defaultFileDialogOptions()):
self.OnSave(event)
app = wx.App()
frame = MainWindow()
frame.Show()
app.MainLoop()
-- Akand
On Jan 25, 6:54 pm, rantingrick wrote:
> On Jan 25, 5:52 pm, Akand Islam wrote:
>
>
>
> > I will appreciate if someone please show me how to add
> > printing option.
>
> Hello Akand,
>
> Well the first step would be to create a stub "OnPrint" method and add
> a command to the File menu named "Print" that calls the "OnPrint"
> method. Can you do this part yourself? All the answers you need are in
> the source you linked to. Give it your best shot and then post some
> code with a specific question if you get stuck.
--
http://mail.python.org/mailman/listinfo/python-list
Re: adding "Print" menu in wxPython
On Jan 26, 12:54 am, rantingrick wrote:
> On Jan 26, 12:19 am, rantingrick wrote:
>
> Actually i found more cruft. Here is something that would be
> acceptable although i had to wrap lines shorter than i normally would
> for the sake of Usenet. Who ever wrote that code should be lashed 50
> times! You still need some error handling for the open and save file
> methods but crikey i can't do everything ;-)
>
> #--STARTCODE--#
> import wx
> import os.path, sys
>
> class MainWindow(wx.Frame):
> def __init__(self, filename='noname.txt'):
> wx.Frame.__init__(self, None, size=(400,200))
> self.filename = filename
> self.dirname = '.'
> self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
> self.CreateMenu()
> self.CreateStatusBar()
> self.SetTitle('Editor %s'%self.filename)
> self.dlgdefaults = {
> 'message':'Choose a file',
> 'defaultDir':self.dirname,
> 'wildcard':'*.*'
> }
>
> def CreateMenu(self):
> fileMenu = wx.Menu()
> item = fileMenu.Append(wx.ID_ABOUT, '&About', 'Info')
> self.Bind(wx.EVT_MENU, self.OnAbout, item)
> item = fileMenu.Append( wx.ID_OPEN, '&Open', 'Info')
> self.Bind(wx.EVT_MENU, self.OnOpen, item)
> item = fileMenu.Append(wx.ID_SAVE, '&Save', 'Info')
> self.Bind(wx.EVT_MENU, self.OnSave, item)
> item = fileMenu.Append(wx.ID_SAVEAS, 'Save &As', 'Info')
> self.Bind(wx.EVT_MENU, self.OnSaveAs, item)
> #
> # psst: Hey put the print menu here
> # psst: do the binding here
> #
> fileMenu.AppendSeparator()
> item = fileMenu.Append(wx.ID_EXIT, 'E&xit', 'Exit')
> self.Bind(wx.EVT_MENU, self.OnExit, item)
> menuBar = wx.MenuBar()
> # Add the fileMenu to the MenuBar
> menuBar.Append(fileMenu, '&File')
> # Add the menuBar to the Frame
> self.SetMenuBar(menuBar)
>
> def askUserForFilename(self, **kw):
> dialog = wx.FileDialog(self, **kw)
> if dialog.ShowModal() == wx.ID_OK:
> userProvidedFilename = True
> self.filename = dialog.GetFilename()
> self.dirname = dialog.GetDirectory()
> self.SetTitle('Editor %s'%(self.filename))
> else:
> userProvidedFilename = False
> dialog.Destroy()
> return userProvidedFilename
>
> def OnAbout(self, event):
> dialog = wx.MessageDialog(
> self,
> 'A sample editor in wxPython',
> 'About Sample Editor',
> wx.OK
> )
> dialog.ShowModal()
> dialog.Destroy()
>
> def OnExit(self, event):
> self.Close()
>
> def OnSave(self, event):
> textfile = open(os.path.join(self.dirname, self.filename),
> 'w')
> textfile.write(self.control.GetValue())
> textfile.close()
>
> def OnOpen(self, event):
> if self.askUserForFilename(
> style=wx.OPEN,
> **self.dlgdefaults
> ):
> textfile = open(os.path.join(self.dirname, self.filename),
> 'r')
> self.control.SetValue(textfile.read())
> textfile.close()
>
> def OnSaveAs(self, event):
> if self.askUserForFilename(
> defaultFile=self.filename,
> style=wx.SAVE,
> **self.dlgdefaults
> ):
> self.OnSave(event)
>
> def OnPrint(self, event):
> sys.stdout.write(self.control.GetValue())
>
> app = wx.App()
> frame = MainWindow()
> frame.Show()
> app.MainLoop()
>
> #--ENDCODE--#
I really appreciate your cooperation. The codes you have written print
in command window, but I want to print (i.e. a popup window will
appear to select printer in order to print). Please assist me
regarding this. I am optimist that I can take care menu creating,
binding, error handling by myself. Therefore you can only show me the
"OnPrint" function to fulfill my purpose.
-- Akand
--
http://mail.python.org/mailman/listinfo/python-list
wxPython's "Print" Help
I can print whatever I want (definitely texts) by using following
"Printer" class. However, it prints only in Black and White mode
regardless original color of texts. Is there any way I can print color
texts?
=
#License: MIT
import wx
from wx import Printout, PrintData, PAPER_LETTER, PrintDialogData
from wx import Printer as wxPrinter, MessageBox, PrintPreview,
PrintDialog
def GetErrorText():
"Put your error text logic here. See Python Cookbook for a useful
example of error text."
return "Some error occurred."
class Printer(Printout):
def __init__(self, frame):
"Prepares the Printing object. Note: change current_y for 1,
1.5, 2 spacing for lines."
Printout.__init__(self)
self.printer_config = PrintData()
self.printer_config.SetPaperId(PAPER_LETTER)
self.frame = frame
self.doc_text = ''
self.doc_name = ''
self.current_y = 50 #y should be either (15, 22, 30)
if self.current_y == 15:
self.num_lines_per_page = 50
elif self.current_y == 22:
self.num_lines_per_page = 35
else:
self.num_lines_per_page = 60
def Print(self, text, doc_name):
"Prints the given text. Currently doc_name logic doesn't
exist. E.g. might be useful for a footer.."
self.doc_text = text
self.doc_name = doc_name
pdd = PrintDialogData()
pdd.SetPrintData(self.printer_config)
printer = wxPrinter(pdd)
if not printer.Print(self.frame,self):
MessageBox("Unable to print the document.")
else:
self.printer_config =
PrintData(printer.GetPrintDialogData().GetPrintData())
def PreviewText(self, text, doc_name):
"This function displays the preview window for the text with
the given header."
try:
self.doc_name = doc_name
self.doc_text = text
#Destructor fix by Peter Milliken --
print1 = Printer(self.frame, text = self.doc_text)
print2 = Printer(self.frame, text = self.doc_text)
preview = PrintPreview(print1, print2,
self.printer_config)
#preview = PrintPreview(self,self,self.printer_config)
if not preview.Ok():
MessageBox("Unable to display preview of document.")
return
preview_window = PreviewFrame(preview, self.frame, \
"Print Preview - %s" %
doc_name)
preview_window.Initialize()
preview_window.SetPosition(self.frame.GetPosition())
preview_window.SetSize(self.frame.GetSize())
preview_window.MakeModal(True)
preview_window.Show(True)
except:
MessageBox(GetErrorText())
def PageSetup(self):
"""
This function handles displaying the Page Setup window and
retrieving the user selected options.
It's been updated to use the new style Windows, which allow
more options to be configured.
"""
config_dialog = wxPageSetupDialog(self.frame)
config_dialog.GetPageSetupData()
config_dialog.ShowModal()
self.printer_config = config_dialog.GetPageSetupData()
config_dialog.Destroy()
def OnBeginDocument(self,start,end):
"Do any end of document logic here."
self.base_OnBeginDocument(start,end)
def OnEndDocument(self):
"Do any end of document logic here."
self.base_OnEndDocument()
def OnBeginPrinting(self):
"Do printing initialization logic here."
self.base_OnBeginPrinting()
def OnEndPrinting(self):
"Do any post printing logic here."
self.base_OnEndPrinting()
def OnPreparePrinting(self):
"Do any logic to prepare for printing here."
self.base_OnPreparePrinting()
def HasPage(self, page_num):
"This function is called to determine if the specified page
exists."
return len(self.GetPageText(page_num)) > 0
def GetPageInfo(self):
"""
This returns the page information: what is the page range
available, and what is the selected page range.
Currently the selected page range is always the available page
range. This logic should be changed if you need
greater flexibility.
"""
minPage = 1
maxPage = int(len(self.doc_text.split('\n'))/
self.num_lines_per_page) + 1
fromPage, toPage = minPage, maxPage
return (minPage,maxPage,fromPage,toPage)
def OnPrintPage(self, page_num):
"This function / event is executed for each page that needs to
be printed."
dc = self.GetDC()
x,y = 25, self.current_y
if not self.IsPreview():
y *=4
line_count = 1
for line in self.GetPageText(page_num):
dc.DrawText(line, x, y*line_count)
line_count += 1
retu
Re: wxPython's "Print" Help
On Feb 2, 3:24 pm, Terry Reedy wrote: > On 2/2/2011 12:36 AM, Akand Islam wrote: > > wxPython has its own mailing list. > > If you prefer newsgroups, like I do, connect to news.gmane.org and > subscribe to comp.lang.python.wxpython. > -- > Terry Jan Reedy Thanks for your response. -- Akand -- http://mail.python.org/mailman/listinfo/python-list
Non-linear regression help in Python
Hello all, I want to do non-linear regression by fitting the model (let say, y = a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must be in between (0 to 1), and others can be of any values. How can I perform my job in python? Thanks in advance. -- Akand -- http://mail.python.org/mailman/listinfo/python-list
Re: Non-linear regression help in Python
On Feb 14, 3:24 pm, Krzysztof Bieniasz wrote: > Dnia Mon, 14 Feb 2011 13:02:25 -0800, Akand Islam napisał(a): > > > Hello all, > > I want to do non-linear regression by fitting the model (let say, y = > > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must > > be in between (0 to 1), and others can be of any values. How can I > > perform my job in python? > > > Thanks in advance. > > > -- Akand > > http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html Dear Krzysztof Bieniasz, Thanks for reply. -- Akand -- http://mail.python.org/mailman/listinfo/python-list
Re: Non-linear regression help in Python
On Feb 14, 4:28 pm, sturlamolden wrote: > On 14 Feb, 22:02, Akand Islam wrote: > > > Hello all, > > I want to do non-linear regression by fitting the model (let say, y = > > a1*x+b1*x**2+c1*x**3/exp(d1*x**4)) where the parameter (say "c1") must > > be in between (0 to 1), and others can be of any values. How can I > > perform my job in python? > > First, install NumPy and SciPy! > > scipy.optimize.leastsq implements Levenberg-Marquardt, which is close > to the 'gold standard' for non-linear least squares. The algorithm > will be a bit faster and more accurate if you provide the Jacobian of > the residuals, i.e. the partial derivative of > > r = y - a1*x+b1*x**2+c1*x**3/exp(d1*x**4) > > with respect to a1, b1, c1, and d1 (stored in a 4 by n matrix). > > If you have prior information about c1, you have a Bayesian regression > problem. You can constrain c1 between 1 and 0 by assuming a beta prior > distribution on c1, e.g. > > c1 ~ Be(z,z) with 1 < z < 2 > > Then proceed as you would with Bayesian regession -- i.e. EM, Gibbs' > sampler, or Metropolis-Hastings. Use scipy.stats.beta to evaluate and > numpy.random.beta to sample the beta distribution. The problem is not > programming it in Python, but getting the correct equations on paper. > Also beware that running the Markov chain Monte Carlo might take a > while. > > Sturla Dear Sturlamolden, Thanks for reply. I will follow-up if I need further assistance. -- Akand -- http://mail.python.org/mailman/listinfo/python-list
