473,804 Members | 3,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fonction in python


Hello,

If we write = x^2 and if I give to the program the values of x, it will
going to calculate the values of y, and also for x.

But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!

Thanks

--
View this message in context: http://www.nabble.com/fonction-in-py....html#a5164997
Sent from the Python - python-list forum at Nabble.com.

Jul 4 '06 #1
6 1465
aliassaf wrote:
Hello,

If we write = x^2 and if I give to the program the values of x, it will
going to calculate the values of y, and also for x.

But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!
That is not possible at all. There are too many possible functions mapping
2 to 4, 3 to 9 etc.

You can, however, create a list of candidate functions and check your input
pairs (x,y) against each of those functions to see if any of them matches.

Short, unoptimized example:

functions = [
lambda x: x,
lambda x: x+1,
lambda x: x*x,
lambda x: x**3,
]

input = [(1,1), (2,2)]

for function in functions:
for x,y in input:
if function(x) != y:
break
else:
print "function", function, "matches"

Georg
Jul 4 '06 #2
On Tue, 04 Jul 2006 03:06:37 -0700, aliassaf wrote:
>
Hello,

If we write = x^2 and if I give to the program the values of x, it will
going to calculate the values of y, and also for x.

But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!
You are asking for curve-fitting. There is a HUGE amount of work on
curve-fitting in computer science and statistics.

Generally, you start with some data points (x, y). You generally have some
idea of what sort of function you expect -- is it a straight line? A
curve? What sort of curve? A polynomial, an exponential, a sine curve, a
cubic spline, a Bezier curve?

You might like to google on "least squares curve fitting" and "linear
regression". That's just two methods out of many.

Some curve-fitting methods also estimate the error between the predicted
curve and the data points; you could then try all of the methods and pick
the one with the least error.

--
Steven.

Jul 4 '06 #3
On 2006-07-04, aliassaf <as*****@ensiet a.frwrote:
But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!
Sort of. There are a number of curve-fitting modules available
for Python as part of packages like ScyPy http://www.scipy.org/
and Scientific Python http://sourcesup.cru.fr/projects/scientific-py/

You generally have to provide the fitter with a function
"template" for which it can find the coefficients. For
example, you tell the fitter that you want a polynomial of the
form f(y) = Ax^2 + Bx + C, and the fitter will find the values
of A, B, C that best fit the data.

There are also commercial products that have lists of hundreds
of "templates" and will crunch through thme to find the ones
that provide the best fits.

--
Grant Edwards
gr****@visi.com
Jul 4 '06 #4

aliassaf wrote:
Hello,

If we write = x^2 and if I give to the program the values of x, it will
going to calculate the values of y, and also for x.

But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!
You can use the GMPY module to determine square & power relationships:
>>import gmpy
for n in range(20):
print n,
if gmpy.is_square( n):
print True,
else:
print False,
if gmpy.is_power(n ):
print True
else:
print False
0 True True
1 True True
2 False False
3 False False
4 True True
5 False False
6 False False
7 False False
8 False True
9 True True
10 False False
11 False False
12 False False
13 False False
14 False False
15 False False
16 True True
17 False False
18 False False
19 False False

9 is both a power and a square whereas 8 is a power but not a square.

>
Thanks

--
View this message in context: http://www.nabble.com/fonction-in-py....html#a5164997
Sent from the Python - python-list forum at Nabble.com.
Jul 4 '06 #5
Steven D'Aprano wrote:
On Tue, 04 Jul 2006 03:06:37 -0700, aliassaf wrote:

>>Hello,

If we write = x^2 and if I give to the program the values of x, it will
going to calculate the values of y, and also for x.

But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!


You are asking for curve-fitting. There is a HUGE amount of work on
curve-fitting in computer science and statistics.

Generally, you start with some data points (x, y). You generally have some
idea of what sort of function you expect -- is it a straight line? A
curve? What sort of curve? A polynomial, an exponential, a sine curve, a
cubic spline, a Bezier curve?

You might like to google on "least squares curve fitting" and "linear
regression". That's just two methods out of many.

Some curve-fitting methods also estimate the error between the predicted
curve and the data points; you could then try all of the methods and pick
the one with the least error.
The problem being that complex enough models will fit the data
arbitrarily closely (i.e. over-fit). The OP should take into account
any prior expectations over the type of function (as you indicate) and
apply Occam's razor (find a relatively simple model that gives a
reasonable fit to the data).

Duncan
Jul 4 '06 #6
On 4/07/2006 8:06 PM, aliassaf wrote:
Hello,

If we write = x^2 and if I give to the program the values of x, it will
going to calculate the values of y, and also for x.

But it is possible ? that is if I give to the program the values of X and Y,
it will indicate to me the relation between the two variables, in the other
hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
that f (t)!!!
Please pardon me for introducing Python-related subject matter into a
thread devoted to curve-fitting :-)

Consider the following:

|>[x ^ 2 for x in range(10)]
[2, 3, 0, 1, 6, 7, 4, 5, 10, 11]

Not what you wanted? Try this:

|>[x ** 2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

Cheers,
John

Jul 4 '06 #7

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

Similar topics

3
5234
by: Philippe Mesmeur | last post by:
J'ai eu une longue discussion hier au sujet des parametres de fonction const. La personne etait pour mettre "const" devant TOUS les parametres ne devant pas etre modifies. A mon avis, il faut le faire que SI le parametre est un pointeur ou une référence. int fct1(const int* i);
3
2844
by: Chris | last post by:
function Main(param) { alert("test "+param); <<<<<<<<<<< Ici tout se passe bien : le contenu de param est bien affiché fchaine='' .... +'<div ><a href="#" onclick="javascript:return Suite('+param+');"><IMG src="tg.gif" ></a></div>' .... document.write(fchaine); }
8
1400
by: jean-jeanot | last post by:
I am writing a prototype program whose aim is to collect bookkeeping transactions in a Database ( Gadfly). After creating the table I create the variables with varAmount = StringVar() I then create labels in Tkinter to ease the input of data. With a function def treatment (): requete = "insert into transactions ( date,amount,,....) values(......) "% (varDate.get(), varAmount.get
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
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
10318
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...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
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
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.