This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Your Projects subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Project Ideas/Start New Projects => Your Projects
Author Message
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 02 Dec 2005 04:07:29 am    Post subject:

I'm working on a curve fitter for a math project.
The project has ended but I want to continue with the program
first beta is here

let it be clear I use non of the build in functions of the calc but use own fitting strategies, if you call it crazy and double work because Ti has already build in these functions, I understand, but my it was a math project and then you have to do stuf yourself, and because it was fun I wanna continue. cause its not realy finished

questions:
-if you know a good fitting method please tel me, data points are in List X and Y make a eqation out of it.
-if you look at the source and say that's absolultely wrong, and some things are (prgm is underconstruction remember) tel me also

short: say everything that can help me build a good curve fitter
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 02 Dec 2005 05:19:53 am    Post subject:

I have a simple plea, Jacobbus:

PLEASE TRY TO REWRITE YOUR CODE WITH THE MINIMUM AMOUNT OF GOTOs! (of course, excepting the situation where you had to use gotos for getting out of Menu( choices...)

Man, MEDGO with your code. :o

Question: can you share with us the algorithm you're using? It would seem to me that you're using the "normal equations" approach for the polynomial fitting, and an iterative method for the sine fit. I can't tell, however. :(

Apart from that, the only space-saving suggestion I can give would be noting that


Code:
If condition
Then
statement1
End


is functionally equivalent to


Code:
If condition
statement1


:)

thornahawk
Back to top
kermmartian
Site Admin Kemetech


Calc Guru


Joined: 20 Mar 2004
Posts: 1220

Posted: 02 Dec 2005 09:23:43 am    Post subject:

I have another great idea. [STAT]-->CALC.
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 02 Dec 2005 10:24:37 am    Post subject:

Kerm, did you read the relevant part of his post? :o

Quote:
...I use none of the built-in functions of the calc, but use my own fitting strategies. If you call it crazy and extraneous work because TI has already built these functions in, I understand, but it was my math project, and then you have to do stuff yourself, and because it was fun I want to continue...


(well, not an exact quote of Jacobbus Very Happy but that's what I think he was saying)

Of course, for it to be a more productive project, I would think that a useful generalization would be the ability to do the general linear regression problem: given functions f1(x), f2(x), ... fi(x) and a set of data points, find parameters a(1), a(2), ... a(i) such that the sum of squares of residuals is minimized. A.k.a., finding the function

y=a(1)*f1(x) + a(2)*f2(x) + ... + a(i)*fi(x)

or even more general schemes like weighted or total least squares regression. :D

thornahawk

P.S. Man, it's sometimes difficult to write formulae without subscripts available... :hmpf:


Last edited by Guest on 02 Dec 2005 10:26:05 am; edited 1 time in total
Back to top
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 02 Dec 2005 10:58:30 am    Post subject:

thornahawk wrote:
I have a simple plea, Jacobbus:

PLEASE TRY TO REWRITE YOUR CODE WITH THE MINIMUM AMOUNT OF GOTOs! (of course, excepting the situation where you had to use gotos for getting out of Menu( choices...)

Man, MEDGO with your code. Surprised

Man your so right, I'am deeply ashamed, I could say that I was under a time limmit, that I only had a few ours sleep this week, and so on. and its true but your absolutey right, It's verry dumb code, and I'm verry angry Mad , cause this is also the code my teachter has, and he has to give the mark Cool
Quote:

Code:
If condition
Then
statement1
End


is functionally equivalent to


Code:
If condition
statement1

[post="63002"]<{POST_SNAPBACK}>[/post]

yep I know but if I use that I always get in trouble with the End's

thornahawk wrote:
Kerm, did you read the relevant part of his post? :o

Quote:
...I use none of the built-in functions of the calc, but use my own fitting strategies. If you call it crazy and extraneous work because TI has already built these functions in, I understand, but it was my math project, and then you have to do stuff yourself, and because it was fun I want to continue...


(well, not an exact quote of Jacobbus Very Happy but that's what I think he was saying)
[post="63008"]<{POST_SNAPBACK}>[/post]

Sad Mad awrg is my Enlish so bad ? Mad Sad

the sin 'algorithm' works for the A and B vars, but has some problems with C and D, but I haven't found someting better, so I made the sin function myself (as you see that has some conseqenses for the quality)
the polynomal is pure brute force and I realy want to improve that part, I'm searching for a way to do that but haven't found somthing yet
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 02 Dec 2005 11:19:49 am    Post subject:

"...I am deeply ashamed..."

Don't worry; I have been guilty of more heinous mistakes in the first few years of my programming! :D

Go catch up with your sleep, will you? It's hard to write when sleep deprived. ;)

"...if I use that I always get in trouble with the End's..."

Can you give us an example?

"...is my English so bad?"

Not really, you're slightly better than a good number of people I know. Wink But it does need improvement!

"...the sin 'algorithm' works for the A and B variables, but has some problems with C and D, but I haven't found something better, so I made the sin function myself (as you can see, that has some consequences for the quality)..."

I will offer you a good search term: "Levenberg-Marquardt".

"...polynomial is pure brute force and I really want to improve that part, I'm searching for a way to do that..."

...and more Google hints: "normal equations" and "QR decomposition".

As a matter of fact, writing a general regression program is one of my hanging projects! ;)

You might also want to take a good look at MathWorld; there's a healthy discussion of mathematics there which might be useful for your particular case...

thornahawk

P.S. If you can't rewrite it now, can you post your pseudocode (i.e. how the logic flows in your program)?


Last edited by Guest on 02 Dec 2005 11:20:55 am; edited 1 time in total
Back to top
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 02 Dec 2005 12:28:16 pm    Post subject:

Yeah, thats real help, thanks :biggrin:
I'l try to start coding tomorow

Quote:
Go catch up with your sleep, will you? It's hard to write when sleep deprived. wink.gif
I relaxed a bit at school and will try to by on time in my bed this evening Wink

Quote:
"...if I use that I always get in trouble with the End's..."

Can you give us an example?
try:

Code:
If A=0
For(X,1,10
"
End
gives ERR:SYNTAX
goto goes to End
because the official if statment is If Then (Else) End, and if there are more End involved the calc doen't know for which If or For( the end is written

Quote:
As a matter of fact, writing a general regression program is one of my hanging projects! wink.gif
If I ever get a real version you may write your name in the credits, for the help, and say it when I forget.

Quote:
P.S. If you can't rewrite it now, can you post your pseudocode (i.e. how the logic flows in your program)
the logic flows like this:

It may look a bit better than the reality, but with this in mind I started programming


Last edited by Guest on 02 Dec 2005 03:29:37 pm; edited 1 time in total
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 03 Dec 2005 03:59:56 am    Post subject:

Actually, I am more interested in what you do in those "Method n" boxes. Very Happy
The rest is pretty straightforward; I just want to analyze the root of your convergence/inaccuracy problems. Why are your constants coming out a bit off and such...

thornahawk
Back to top
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 03 Dec 2005 02:53:43 pm    Post subject:

oke oke I thougt you did understand the code,but if I have to enlight it oke, the sin code:

Code:
Lbl B4
dim(LX)->N;look how much data points we have
max(LY)->T;highest point we have
min(LY)->Y; lowest  ''
T+Y->O
O/2->LB4(1);min+max/2=line trough the middle
T-(O/2)->LB4(2);the distance from the highest point to the midle line
For(O,1,N
If LY(O)=T
Then
O->T
End; search the place of the highest point in our data lists
If LY(O)=Y
Then
O->Y
End
End;same for lowest point
0->S
For(O,T,N; go from highest to the end
If LY(O)<0; check if we pass the 0 line (dumb cause: we have no 0's in the data and if 0 isn't the middle we have problems)
Then
1->Z
LX(O)-LX(T)->S;check difference
End
End
If Z=1
Then
For(O,T,1,-1; do the same as before only to the other side of highest point
If LY(O)<0
Then
LX(T)-LX(O)->S
End
End
End
If S=0; if something went wrong give a high value for the fit so this one isn't selected as the best
Then
1E99->LM(4)
Goto A2

o, and S is C thus list B4(3)
and the distance form the higest point to the Y axis is D list B4(4)
Back to top
TStach


Newbie


Joined: 30 Nov 2005
Posts: 40

Posted: 03 Dec 2005 05:10:55 pm    Post subject:

Optimized Code:

Code:
dim(LX)->N;look how much data points we have
max(LY)->T;highest point we have
min(LY)->Y; lowest  ''
T+Ans->O ///////////////// line changed /////////////////
.5Ans->LB4(1);min+max/2=line trough the middle ///////////////// line changed /////////////////
T-(O/2)->LB4(2);the distance from the highest point to the midle line
For(O,1,N
If LY(O)=T
///////////////// line removed /////////////////
O->T
///////////////// line removed /////////////////
If LY(O)=Y
///////////////// line removed /////////////////
O->Y
///////////////// line removed /////////////////
End;same for lowest point
0->S
For(O,T,N; go from highest to the end
If LY(O)<0; check if we pass the 0 line (dumb cause: we have no 0's in the data and if 0 isn't the middle we have problems)
Then
1->Z
LX(O)-LX(T)->S;check difference
End
End
If Z=1
Then
For(O,T,1,-1; do the same as before only to the other side of highest point
If LY(O)<0
///////////////// line removed /////////////////
LX(T)-LX(O)->S
///////////////// line removed /////////////////
End
End
If Ans=0; if something went wrong give a high value for the fit so this one isn't selected as the best ///////////////// line changed /////////////////
Then
1E99->LM(4)
///////////////// memory leak! /////////////////
Goto A2


When programming:
- After storing something into a variable, and if the next line uses that variable, replace the second iteration of variable with Ans. Example:

Code:
// unoptimized code
A + X -> Y
Y + 5 -> Z

// optimized code
A + X -> Y
Ans + 5 -> Z


- Watch your if...then...ends

Code:
// proper usage of if...then...end
if x=0
then
X+5 -> A
Y+2 -> B
end

// do not use if...then...end if you're only have one statement in your conditional
// bad example:
if x=0
then
x + 5 -> Y
end

// good example:
if x=0
x + 5 -> Y
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 03 Dec 2005 05:56:27 pm    Post subject:

I guess I'll squeeze out the rest of the optimizations that I can see.

[font="courier new"]max(LY→T
min(LY→Y
T+Ans→O
.5Ans→LB4(1
T-Ans→LB4(2
For(O,1,dim(LX
If T=LY(O:O→T
If Y=LY(O:O→Y
End
DelVar SFor(O,T,dim(LX
If 0>LY(O
Then
For(O,T,1,-1
If 0>LY(O
LX(T)-LX(O→S
End
LX(O)-LX(T→S
End
End
If not(Ans
E99→LM(4
If Ans=E99
Goto A2

I cannot guarantee that this works how it is supposed to,
as you only showed us a fragment of your entire program.

Last edited by Guest on 03 Dec 2005 11:02:07 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 03 Dec 2005 08:52:15 pm    Post subject:

One of your DelVars is missing its argument.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 03 Dec 2005 11:18:54 pm    Post subject:

That's not good. *edits*
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 03 Dec 2005 11:52:14 pm    Post subject:

My first few notes on your code, barring optimizations.

1. Since you're doing a number of possible regressions in your code... you could move the computation of the X list's dimensions to the top, so that you can remove the repeats... and also add a check the the X and Y lists have the same dimensions, I suppose.

2. the comment "if 0 isn't the middle we have problems" I don't understand. Sad Remember that the repeating segment of a sine wave can be

[attachment=394:attachment]

or versions of those flipped about the x-axis in the attached figure.

Now for the major flaw: there is no convergence guarantee to the (locally) best possible set of parameters in this algorithm. This would be akin to a traveler trying to find valleys by climbing every mountain, then trying to see where his descent from the mountain takes him! :(

Truth be told, it surprised me that you managed not to use matrices in the whole of your regression routine! Much can be gained by using the matrix representation of the problem. (Oh, and sorry to the ones who spent their time doing optimizations; no amount of optimizations will help an intrinsically flawed algorithm.)

Do some research and keep the keywords I mentioned earlier in mind, Jacobbus. ;)

thornahawk


Last edited by Guest on 03 Dec 2005 11:55:38 pm; edited 1 time in total
Back to top
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 05 Dec 2005 03:14:54 pm    Post subject:

thornahawk wrote:
2. the comment "if 0 isn't the middle we have problems" I don't understand. Sad Remember that the repeating segment of a sine wave can be

[attachment=394:attachment]

I mean if you have the function: Sin(x)+4 the middle of the waves will not be 0 but 4
Quote:
Do some research and keep the keywords I mentioned earlier in mind, Jacobbus. ;)

thornahawk
[post="63204"]<{POST_SNAPBACK}>[/post]

I'm currently bussy trying to understand the hints google gave me, I'll report when I have some progress

thanks, jacobbus
Back to top
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 06 Feb 2006 01:47:29 pm    Post subject:

Conclusion:

My teacher didn'd find it too bad he gave an 8 out of 10 Smile
Don't think there will ever come a better version, build in functions work right Razz
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 07 Feb 2006 07:31:18 am    Post subject:

Congratulations then, Jacobbus. :)

Newsflash: I've been able to write a TI-BASIC program for general nonlinear regression (i.e., fit to any model function you choose like A*e^(B*X) + C or A/(1 + B*X) not available on the TI 83+). It's still in beta though, so I'm not revealing the code yet unless there's interest among you. I have, however, started testing it against some examples. :)

edit: It might interest some that the program and its one subroutine take up only a bit more than 900 bytes. ;)

thornahawk


Last edited by Guest on 07 Feb 2006 10:44:46 am; edited 1 time in total
Back to top
Jacobbus


Member


Joined: 20 Aug 2005
Posts: 106

Posted: 07 Feb 2006 10:35:26 am    Post subject:

"any model function" Surprised wow thats the real work
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement