Re: [Tutor] equation solving (was: Re: Tutor Digest, Vol 114, Issue 73)

2013-09-06 Thread Oscar Benjamin
On 5 September 2013 21:59, Alan Gauld  wrote:
> On 05/09/13 20:13, I. Alejandro Fleischer wrote:
>>
>> I have a set of data to fit to a custom equation, y=a+b*exp(k*x), would
>> you advice me on the how to, or tutorial?
>
> Can be be more precise? The more specific you are the easier it is
> to give specific answers.

I agree with Alan. You need to be more specific. I think that I
understand what you mean but perhaps you aren't aware that your
problem is ill-posed.

I'm going to assume that you have some data that gives paired
measurements of two quantities e.g. (x1, y1), (x2, y2), ... (xn, yn).
You want to find parameters a, b, and k so that y = a+b*exp(k*x) is a
good fit to your data. The problem is that there is no unique
definition of a "good" fit.

A well-posed optimisation problem identifies a single scalar quantity
that must be minimised (or maximised). The obvious choice in this kind
of thing is to treat one of your measured variables as the independent
variable (by convention this is called x) and the other as the
dependent variable (by convention y) and then define your error as the
sum of the squares of the residuals in estimating yi from xi:

Error = (1/2) sum[i=1..N] {   ((yi - (a+b*exp(k*xi)))**2)  }

However this is an arbitrary choice. You could have tried to regress x
onto y instead and then used the residuals for x which would lead to
different answers. Similarly choosing the sum of squares of the
residuals is an arbitrary choice.

In your particular case the highly non-linear relationship between x
and y means that minimising this kind of error could lead to a poor
result. If some of the yi are very large - as they could easily be for
this exponential relationship - then your fit will end up being
dominated by the largest data-points. In the worst case you'd
basically be computing an exact fit to the three largest data-points.
So a better residual might be something like:

(yi - (a+b*exp(k*xi))) / yi

It's hard to say without knowing more about the data or the problem though.

In any case your problem is just complicated enough that you need a
non-linear optimisation routine e.g. from scipy. If you knew the value
of a you could do a linear regression of log(y-a) onto x. Similarly if
you knew the value of k you could do a linear regression of y onto
exp(k*x). If you don't know any of a, b, or k then you have a
non-linear regression problem and you'll probably want to use a
function for non-linear least squares or perhaps an arbitrary
non-linear optimisation routine.

So your first step is probably to install scipy if you haven't already
and have a look at its optimize module. I can be more specific if you
explain a little more about what you're trying to do and what your
data looks like. Also as Alan says you need to explain how experienced
you are in the relevant maths, and in programming and Python to get
reasonable help.


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] OT: Coffeescript and Python

2013-09-06 Thread Alan Gauld

This is somewhat off topic so replies offlist may be appropriate.

I've just come across coffeescript(*) and started playing with it.
It seems to share a lot with Python and as such seems like a good 
replacement for Javascript in client side web code. I'm wondering if 
anyone here has used coffeescript with any of the Python web frameworks?

Specifically any of Turbogears, Django or Pylons?

(*)For any similarly afflicted souls, coffeescript is a language that 
compiles into pure (portable) javascript so it has no dependency issues 
with webservers or browsers but is easier to read/write. At least, 
that's the theory, I'm too early into it to be sure it works as 
advertised, but it looks promising.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fit data to equation

2013-09-06 Thread I. Alejandro Fleischer
Dear Alan and Oscar

Thank you.

 I'll try to be more accurate:

What Oscar wrote is exactly the situation:


> "I'm going to assume that you have some data that gives paired
> measurements of two quantities e.g. (x1, y1), (x2, y2), ... (xn, yn).
> You want to find parameters a, b, and k so that y = a+b*exp(k*x) is a
> good fit to your data. The problem is that there is no unique
> definition of a "good" fit."
>
>
> I will install scipy.



>
> So your first step is probably to install scipy if you haven't already
> and have a look at its optimize module. I can be more specific if you
> explain a little more about what you're trying to do and what your
> data looks like.


It's a variation , of a physical value ("y")  in time ("x")   (while
cooling) , you have the data measured (xi, yi), but not from x=0. I need to
extrapolate "y" to "x=0", by that equation.

I know the very basics about statistics, and a beginner in python, I ve
chosen python to work with.

Regards,

Igor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fit data to equation

2013-09-06 Thread Oscar Benjamin
On 6 September 2013 13:19, I. Alejandro Fleischer  wrote:
>
> It's a variation , of a physical value ("y")  in time ("x")   (while
> cooling) , you have the data measured (xi, yi), but not from x=0. I need to
> extrapolate "y" to "x=0", by that equation.
>
> I know the very basics about statistics, and a beginner in python, I ve
> chosen python to work with.

Okay well you'll want numpy, scipy and matplotlib if you don't have
those. Most documentation for those assumes familiarity with Python so
you may want to work through a bit of a python tutorial first (if you
haven't already). Then I'd suggest first writing a script that can
just plot your data-points using matplotlib.

Then for your actual fitting problem you'll want to use leastsq from
scipy's optimize module. See section 5.4 in this link:
http://www.tau.ac.il/~kineret/amit/scipy_tutorial/

Here's a basic example of how to use the function:

from scipy.optimize import leastsq

# The "true values"
amin = 2
bmin = 3

# The residual as a function of the parameters a and b
def residual(ab):
a, b = ab
return [amin - a, bmin - b]

# Initial estimate of parameters a and b
aguess = 0
bguess = 0

# Fitted values from fitting algorithm
(afit, bfit), _ = leastsq(residual, (aguess, bguess))
print('afit: %s' % afit)
print('bfit: %s' % bfit)


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to unpack python-dateutil-2.0.tar.gz

2013-09-06 Thread nelsonpaixao
Richard D. Moores  gmail.com> writes:

> 
> Python 3.2.3 64 bit
> MS Windows 7 Home Premium 64-bit SP1
> 
> I see python-dateutil recommended here from time to time, so I thought
> I'd try it out. I downloaded python-dateutil-2.1.tar.gz from
> http://pypi.python.org/pypi/python-dateutil but have forgotten how to
> unpack a .tar.gz file. Please remind me.
> 
> Thanks,
> 
> Dick Moores
> ___
> Tutor maillist  -  Tutor  python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

hello there,

today i was searching for that too,

you can download here all the adds you need for python, all came with windons 
installer
http://www.lfd.uci.edu/~gohlke/pythonlibs/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: Coffeescript and Python

2013-09-06 Thread Emile van Sebille

On 9/6/2013 3:47 AM, Alan Gauld wrote:

This is somewhat off topic so replies offlist may be appropriate.


I can fix that.  :)

Are you familiar with pyjs, which provides python to javascript 
capabilities? (see http://pyjs.org/)


Is there any reason to prefer one over the other?

Emile



I've just come across coffeescript(*) and started playing with it.
It seems to share a lot with Python and as such seems like a good
replacement for Javascript in client side web code. I'm wondering if
anyone here has used coffeescript with any of the Python web frameworks?
Specifically any of Turbogears, Django or Pylons?

(*)For any similarly afflicted souls, coffeescript is a language that
compiles into pure (portable) javascript so it has no dependency issues
with webservers or browsers but is easier to read/write. At least,
that's the theory, I'm too early into it to be sure it works as
advertised, but it looks promising.




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] why do i keep getting syntax errors in python when this runs

2013-09-06 Thread mike johnson
can you please help me figure out why this isnt working thanks
# convert.py
# this program is used to convert Celsius temps to Fahrenheit
# By: James Michael Johnson

Def main ():
Celsius = float (input ("What is the Celsius temperature? "))
Fahrenheit = 9.0 / 5.0 * Celsius + 32
Print ("The temperature is ", Fahrenheit, " degrees Fahrenheit.")


Main ()








  # convert.py
# this program is used to convert Celsius temps to Fahrenheit
# By: James Michael Johnson

Def main ():
Celsius = float (input ("What is the Celsius temperature? "))
Fahrenheit = 9.0 / 5.0 * Celsius + 32
Print ("The temperature is ", Fahrenheit, " degrees Fahrenheit.")


Main ()




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why do i keep getting syntax errors in python when this runs

2013-09-06 Thread Prasad, Ramit
Joel Goldstick wrote:
> On Fri, Sep 6, 2013 at 12:27 AM, mike johnson  wrote:
> > can you please help me figure out why this isnt working thanks
> 
> You have tthree problems:
> 
> > # convert.py
> > # this program is used to convert Celsius temps to Fahrenheit
> > # By: James Michael Johnson
> >
> > Def main ():
> 
> The keyword is def, not Def, so rewrite like:
> def main():
> 
> > Celsius = float (input ("What is the Celsius temperature? "))
> > Fahrenheit = 9.0 / 5.0 * Celsius + 32
> > Print ("The temperature is ", Fahrenheit, " degrees Fahrenheit.")
> >
> >
> You have not indented the suite of code that runs in main, so set your
> editor to print 4 spaces when tab is pressed, and tab each line under
> main.
> 
> 
> > Main ()
> 
> 
> You defined main() but you called Main.  Python is case sensitive, so
> change this to main()

It should also be "print" and not "Print".


~Ramit



This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: Coffeescript and Python

2013-09-06 Thread Japhy Bartlett
I worked on a project that used cofeescript with Django.  You basically
have to know javascript to debug it properly, so it didn't really save our
team any time and we got rid of it as soon as we could.

Obviously that's just anecdotal, YMMV!


On Fri, Sep 6, 2013 at 5:47 AM, Alan Gauld wrote:

> This is somewhat off topic so replies offlist may be appropriate.
>
> I've just come across coffeescript(*) and started playing with it.
> It seems to share a lot with Python and as such seems like a good
> replacement for Javascript in client side web code. I'm wondering if anyone
> here has used coffeescript with any of the Python web frameworks?
> Specifically any of Turbogears, Django or Pylons?
>
> (*)For any similarly afflicted souls, coffeescript is a language that
> compiles into pure (portable) javascript so it has no dependency issues
> with webservers or browsers but is easier to read/write. At least, that's
> the theory, I'm too early into it to be sure it works as advertised, but it
> looks promising.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2013-09-06 Thread Sammy Cornet
on my Interpreter windows, as my first attempt, I wrote "hello world" but it 
keep telling me this: SyntaxError: invalid syntax
 Can you help me please?
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why do i keep getting syntax errors in python when this runs

2013-09-06 Thread Alan Gauld

On 06/09/13 05:27, mike johnson wrote:

can you please help me figure out why this isnt working thanks


The fundamental problem is that Python is case sensitive
so Def and def are two different words.
As are Main and main and Print and print.

Also Python cares about spacing. You need to indent your
code within the function.


Def main ():
Celsius = float (input ("What is the Celsius temperature? "))
Fahrenheit = 9.0 / 5.0 * Celsius + 32
Print ("The temperature is ", Fahrenheit, " degrees Fahrenheit.")

>
> Main()

Finally, as a matter of style, capitalized names tend to be
reserved for class definitions (you probably haven't read
about them yet!)

This should therefore become:

def main ():
   celsius = float (input ("What is the Celsius temperature? "))
   fahrenheit = 9.0 / 5.0 * celsius + 32
   print ("The temperature is ", fahrenheit, " degrees Fahrenheit.")

main()

HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2013-09-06 Thread Alan Gauld

On 06/09/13 20:52, Sammy Cornet wrote:

on my Interpreter windows, as my first attempt, I wrote "hello world"
but it keep telling me this: SyntaxError: invalid syntax
  Can you help me please?


Python doesn't understand what "hello world" means.
It's just a value, like 42 or True to python. So python reports a syntax 
error (ie 'grammar' it doesn't understand).


You need to tell Python what to do with your text. I suspect you
wanted to print it so you should type:

print("hello world")

Find a tutorial you like and follow it until you get
the hang of things.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2013-09-06 Thread Steven D'Aprano
On Fri, Sep 06, 2013 at 02:52:51PM -0500, Sammy Cornet wrote:

> on my Interpreter windows, as my first attempt, I wrote "hello world" 
> but it keep telling me this: SyntaxError: invalid syntax
>  Can you help me please?

Yes. The first, and most important, tool in your toolbox as a programmer 
is to take careful note of the error messages you are given. The second 
most important tool is to ask good questions.

Asking good questions means showing exactly what you did, *precisely*, 
and not leaving it up to the reader to guess. The best way is to copy 
and paste the relevant lines from your interpreter window.

If you typed *literally* "hello world", complete with quotation marks, 
you shouldn't have got a SyntaxError, so I'm guessing you didn't do 
this:

py> "hello world"
'hello world'


But if you left out the quotation marks, you would have:

py> hello world
  File "", line 1
hello world
  ^
SyntaxError: invalid syntax


Notice the almost-blank line above the SyntaxError? See the ^ caret? 
That shows you where Python thinks the error is. Unfortunately the 
Python parser is a bit dumb, and often doesn't detect the error until 
the end of the offending text, rather than the beginning. But in this 
case, it doesn't matter: the offending term is "world" (no quotation 
marks) since you cannot separate what looks like two variables with just 
a space.

`"hello"` inside quotation marks is a string, `hello` on its own without 
quotation marks is a variable. If you leave the quotation marks out, 
then Python parses your text as:

(variable hello) (variable world)

which is illegal syntax.

Have I guessed you problem correctly? If not, you'll have to show us 
exactly what you did. In the meantime, here's my second guess: you tried 
to *print* "hello world", and you did this:

print "hello world"


In this case, are you using Python 3? In Python 2, print is a statement, 
and can be given as shown above, but that was deemed to be a mistake for 
various reasons, and in Python 3 it was changed to a regular function 
that requires round brackets (or parentheses for American readers):

print("hello world")


Does this help?


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fit data to equation

2013-09-06 Thread Tanmaya Meher
You can try the below tutorial.

1. http://wiki.scipy.org/Cookbook/FittingData

2. http://people.duke.edu/~ccc14/pcfb/analysis.html

Also, take a look at the below curve fitting tool from optimization tool
set of scipy. I think it will help you better and with ease.

http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

If you are writing program on your own try lambda to define your function,
use some library module like scipy for fitting / optimization and library
module like pylab to plot.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why do i keep getting syntax errors in python when this runs

2013-09-06 Thread Joel Goldstick
On Fri, Sep 6, 2013 at 12:27 AM, mike johnson  wrote:
> can you please help me figure out why this isnt working thanks

You have tthree problems:

> # convert.py
> # this program is used to convert Celsius temps to Fahrenheit
> # By: James Michael Johnson
>
> Def main ():

The keyword is def, not Def, so rewrite like:
def main():

> Celsius = float (input ("What is the Celsius temperature? "))
> Fahrenheit = 9.0 / 5.0 * Celsius + 32
> Print ("The temperature is ", Fahrenheit, " degrees Fahrenheit.")
>
>
You have not indented the suite of code that runs in main, so set your
editor to print 4 spaces when tab is pressed, and tab each line under
main.


> Main ()


You defined main() but you called Main.  Python is case sensitive, so
change this to main()
>
>
>
>
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
http://joelgoldstick.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor