# Programming in C. Help!!!

Discussion in 'OT Technology' started by Chiller, Jun 24, 2004.

1. ### ChillerIs Chillin'

Joined:
Apr 13, 2002
Messages:
591
0
Location:
Lausanne, Switzerland
So I'm in the middle of finals and I don't have enough time to finish this project I'm doing. I need some parts to be reprogrammed. It works and all I just need an alternate main() and step 4 and step 5. Please help!!! It really is on me passing the year or not.

Heres the link for the file:
http://www.yousendit.com/d.aspx?id=92CC42D15BDEFE2FA6FAABECCBAA0298

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
// Semester Project No. 1 //
//............................//

#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>

#define N 12
#define M 1000

float synaptic_weight [N];
int i;
double proba [2][2];
int noise_signal[N];
int output=0;
int no_stimuli[N] = {0,0,0,0,0,0,1,1,1,1,1,1}; //Prenence and absence of an object
int with_stimuli[N] = {0,0,0,1,1,1,0,0,0,1,1,1}; //in the visual field

// Step 1. Activation of the 12 neurons of the retinea according to stimuli S
void input(int S, int retina[])
{
int i;

if(S==1)
for (i = 0; i < N; i++)
retina = with_stimuli;
else
for (i = 0; i < N; i++)
retina = no_stimuli;
}

int noise(int retina[N])

// Step 2. Noise activation of the 12 neurons of the visual cortex

{
float p;

for(i=0; i < N; i++)
{
p = ((float)rand()/(float)RAND_MAX);
if(p>=0.9) // probabilty of 0.1 knowing that the parameters: [0.9,1.0]
{
noise_signal= retina;
}
else
{
if(retina == 1)
noise_signal = 0;

if(retina==0)
noise_signal=1;
}
}
}

// Step 3. Random generation of the synaptic weights
float weight()
{
float p;
for(i=0; i<N; i++)
{
p =((float)rand()/(float)RAND_MAX) * 50 - 25;
synaptic_weight = p;
}
}
int activation(int noise [N], float synaptic_weight [N])

// Calculation of the activation (output) of the receiving neuron

{
float sum = 0;

for (i=0; i<N; i++)
{
sum = sum + synaptic_weight *noise;
}
if ( sum >= 0)
output = 1;
else
output = 0;

return output;
}

// Step 4. Creation of a table of probabilities, comparing a stimulus S with corresponding activation (output)

{
int j,i;

for(j=0;j<1000;j++)
for(j=0;j<2;j++)
for(i=0;i<2;i++)
proba[j]=(proba[j])/1000;
}

inline double xlogx(double x)

// Calculation of the value xlogx

{
if(x==0) return 0.0;
else return x*log(x)/log(2);
}

double mutual_information(int nb_values, double proba[2][2])

// Step 5. Calculation of the mutual information between the stimulus and the activation

{
double h_xy = 0.0, h_x = 0.0, h_y = 0.0;
int i,j;

for(i=0;i< nb_values;i++)
{
double p_x=0.0, p_y=0.0;
for(j=0;j<nb_values;j++)
{
p_x += proba[j];
p_y += proba[j];
h_xy -= xlogx(proba[j]);
}
h_x -= xlogx(p_x);
h_y -= xlogx(p_y);
}
return h_x + h_y + - h_xy;
}

main()
{
srand(time(NULL));
int j,z,k,s;
int tabS[M];
double score = 0;
int S;
float r;
float optimal_synaptic_weight[N];
int retina[N];

FILE *f;
f = fopen("Score List.txt", "w");

// Makes a file that lists the values of the mutual information of 10000 neurons subjected each one to 1000 different stimuli

for(z=0;z<10000;z++)
{
weight();
for(j = 0;j<1000;j++)
{
r = (float)(rand())/(float)(RAND_MAX);
if(r <= 0.5)
S = 0;
else
S=1;
tabS[j] = S;

input(S, retina);
noise(retina);
activation(noise_signal,synaptic_weight);
}

fprintf(f,"%lf \n",mutual_information(2,proba));

if(mutual_information(2,proba) > score) //determination of the best score of mutual information
{
score = mutual_information(2,proba);

for(k=0;k<N;k++)
optimal_synaptic_weight[k]=synaptic_weight[k];
} //determination of the configuration of the synaptic weights relative to the best score
}

printf("best score = %lf \n", score);
printf("synaptic weight :\n");

for(k=0;k<N;k++)
printf("%f ", optimal_synaptic_weight[k]);

printf("\n\n");
fclose(f);
}

2. ### ChillerIs Chillin'

Joined:
Apr 13, 2002
Messages:
591
0
Location:
Lausanne, Switzerland
3. ### ChillerIs Chillin'

Joined:
Apr 13, 2002
Messages:
591
0
Location:
Lausanne, Switzerland

4. ### col_paniccalm like a bombModerator

Joined:
Sep 19, 2003
Messages:
188,160
0
Location:
winter haven, fl
please structure your code before posting requests like that - it makes it a lot easier to read.

5. ### ChillerIs Chillin'

Joined:
Apr 13, 2002
Messages:
591
0
Location:
Lausanne, Switzerland

6. ### CompiledMonkeyNew Member

Joined:
Oct 26, 2001
Messages:
8,528
0
Location:
Richmond, VA
Use the code tags.

7. ### col_paniccalm like a bombModerator

Joined:
Sep 19, 2003
Messages:
188,160
0
Location:
winter haven, fl
dude i was trying to help by advising you how to get help. it is 11pm on the last night of my class and i am completely fried. no way i am sorting through code now. but good luck

8. ### CyberBulletsI reach to the sky, and call out your name. If I c

Joined:
Nov 13, 2001
Messages:
11,865
0
Location:
\$250USD and ill finish it

Joined:
Apr 13, 2002
Messages:
591