Skip to main content
GameDev.net gamedev.net
🔒 Locked

Calculus/Statistics Question

Started by Numsgil Nov 4, 2004 at 11:49 PM 7 replies 650+ views
Original Post
Numsgil
Numsgil
I'm trying to create a regression curve (ie: best fit curve) for stars' spectral class. There are 3 types (F,G,K) with each type having 10 subtypes. I know that: F type stars together = 10.344% G type stars together = 27.587% K type stars together = 62.069% I want to create a function (f(x)) such that: the integral, F(x) has the following properties, derived from the star percentages above: F(9)-F(0) = .10344 F(19)-F(10)=.27587 F(29)-F(20)=.62069 I don't know how to do it. I have a pretty high mathematics training, but I don't think I ever learned how to do the above. Ideally, the regression curve f(x) would be of the form a*b^x. If anyone can crunch the numbers, that'd be awesome. Thnx for your time.
[size=2]Darwinbots - [size=2]Artificial life simulation
C-Junkie
C-Junkie
Doesn't this involve something like taking the log of one or both axis and doing a linear regression on that?

Er, umm... That doesn't involve any integral, though.

Maybe I'm just nuts.
pmouse
pmouse
Quote:
Original post by Numsgil

F(9)-F(0) = .10344
F(19)-F(10)=.27587
F(29)-F(20)=.62069



That looks like an exponential function to me...
Doc
Doc
Just a quick thought, couldn't you just integrate the f(x)=ax+b function (ie to F(x)=ax2/2+bx+c), then take F(9)-F(0)=81a+9b=.10344, similarly for others, and solve simultaneously for a, and b?

EDIT: Bah. Silly me. Try integrating aekx. The methodology should still work. I think.
Numsgil
Numsgil
Quote:

That looks like an exponential function to me...


sure is, that's why f(x) is in the form of a*b^x.

Quote:

Just a quick thought, couldn't you just integrate the f(x)=ax+b function (ie to F(x)=ax2/2+bx+c), then take F(9)-F(0)=81a+9b=.10344, similarly for others, and solve simultaneously for a, and b?

EDIT: Bah. Silly me. Try integrating aekx. The methodology should still work. I think.


Yeah, I was trying to do something like that. F(x) is in the form of (ab^x)/(ln(b)), but I ran into two problems:

1. I have three equations and two unknowns. This is where the stats comes in. I need a regression that best fits the data, and I don't know how to do that. I usually just plug in points on my calculator and have it do it.

2. Even if I changed the equations to f(x) = a*b^(kx) so that I have three unknowns (kind of cheating I admit, but bear with me) the equations are a bit unruly for me. It could just be late at night. I'll work on it some more in the morning. THnx for the fast input everyone.
[size=2]Darwinbots - [size=2]Artificial life simulation
Doc
Doc
Quote:
Original post by Numsgil
Even if I changed the equations to f(x) = a*b^(kx) so that I have three unknowns (kind of cheating I admit, but bear with me) the equations are a bit unruly for me.


Yeah, that will happen when two of your three variables are related. A quick hack would be to pick two of your data points and solve for a and b. And maybe take the average of the solutions with different data points picked.

OK, how bout this (using aekx for ease, k and b are related, you can probably work out how):
We have M, the difference between F(x+9) and F(x). Thus, we have:
M = (a/k)ek(x+9)-(a/k)ekx
= (a/k)(e9k-1)ekx
By taking ln of both sides:
ln M = ln((a/k)(e9k-1)ekx)
= ln((a/k)(e9k-1)) + kx
Thus you have a gradient for the linear regression k and the y-offset is ln((a/k)(e9k-1)).

HTH

lonesock
lonesock
Well, I plugged the equation a*b^x (where x was the integer from 0 to 29) and let the Excel solver go wild. Best values were these:

a = 0.099793032
b = 1.088480207

the sum of the error (squared) got pretty low, but not to zero. But that could be just because of roundoff on those target percentage values.

if by "F(9)-F(0)" you meant the sum over that range (which I suspect you did mean), then I get this result.

a = 0.007571558
b = 1.088495955
Dmytry
Dmytry
Why not simply make your F(x) to fit, and then f(x) = derivative of F by x ?

Make F to be
F(0)=c
F(10)=c+0.10344
F(20)=c+0.10344 + 0.27587
F(30)=c+0.10344 + 0.27587 + 0.62069

and then take derivative.
If you want derivative to be
a*b^x
that is,
a*exp(ln(b)*x)
then , F must be integral of f,
F(x)=a*exp(ln(b)*x)/ln(b) + c

So you need to fit F(x)=a*exp(ln(b)*x)/ln(b) + c to several equations F(xn)=yn , that is,
F(0)=0
F(10)=0.10344
F(20)=0.10344 + 0.27587
F(30)=0.10344 + 0.27587 + 0.62069
,that is, solve that equations for a,b,c or bestfit.

Note that
a*exp(ln(b)*x)/ln(b) + c = exp(ln(a)-ln(b)+ln(b)*x) + c

so if you take logarithm of both sides of equations, you get
ln(F(xn)) = ln(yn)
that is,
ln(exp(ln(a)-ln(b)+ln(b)*xn)+c)=ln(yn)
then moving c outta ln edit: this step was WRONG. Don't read further.
ln(exp(ln(a)-ln(b)+ln(b)*xn))*exp(c)=ln(yn)
then using ln(exp(anything))=anything
(ln(a)-ln(b)+ln(b)*xn)*exp(c)=ln(yn)

Now nearly complete. It's linear [edit: not linear] now and you can [edit:probably can't] solve for ln(a), ln(b), and exp(c) and then find a,b,c.
(or i think probably you'll need to best-fit it, coz there's 4 equations and 3 unknowns)

Or use automatic solver. edit: and use automatic solver, coz there's mistake in my derivations.

And it's better if you'll not try it to be
0..9
10..19
20...30
because you have holes between 9 and 10, between 19 and 20, and it's not good.

edit:
Ehh... with all those stupid computer autosolvers i almost forgotten how it's done without calculator..
You need to make a logarithmical plot for your data, that is, plot points on
ln(xn),ln(yn)
(usually done using special paper)
and for that plots, any
a*b^x
is obviously straight line...

edit: got some idea:
Note that all these F,G,K classes is absolutely artifical thing. Them don't have to fit to exponential curve. At all. It's probably as good to make cubic spline for F and then differentiate(trivial) .

[Edited by - Dmytry on November 5, 2004 6:37:36 AM]
Numsgil
Numsgil
Quote:
Original post by lonesock
Well, I plugged the equation a*b^x (where x was the integer from 0 to 29) and let the Excel solver go wild. Best values were these:

a = 0.099793032
b = 1.088480207

the sum of the error (squared) got pretty low, but not to zero. But that could be just because of roundoff on those target percentage values.

if by "F(9)-F(0)" you meant the sum over that range (which I suspect you did mean), then I get this result.

a = 0.007571558
b = 1.088495955


I decided to use the second set of numbers as a starting point, and modified them slightly. I'll be using .0075448613 * exp(.0847968856x) since I like the exp function better than pow, (and I'm sure it's a little faster). Thanks for the help all. I'm glad I didn't have to resort to numerical methods. I should probably figure out Matlab or Matmatica or Excel or something, shouldn't I?
[size=2]Darwinbots - [size=2]Artificial life simulation

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.