Neural Network Experiment Software

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Glasswalker on Sun Apr 08, 2001 6:16 pm

Allrighty... I have finally got my neural networking experiment package to a 99% complete state (it all functions) but there is still something wrong with the neural net... I have done these before on the pc, but I founf it a bit more difficult with the memory limitations, and array structure of pocketc... If anybody would like to help me out on this one, or anyone who has any experience in neural networks I will post the source on this board... (I hope it is not too long to post)

Another thing I am having problems with is the icon directives, I can't seem to get them to work, so if anybody has any pointers on that I would appreciate it as well.

Anyway here is the source:

@cid "NNet";
@name "NeuralNet Experiment";
@dbname "NeuralNet";
@ver "0.1b";
@licon2 "C:\\Windows\\Desktop\\nnl.bmp";
@sicon2 "C:\\Windows\\Desktop\\nns.bmp";

int synapse_weight[2881];
char synapse_used[2881];
char neuron_fired[121];
int neuron_threshold[121];
int neuron_value[121];
int input<img src=icon_smile_8ball.gif border=0 align=middle>, output<img src=icon_smile_8ball.gif border=0 align=middle>, passon<img src=icon_smile_8ball.gif border=0 align=middle>;
int src, dest, layer;
int src_neuron;
int i,x,y,z,a,b;
int x1,x2,y1,y2;
int datain[10],dataout[10];

NN_Eval(int layer)
{
int current_synapse,src_neuron,dest_neuron;
for(dest=1;dest<=24;dest++)
{
dest_neuron = dest + ((layer-1) * 24);
for(src=1;src<=24;src++)
{
src_neuron = src + ((layer-1) * 24);
current_synapse = src + ((dest-1) * 24) + ((layer-1) * 576);
if (neuron_fired[src_neuron]='Y')
{
neuron_value[dest_neuron] = neuron_value[dest_neuron] + synapse_weight[current_synapse];
synapse_used[current_synapse] = 'Y';
}
}
neuron_fired[dest_neuron] = 'N';
if (neuron_value[dest_neuron] >= neuron_threshold[dest_neuron]) neuron_fired[dest_neuron] = 'Y';
}
}

NN_Startup()
{
int current_synapse;
for(layer=1;layer<=5;layer++)
{
for(src=1;src<=24;src++)
{
src_neuron = src + ((layer-1) * 24);
for(dest=1;dest<=24;dest++)
{
current_synapse = src + ((dest-1) * 24) + ((layer-1) * 576);
synapse_weight[current_synapse] = random(15);
synapse_used[current_synapse] = 'N';
}
neuron_fired[src_neuron] = 'N';
neuron_threshold[src_neuron] = 500;
neuron_value[src_neuron] = 0;
}
}
}

NN_Init()
{
int current_synapse;
for(layer=1;layer<=5;layer++)
{
for(src=1;src<=24;src++)
{
src_neuron = src + ((layer-1) * 24);
for(dest=1;dest<=24;dest++)
{
current_synapse = src + ((dest-1) * 24) + ((layer-1) * 576);
synapse_used[current_synapse] = 'N';
}
neuron_fired[src_neuron] = 'N';
neuron_value[src_neuron] = 0;
}
}
}

NN_RunNet()
{
int neuron;
for(i=1;i<=8;i++) passon[i] = input[i];
for(layer=1;layer<=5;layer++)
{
for(i=1;i<=8;i++)
{
neuron = i + ((layer-1) * 24);
neuron_value[neuron] = passon[i];
}
NN_Eval(layer);
for(i=17;i<=24;i++)
{
neuron = i + ((layer-1) * 24);
passon[i] = neuron_value[neuron];
if (neuron_fired[neuron] == 'Y') output[i-16] = 1;
if (neuron_fired[neuron] == 'N') output[i-16] = 0;
text(10,(i-16)*12,neuron_value[neuron]);
text(40,(i-16)*12,neuron_fired[neuron]);
text(70,(i-16)*12,neuron_threshold[neuron]);
text(100,(i-16)*12,synapse_weight[neuron*24]);
}
}

}

NN_Learn(int goodbad)
{
int current_synapse;
if (goodbad == 1)
{
for(layer=1;layer<=5;layer++)
{
for(src=1;src<=24;src++)
{
src_neuron = src + ((layer-1) * 24);
for(dest=1;dest<=24;dest++)
{
current_synapse = src + ((dest-1) * 24) + ((layer-1) * 576);
if (synapse_used[current_synapse] == 'Y')
{
synapse_weight[current_synapse] = synapse_weight[current_synapse] + 1;
}
}
}
}
}
if (goodbad == 2)
{
for(layer=1;layer<=5;layer++)
{
for(src=1;src<=24;src++)
{
src_neuron = src + ((layer-1) * 24);
for(dest=1;dest<=24;dest++)
{
current_synapse = src + ((dest-1) * 24) + ((layer-1) * 576);
if (synapse_used[current_synapse] == 'Y')
{
synapse_weight[current_synapse] = synapse_weight[current_synapse] + 1;
}
}
}
}
}
}

data_button_pushed(int butnum)
{
datain[butnum] = (datain[butnum] - 1) * -1;
if (datain[butnum] == 1) rect(1,10,(butnum*12)+12,20,(butnum*12)+22,3);
if (datain[butnum] == 0)
{
rect(0,10,(butnum*12)+12,20,(butnum*12)+22,3);
frame(1,10,(butnum*12)+12,20,(butnum*12)+22,3);
}
}

do_output_boxes()
{
for(i=1;i<=8;i++)
{
if (dataout[i] == 1) rect(1,140,(i*12)+12,150,(i*12)+22,3);
if (dataout[i] == 0)
{
rect(0,140,(i*12)+12,150,(i*12)+22,3);
frame(1,140,(i*12)+12,150,(i*12)+22,3);
}
}
}

button_start()
{
rect(1,20,135,50,147,3);
NN_Init();
for(i=1;i<=8;i++)
{
input[i] = datain[i];
}
NN_RunNet();
for(i=1;i<=8;i++)
{
dataout[i] = output[i];
}
rect(0,20,135,50,147,3);
frame(1,20,135,50,147,3);
text(22,135,"Start");
text(98,123,dataout[1]);
text(104,123,dataout[2]);
text(110,123,dataout[3]);
text(116,123,dataout[4]);
text(122,123,dataout[5]);
text(128,123,dataout[6]);
text(134,123,dataout[7]);
text(140,123,dataout<img src=icon_smile_8ball.gif border=0 align=middle>);
do_output_boxes();
}

button_save()
{
}

button_good()
{
}

button_bad()
{
}

click_handler(int cx, int cy)
{
if (cx>=10 && cx<=20 && cy>=24 && cy<=34) data_button_pushed(1);
if (cx>=10 && cx<=20 && cy>=36 && cy<=46) data_button_pushed(2);
if (cx>=10 && cx<=20 && cy>=48 && cy<=58) data_button_pushed(3);
if (cx>=10 && cx<=20 && cy>=60 && cy<=70) data_button_pushed(4);
if (cx>=10 && cx<=20 && cy>=72 && cy<=82) data_button_pushed(5);
if (cx>=10 && cx<=20 && cy>=84 && cy<=94) data_button_pushed(6);
if (cx>=10 && cx<=20 && cy>=96 && cy<=106) data_button_pushed(7);
if (cx>=10 && cx<=20 && cy>=108 && cy<=118) data_button_pushed(8);
if (cx>=20 && cx<=49 && cy>=135 && cy<=147) button_start();
if (cx>=50 && cx<=79 && cy>=135 && cy<=147) button_save();
if (cx>=80 && cx<=109 && cy>=135 && cy<=147) button_good();
if (cx>=110 && cx<=140 && cy>=135 && cy<=147) button_bad();
text(20,123,datain[1]);
text(26,123,datain[2]);
text(32,123,datain[3]);
text(38,123,datain[4]);
text(44,123,datain[5]);
text(50,123,datain[6]);
text(56,123,datain[7]);
text(62,123,datain<img src=icon_smile_8ball.gif border=0 align=middle>);
text(98,123,dataout[1]);
text(104,123,dataout[2]);
text(110,123,dataout[3]);
text(116,123,dataout[4]);
text(122,123,dataout[5]);
text(128,123,dataout[6]);
text(134,123,dataout[7]);
text(140,123,dataout<img src=icon_smile_8ball.gif border=0 align=middle>);
}

event_handler()
{
x = event(2);
if (x == 1)
{
}
if (x == 2) click_handler(penx(),peny());
}

init_screen()
{
graph_on();
clearg();
title("Neural Network Experiment");
frame(1,2,20,158,158,3);
frame(1,10,24,20,34,3);
frame(1,10,36,20,46,3);
frame(1,10,48,20,58,3);
frame(1,10,60,20,70,3);
frame(1,10,72,20,82,3);
frame(1,10,84,20,94,3);
frame(1,10,96,20,106,3);
frame(1,10,108,20,118,3);
frame(1,140,24,150,34,3);
frame(1,140,36,150,46,3);
frame(1,140,48,150,58,3);
frame(1,140,60,150,70,3);
frame(1,140,72,150,82,3);
frame(1,140,84,150,94,3);
frame(1,140,96,150,106,3);
frame(1,140,108,150,118,3);
for(a=1;a<=8;a++)
{
for(b=1;b<=8;b++)
{
y1 = (a * 12) + 15;
y2 = (b * 12) + 15;
line(1,20,y1,140,y2);
}
}
text(30,130,"Please Wait, Initializing...");
NN_Startup();
rect(0,10,123,150,150,3);
text(30,130," Finished Initializing... ");
sleep(1000);
rect(0,10,123,150,150,3);
frame(1,10,123,150,150,3);
text(20,123,datain[1]);
text(26,123,datain[2]);
text(32,123,datain[3]);
text(38,123,datain[4]);
text(44,123,datain[5]);
text(50,123,datain[6]);
text(56,123,datain[7]);
text(62,123,datain<img src=icon_smile_8ball.gif border=0 align=middle>);
text(98,123,dataout[1]);
text(104,123,dataout[2]);
text(110,123,dataout[3]);
text(116,123,dataout[4]);
text(122,123,dataout[5]);
text(128,123,dataout[6]);
text(134,123,dataout[7]);
text(140,123,dataout<img src=icon_smile_8ball.gif border=0 align=middle>);
frame(1,20,135,50,147,3);
frame(1,50,135,80,147,3);
frame(1,80,135,110,147,3);
frame(1,110,135,140,147,3);
text(22,135,"Start");
text(52,135,"Save");
text(82,135,"Good");
text(112,135,"Bad");
}

main()
{
init_screen();
while (1)
{
event_handler();
}
exit();
}}
Glasswalker
 
Posts: 47
Joined: Wed Mar 21, 2001 12:18 am
Location: Canada

Postby wossname on Sun Apr 08, 2001 7:27 pm

I'll print out all that, and have a trawl through it. I'll post again tomorrow.

Wossname :)
Wossname :)
Are you <i>local</i>?
wossname
 
Posts: 275
Joined: Sat Feb 24, 2001 7:18 am

Postby mselmeci on Fri Apr 13, 2001 2:52 am

Glasswalker wrote:
> Another thing I am having problems with is the icon directives
> I can't seem to get them to work

> @licon2 "C:\\Windows\\Desktop\\nnl.bmp";
> @sicon2 "C:\\Windows\\Desktop\\nns.bmp";

Very simple.
You have to specify the 1-bit icons in addition to the multiple-bit ones by using
@licon1
and
@sicon1
- Matt Selmeci
mselmeci
 
Posts: 3
Joined: Fri Apr 13, 2001 2:20 am
Location: USA

Postby wossname on Sun Apr 15, 2001 8:54 am

Glasswalker:

Well, none of the buttons actually do anything apart from the start button which repeats the startup process (Why?) by calling NN_Init()again.

I ran the code on my palm and put code to show a message every time one of the values changes in the loops of NN_Init().

It takes such a long time to complete the loops that its not really worth doing it again in the start button (more than 10 minutes at a guess, i didnt time it)

Did you write it on your palm, or using an emulator? Can you do icon'ed apps with PocketC4?

Wossname :)
Wossname :)
Are you <i>local</i>?
wossname
 
Posts: 275
Joined: Sat Feb 24, 2001 7:18 am


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 1 guest

cron