Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Output format for find_fit and solve
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Oscar Gerardo Lazo Arjona  
View profile  
 More options Oct 29 2010, 6:59 pm
From: Oscar Gerardo Lazo Arjona <algebraicame...@gmail.com>
Date: Fri, 29 Oct 2010 17:59:16 -0500
Local: Fri, Oct 29 2010 6:59 pm
Subject: Output format for find_fit and solve
I want to propose the following changes to the output format of find_fit
and solve:

for find_fit the current output format is a list of equations:

sage: data = [(i, 1.2 * sin(0.5*i-0.2) + 0.1 * normalvariate(0, 1)) for
i in xsrange(0, 4*pi, 0.2)]
sage: var('a, b, c, x')
sage: model(x) = a * sin(b * x - c)
sage: find_fit(data, model)

[a == 1.2204167610363676, b == 0.50171964598627838, c ==0.22401763827376933]

or a dictionary:

sage: find_fit(data,model,solution_dict=True)

{c: 0.22401763827376933, b: 0.50171964598627838, a: 1.2204167610363676}

I'd like to get an expression where the values found for the parameters
are put in the model given to find_fit:

sage: find_fit(data, model)
1.2204167610363676*sin(0.50171964598627838 *x -0.22401763827376933 )

For solve the current output format depends on the input:

sage: var('x y')
sage: eq1=x+4==0
sage: eq2=x^2+4*x+2==0
sage: sys1=x+y==1
sage: sys2=x-2*y==-2
sage: solve(eq1,x)
[x == -4]
A list containing solutions (even when there is only one solution).

sage: solve(eq2,x)
[x == -sqrt(2) - 2, x == sqrt(2) - 2]
A list containing solutions when there is more than one solution

solve([sys1,sys2],x,y)
[[x == 0, y == 1]]
A list containing a list containing solutions (this is the worst)

The format I would like to see is:

sage: solve(eq1,x)
x == -4
A single equation

sage: solve(eq2,x)
[x == -sqrt(2) - 2, x == sqrt(2) - 2]
This one is fine

solve([sys1,sys2],x,y)
[x == 0, y == 1]
Just a list of solutions. It is harder to work with the solutions if
they are inside another list.

I would like all of this changes to become standard outputs, although I
imagine that that would produce some backwards compatibility issues.

thanks!

Oscar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Grout  
View profile  
 More options Oct 30 2010, 3:26 am
From: Jason Grout <jason-s...@creativetrax.com>
Date: Sat, 30 Oct 2010 02:26:20 -0500
Local: Sat, Oct 30 2010 3:26 am
Subject: Re: Output format for find_fit and solve
On 10/29/10 5:59 PM, Oscar Gerardo Lazo Arjona wrote:

Why not make solution_dict=True the default, since then you could say:

fit=find_fit(data,model)
model.subs(fit)

to get the model with those parameters?

In fact, it would be great if this worked too:

fit=find_fit(data,model)
model(**fit)

but (even if solution_dict=True is the default) that complains that the
keys in the dictionary are not strings.

However, we could make this work:

fit=find_fit(data,model)
model(fit)

but it require changes to the __call__ method to allow a dictionary
input that would do the same as .subs() would do if handed a dictionary.

What if there are two different solutions, like (x=0, y=0) and (x=0,y=1)?

Personally, I think returning an equation is okay for situations where I
am just checking something, and don't plan on using the solution again.
  Returning a list of equations is horrible for actually doing anything
with the results, which is my intent in the vast majority of situations.
  Having to always append the not-very-obvious "solution_dict=True" to
use solve in the common case is not very user-friendly.  If we're
changing the output of solve, I'd propose returning either a single
dictionary (a single solution) or a list of dictionaries (multiple
solutions).  Solve seems like it would be much more useful that way.

Thanks,

Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oscar Lazo  
View profile  
 More options Oct 30 2010, 11:20 am
From: Oscar Lazo <estadisticame...@gmail.com>
Date: Sat, 30 Oct 2010 08:20:13 -0700 (PDT)
Local: Sat, Oct 30 2010 11:20 am
Subject: Re: Output format for find_fit and solve

On Oct 30, 2:26 am, Jason Grout <jason-s...@creativetrax.com> wrote:

Making solution_dict the default seems apropiate for find_fit and
solve. I still would prefer a symbolic result for find_fit though (at
least an option to get that). Usually when one fits some data to a
model what one is trying to do is to interpolate data in between the
current data (plot the fitted function etc). Mathematica uses this two
outputs in two different functions:

For Fit they use a symbolic output: http://reference.wolfram.com/mathematica/ref/Fit.html

For FindFit they use something that looks like a dictionary:
http://reference.wolfram.com/mathematica/ref/FindFit.html

As for solve, I agree, we should return a single dictionary when
there's just one solution and a list of dictionaries when there's more
than one solution.

thanks!

Oscar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Grout  
View profile  
 More options Oct 30 2010, 6:47 pm
From: Jason Grout <jason-s...@creativetrax.com>
Date: Sat, 30 Oct 2010 17:47:06 -0500
Local: Sat, Oct 30 2010 6:47 pm
Subject: Re: Output format for find_fit and solve
On 10/30/10 10:20 AM, Oscar Lazo wrote:

> Making solution_dict the default seems apropiate for find_fit and
> solve. I still would prefer a symbolic result for find_fit though (at
> least an option to get that). Usually when one fits some data to a
> model what one is trying to do is to interpolate data in between the
> current data (plot the fitted function etc). Mathematica uses this two
> outputs in two different functions:

> For Fit they use a symbolic output: http://reference.wolfram.com/mathematica/ref/Fit.html

> For FindFit they use something that looks like a dictionary:
> http://reference.wolfram.com/mathematica/ref/FindFit.html

I think that having two functions sounds like a great approach.

Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Kirkby  
View profile   Translate to Translated (View Original)
 More options Oct 31 2010, 7:59 am
From: David Kirkby <david.kir...@onetel.net>
Date: Sun, 31 Oct 2010 11:59:09 +0000
Local: Sun, Oct 31 2010 7:59 am
Subject: Re: [sage-devel] Re: Output format for find_fit and solve
On 30 October 2010 23:47, Jason Grout <jason-s...@creativetrax.com> wrote:

Wolfram Research do the same with integration.

Integrate[]  symbolic
NIntegrate[] -  numeric

N[ Integrate[] ] - Numerical approximation to a symbolic answer.
Integrate[] //N - another way of writing the above

The same for finding roots.

http://reference.wolfram.com/mathematica/ref/FindRoot.html (numerical)
http://reference.wolfram.com/mathematica/ref/Root.html (symbolic)

There are undoubtedly other examples too. Mathematica uses different
functions for numerical and symbolic work.

Dave


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oscar Lazo  
View profile  
 More options Nov 4 2010, 3:39 pm
From: Oscar Lazo <estadisticame...@gmail.com>
Date: Thu, 4 Nov 2010 12:39:56 -0700 (PDT)
Local: Thurs, Nov 4 2010 3:39 pm
Subject: Re: Output format for find_fit and solve
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »