cross-over
I made probably the worst decision of my life. I am making a TI-Basic neural network.

Here's what's working:
-Perceptron/single neuron
-Input
-Weights

Here's what's not working:
-Outputs
-More than one neuron (network part of 'neural network')
-My brain
-TI-Basic

I have some code done, but it's really sloppy, and uses a lot of subprograms to keep it organized. (I'm porting from Java, ok?!) In the end, I can just paste the code from the subprograms into the main class (dang OOP is getting to me) program.

I will post progress updates here and potentially code snippets, but I'm going to take a small break from it. I spent way too much time getting to this point.

Also, this is definitely the first time anyone has done this, so I'm pretty proud of my mess code.

I will post code when I can, as I am in a very volatile state. I currently am working on solving some of the problems of the code and do not have a working version.

I expect to be done in a week or two, but I am not sure. [edit: not happening]

Additionally, it is surprisingly fast, with one neuron/layer. The time required per layer should (this is from experience) go up exponentially, though.


Single Perceptron
Code/Download (version 1, I used a super cheatysimple activation function to give me time to re-learn basic calculus.)
[dropbox download here]

Source (optimized, credits down below, may not work 100%):

prgmPERCEPT:

Code:
Ans->|LARGS

0.1->C
If 1=|LARGS(1
seq(2rand-1,I,1,|LARGS(2->|LWTS

If 2=|LARGS(1
Then
   DelVar S
   For(I,3,dim(|LARGS)-1
      S+|LARGS(I)*|LWTS(I-2->S
   End
   1-2(S<0->theta
End

If 3=|LARGS(1
Then
   |LARGS(2->D
   dim(|LARGS)-2->dim(|LA
   DelVar S
   ~1+2(5>2sum(seq(|LARGS(I)*|LWTS(I-2),I,3,dim(|LARGS)-1->S
   D-Ans->E
   For(I,1,dim(|LWTS
      C*E*|LARGS(I+2->|LB(I
      |LWTS(I)+C*E*|LARGS(I+2->|LWTS(I
   End
   {E,S,|LB(1),|LB(2
End

last updated March 30, 2017
prgmTRAIN:

Code:
Menu("RESUME TRAINING?","YES",02,"NO",03
Lbl 03
3->dim(|LZYZYZ
Fill(0,|LZYZYZ
1->|LZYZYZ(1
ClrDraw
{1,2:prgmPERCEPT
Lbl 02

Input "NUMBER OF TRIALS: ",A
|LZYZYZ(2->I%
A->|N
Repeat not(|N
   |N-1->|N
   Text(0,1,|LZYZYZ(1
   Text(12,1,|LZYZYZ(2
   Text(24,1,|LZYZYZ(1)-|LZYZYZ(2
   randInt(~100,100,2->L1
   1-2(L1(1)>L1(2
   augment({3,Ans},L1->|LZ
   prgmPERCEPT
   Ans->L1
   If Ans(1
   Pt-On(|LZ(3),|LZ(4),Black,3
   |LZYZYZ(2)+not(Ans(1->|LZYZYZ(2
   Pt-On(|LZ(3),|LZ(4),Black+L1(2),1
   1+|LZYZYZ(1->|LZYZYZ(1
End

Last updated April 2, 2017

And here's the README file (text, have fun putting this on your calc), for archival purposes (and for help):

Code:
Drag both onto CE/CSE (monochrome may work)

Launch prgmTRAIN

Do not change the name of prgmPERCEPT.

Bugs/Modifications are welcome.

If there is any code that doesn’t run (I’m talking about stuff in prgmPERCEPT), it is there for later versions.

Thanks!

~iPhoenix


Credits for optimizations not included in download, but in source:
mr womp womp
PT_ or P_T (can't tell anymore!)
(potentially you?)


Here's a really good image on perceptrons I found.
It explained a lot (to me, at least, a long time ago)



Here's a video about the speed (and I leaked some stuff)
here!
Here's a great explanation (including psudocode) on what a neural network is, and how to make one.

1 layer (3 neurons) neural network
prgmXOR (solves the classic xor problem)
Takes literally days to run the 20k iterations to be somewhat accurate

Code:
"Change to {0 (instead of {1}) if you do not want to see the nerd stuff :P (may or may not run faster)
{1->|LDEBUG
rand(6->|LN1
rand(3->|LN2
DelVar theta
{0,1,0,1->|LIN1
{0,0,1,1->|LIN2
{0,1,1,0->|LIN3
Repeat 0
   theta+1->theta
   Disp "---","Trial Num: "+toString(theta
   1+remainder(theta-1,4->I
   |LIN1(I->|LINPUT(1
   |LIN2(I->|LINPUT(2
   |LIN3(I->Z
   Disp "Expected Output: "+toString(Z
   For(A,1,2
      Disp "Input "+toString(A)+": "+toString(|LINPUT(A
   End
   Disp "---",""
   DelVar P
   For(A,1,3
      DelVar S
      For(I,0,3,3
         S+|LINPUT(I/3+1)*|LN1(A+I->S
      End
      S->L2(A
      1/(1+e^(~S->|LRES(A
   End
   |LRES*|LN2->|LRES
   
   sum(|LRES->A
   1/(1+e^(~A))->A
   For(N,1,3
      If sum(|LDEBUG:Then
         Disp "Synapse "+toString(N
         Disp "Expected: "+toString(Z),"Result: "+toString(A),"Error: "+toString(Z-A
      End
      Z-A->E
      nDeriv(1/(1+e^(~B)),B,A)*E->C
      If sum(|LDEBUG
      Disp "Change: "+toString(C
      |LN2(N->L3(N
      C+|LN2(N->|LN2(N
      
      If sum(|LDEBUG:Then
         Disp "old:"+toString(L3(N
         Disp "new:"+toString(|LN2(N
         Disp ""
      End
   End
   If sum(|LDEBUG
   Disp "","Input-Hidden:"
   For(A,1,3
      L2(A->O
      C*L3(A)*nDeriv(1/(1+e^(~X)),X,O)->L4(A
      If sum(|LDEBUG
      Disp "Change "+toString(A)+": "+toString(Ans
   End
   For(A,1,3
      |LINPUT(1->L5(A
      |LINPUT(2->L5(A+3
   End
   3->dim(L4
   augment(L4,L4->L4
   L4*L5->L5
   |LN1+L5->|LN1
   If sum(|LDEBUG:Then
      For(A,1,12
         If A<6
         Disp "old: "+toString(|LN1(A)-L5(A
         If A=6
         Disp ""
         If A>6
         Disp "new: "+toString(|LN1(A-6
      End
   End
   Disp "",""
End

End

^^ Code looks weird, just input it into SC3

I literally copied and pasted the code, so there may be a few bugs.
I am also not 100% sure the code works (It should), I need a day or two to run 20 thousand trials Razz

I also will not (as of right now) be explaining what it writes on the homescreen, it's a huge mess.
Whoa. *waits for day when graphing calculators become sentient*
RandomGuest wrote:
Whoa. *waits for day when graphing calculators become sentient*


According to my location, I am spearheading the robotic revolution. With this, my power will expand!!

[insert maniacal laugh here]
_iPhoenix_ wrote:
RandomGuest wrote:
Whoa. *waits for day when graphing calculators become sentient*


According to my location, I am spearheading the robotic revolution. With this, my power will expand!!

[insert maniacal laugh here]

*imagines the body of IPhoenix overrun with little robots*
SAX wrote:
_IPhoenix_: THEY'VE TURNED ON ME!!!!
_iPhoenix_ wrote:
RandomGuest wrote:
Whoa. *waits for day when graphing calculators become sentient*


According to my location, I am spearheading the robotic revolution. With this, my power will expand!!

[insert maniacal laugh here]

s/maniacal/mathematical/
TI-BASIC is intended for simple procedural programming. For a neural network, you will probably need some sort of object-orientedness or pointers. As a result, you will lose a great deal of performance when you start adding multiple neurons, because the overhead of recalling information from lists will get in the way.
oldmud0 wrote:
TI-BASIC is intended for simple procedural programming. For a neural network, you will probably need some sort of object-orientedness or pointers. As a result, you will lose a great deal of performance when you start adding multiple neurons, because the overhead of recalling information from lists will get in the way.


Yep! That's why I've called it the worst decision of my life.

I might keep the subprograms as I can do things like

Code:
{1,2,3,rand:prgmPERCEPT

which adds time but makes it easier to see.

I have also chosen a task which will only require ~10 neutrons in 2 hidden layers. I'm going to keep it secret, but it's been done before, first in js by someone else, then in Java by me and then hopefully in TI-BASIC, also by me!

RandomGuest wrote:
*imagines the body of iPhoenix overrun with little robots*
SAX wrote:
_iPhoenix_: THEY'VE TURNED ON ME!!!!


Do you have any proof I'm not a LSTM?

jk. I'm only a RNN running on a supercomputer?
You could try linking multiple calculators, each being a separate sensory organ. That's how [insert evolution/intelligent design/other] does it, and quite successfully I might add. This will make things a lot quicker by allow simultaneous processing of different inputs. It does cost money though.
high waiting times is better than cost, in my book. Unless the waiting time is longer than my life span/battery life.
I'm assuming that the calc will be running full-blast during the eternal processing time, and that does wonders for battery life. Also, they say time is money too. Besides, if I take forever to process my own movement, my brain will completely ignore the red light dead ahead.
I think this is going GREAT _iPhoenix_! You should take it one step at a time (instead of listening to naysayers like prgmTrouble Very Happy )
I imagine its rather hard to port classes to a language that doesn't even support real functions. Razz Good work on this! Smile
calcnerd_CEP_D wrote:
I imagine its rather hard to port classes to a language that doesn't even support real functions. Razz Good work on this! Smile


Yeah, it's been a struggle.

Also, does anyone know how to fix this?
Whenever I call a subprogram in a loop, it never respects the loop and simply ends, without even running the subprogram.
I theoretically could directly put the code in the loop, but that gets messy real quickly.

Additionally, this is a great book and I hereby recommend it to everyone.

Like seriously. It's really good. (at least the last few chapters are, I didn't really want to learn "the basics")
Ooh! I have a thing for this! I will find it somewhere...
I think it was from JWinslow or something
I'd do a If-Then with a goto to simulate a loop.
prgmTrouble wrote:
I'd do a If-Then with a goto to simulate a loop.

⚠ Memory leak! ⚠

Here's a question for ya'll.

Is a simple If-Goto (no then) a leak?

[edit] PT says no. Case closed. [/edit]

(that should be a real tag!)
If-then is for a condition, where I would set a variable to a certain number.
I would then do an if (no then) and a goto.

[edit]Got advanced newbie, woo[/edit]
Credits to JWinslow for this:

Pseudocode:

Code:

SUBROUTINE() {
  CODE GOES HERE
  Return
}


TI-BASIC:


Code:

Lbl SB
CODE GOES HERE
End


(placed in such a way so that it is never run by accident)

Pseudocode:


Code:

Call SUBROUTINE();


TI-BASIC:


Code:

For(Z,-1,0
If Z
Goto SB
End


(make sure Z isn't used inside of the subroutine!)
If you have a subroutine, it might be possible to use the function variables u,v and w, which could save you tons of bytes, but this subroutine would have to be something like evaluating a function. Essentially, I think a rule that would work is: 'If it could be written out as a one-liner on the homescreen and it would work, then you can put that in a function variable.'
One thing's for sure, you don't want to have a looping memory leak (A memory leak that does not happen often, or just once is acceptable, but not a loop, that's just garbage code).
What you've made is quite an interesting program, but the real hurdle is getting it to speed up to a descent speed.
As for the If-Then, as you already know, it only causes a memory leak if you have a Then and an End in there. The IS>() and DS<() commands will not cause a memory leak either if you use a goto directly after them.
I'm currently doing something like this

Code:
{1,2,3,4:prgmPERCEPT


prgmPERCEPT:

Code:
Ans->L1
If 1=L1(1
Then
<snip>
Else
If 2=L1(1
Then
<snip>
End
End
  
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
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement