Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/02/09 13:36
Read: times


 
Msg Score: -1
 -1 Didn't Search First
#165006 - help is need
i have a c code and i wana 2 change it according keil..dat's mean wht the input i hd provided in c is an array input..can u pls help me out hw cn i provide that array input to the ports..pls help me out..
...insert code here
 


#include <stdio.h>
#include <C:TCINCLUDEstdlib.h>
//#include <C:TCINCLUDEtime.h>
#include <math.h>
//#include <C:TCINCLUDEfcntl.h>
//#include <reg51.h>
#define NUMPAT 4
#define NUMIN 2
#define NUMHID 2
#define NUMOUT 1
#define MAX_RAND 32767.0


#define rando() ((double)rand()/(MAX_RAND+1))
//#define rando() 0.8
int main() {
int i, j, k, p, np, op, ranpat[NUMPAT+1], epoch;
int NumPattern = NUMPAT, NumInput = NUMIN, NumHidden = NUMHID, NumOutput = NUMOUT;
double Input[NUMPAT+1][NUMIN+1] = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 };
double Target[NUMPAT+1][NUMOUT+1] = { 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 };
double SumH[NUMPAT+1][NUMHID+1], WeightIH[NUMIN+1][NUMHID+1], Hidden[NUMPAT+1][NUMHID+1];
double SumO[NUMPAT+1][NUMOUT+1], WeightHO[NUMHID+1][NUMOUT+1], Output[NUMPAT+1][NUMOUT+1];
double DeltaO[NUMOUT+1], SumDOW[NUMHID+1], DeltaH[NUMHID+1];
double DeltaWeightIH[NUMIN+1][NUMHID+1], DeltaWeightHO[NUMHID+1][NUMOUT+1];
double Error, eta = 0.5, alpha = 0.9, smallwt = 0.5;

for( j = 1 ; j <= NumHidden ; j++ ) { /* initialize WeightIH and DeltaWeightIH */
for( i = 0 ; i <= NumInput ; i++ ) {
DeltaWeightIH[i][j] = 0.0 ;
WeightIH[i][j] = 2.0 * ( rando() - 0.5 ) * smallwt ;
}
}
for( k = 1 ; k <= NumOutput ; k ++ ) { /* initialize WeightHO and DeltaWeightHO */
for( j = 0 ; j <= NumHidden ; j++ ) {
DeltaWeightHO[j][k] = 0.0 ;
WeightHO[j][k] = 2.0 * ( rando() - 0.5 ) * smallwt ;
}
}

for( epoch = 0 ; epoch < 10000; epoch++) { /* iterate weight updates */
for( p = 1 ; p <= NumPattern ; p++ ) { /* randomize order of individuals */
ranpat[p] = p ;
}
for( p = 1 ; p <= NumPattern ; p++) {
np = p + rando() * ( NumPattern + 1 - p ) ;
op = ranpat[p] ; ranpat[p] = ranpat[np] ; ranpat[np] = op ;
}
Error = 0.0 ;
for( np = 1 ; np <= NumPattern ; np++ ) { /* repeat for all the training patterns */
p = ranpat[np];
for( j = 1 ; j <= NumHidden ; j++ ) { /* compute hidden unit activations */
SumH[p][j] = WeightIH[0][j] ;
for( i = 1 ; i <= NumInput ; i++ ) {
SumH[p][j] += Input[p][i] * WeightIH[i][j] ;
}
Hidden[p][j] = 1.0/(1.0 + exp(-SumH[p][j])) ;
}
for( k = 1 ; k <= NumOutput ; k++ ) { /* compute output unit activations and errors */
SumO[p][k] = WeightHO[0][k] ;
for( j = 1 ; j <= NumHidden ; j++ ) {
SumO[p][k] += Hidden[p][j] * WeightHO[j][k] ;
}
Output[p][k] = 1.0/(1.0 + exp(-SumO[p][k])) ; /* Sigmoidal Outputs */
/* Output[p][k] = SumO[p][k]; Linear Outputs */
Error += 0.5 * (Target[p][k] - Output[p][k]) * (Target[p][k] - Output[p][k]) ; /* SSE */
/* Error -= ( Target[p][k] * log( Output[p][k] ) + ( 1.0 - Target[p][k] ) * log( 1.0 - Output[p][k] ) ) ; Cross-Entropy Error */
DeltaO[k] = (Target[p][k] - Output[p][k]) * Output[p][k] * (1.0 - Output[p][k]) ; /* Sigmoidal Outputs, SSE */
/* DeltaO[k] = Target[p][k] - Output[p][k]; Sigmoidal Outputs, Cross-Entropy Error */
/* DeltaO[k] = Target[p][k] - Output[p][k]; Linear Outputs, SSE */
}
for( j = 1 ; j <= NumHidden ; j++ ) { /* 'back-propagate' errors to hidden layer */
SumDOW[j] = 0.0 ;
for( k = 1 ; k <= NumOutput ; k++ ) {
SumDOW[j] += WeightHO[j][k] * DeltaO[k] ;
}
DeltaH[j] = SumDOW[j] * Hidden[p][j] * (1.0 - Hidden[p][j]) ;
}
for( j = 1 ; j <= NumHidden ; j++ ) { /* update weights WeightIH */
DeltaWeightIH[0][j] = eta * DeltaH[j] + alpha * DeltaWeightIH[0][j] ;
WeightIH[0][j] += DeltaWeightIH[0][j] ;
for( i = 1 ; i <= NumInput ; i++ ) {
DeltaWeightIH[i][j] = eta * Input[p][i] * DeltaH[j] + alpha * DeltaWeightIH[i][j];
WeightIH[i][j] += DeltaWeightIH[i][j] ;
}
}
for( k = 1 ; k <= NumOutput ; k ++ ) { /* update weights WeightHO */
DeltaWeightHO[0][k] = eta * DeltaO[k] + alpha * DeltaWeightHO[0][k] ;
WeightHO[0][k] += DeltaWeightHO[0][k] ;
for( j = 1 ; j <= NumHidden ; j++ ) {
DeltaWeightHO[j][k] = eta * Hidden[p][j] * DeltaO[k] + alpha * DeltaWeightHO[j][k] ;
WeightHO[j][k] += DeltaWeightHO[j][k] ;
}
}
}
if( epoch%100 == 0 ) printf("nEpoch %-5d : Error = %f", epoch, Error) ;
if( Error < 0.0004 ) break ; /* stop learning when 'near enough' */
}

printf("nnNETWORK DATA - EPOCH %dnnPatt", epoch) ; /* print network outputs */
for( i = 1 ; i <= NumInput ; i++ ) {
printf("Input%-4dt", i) ;
}
for( k = 1 ; k <= NumOutput ; k++ ) {
printf("Target%-4dtOutput%-4dt", k, k) ;
}
for( p = 1 ; p <= NumPattern ; p++ ) {
printf("n%dt", p) ;
for( i = 1 ; i <= NumInput ; i++ ) {
printf("%ft", Input[p][i]) ;
}
for( k = 1 ; k <= NumOutput ; k++ ) {
printf("%ft%ft", Target[p][k], Output[p][k]) ;
}
}
printf("nnGoodbye!nn") ;
return 1 ;
}






List of 36 messages in thread
TopicAuthorDate
help is need            01/01/70 00:00      
   What do you want to solve?            01/01/70 00:00      
   What do you want to do is not clear            01/01/70 00:00      
      clarification of requirements            01/01/70 00:00      
         I am still confused...but here goes            01/01/70 00:00      
            printf writes data on serial port            01/01/70 00:00      
               Not necessarily            01/01/70 00:00      
            reply again.            01/01/70 00:00      
               Some more clarification..try this            01/01/70 00:00      
                  To kiran            01/01/70 00:00      
                     How did you do it?            01/01/70 00:00      
                        explanation            01/01/70 00:00      
                           How to post legible source code            01/01/70 00:00      
                           Please post your actual code.            01/01/70 00:00      
                              abt actual code            01/01/70 00:00      
                                 TC?            01/01/70 00:00      
                                    to andy..            01/01/70 00:00      
                                       Confusing!            01/01/70 00:00      
                                          not to miss            01/01/70 00:00      
                                             Oh no he didn't!            01/01/70 00:00      
                                 I think there is a confusion...            01/01/70 00:00      
                                    reply..            01/01/70 00:00      
                                       Got your point            01/01/70 00:00      
                                       a question and a comment            01/01/70 00:00      
                                          double = double precision float            01/01/70 00:00      
                                             not used it after seeing the effects, thus            01/01/70 00:00      
                                                Good incentive to look at fixed point            01/01/70 00:00      
                           Please explain            01/01/70 00:00      
               But Why Keil??            01/01/70 00:00      
         two dimensional input provided at the ports            01/01/70 00:00      
            simulate the data.            01/01/70 00:00      
               seems that not the real MCU            01/01/70 00:00      
                  to jacksonc ben            01/01/70 00:00      
                     The serial port don't need to know what you transfer            01/01/70 00:00      
   this is obviously not for an embedded app.            01/01/70 00:00      
      Clearly            01/01/70 00:00      

Back to Subject List