/* ************************************************************************* * * * THE RANDOM NUMBER GENERATOR * * * ************************************************************************* */ #include #include #include #include "cortex.h" float HIDDEN_weight [HUNIT][ITUPLE]; /* Hunit's weights */ float HIDDEN_threshold [HUNIT]; /* Hunit's thresholds */ int Chkix [ROW*COLUMN]; /* ( fully connection for state units ) */ int Multi_itupling [ROW*COLUMN]; float OUTPUT_weight [CATEGORY][HUNIT]; /* Ounit's weights */ float OUTPUT_threshold [CATEGORY]; /* Ounit's thresholds */ float CATEGORY_activity [CATEGORY][CATEGORY]; /* Category activity */ void Random_of_hidden_weight(); /* Function */ void Random_of_hidden_threshold(); /* Function */ void Random_of_output_weight(); /* Function */ void Random_of_output_threshold(); /* Function */ void Category_Degit(); /* Function */ int Check_ix(); /* Function */ void Storage_of_outputs(); /* Function */ FILE *stream1; /* Output files */ FILE *stream2; FILE *stream3; FILE *stream4; FILE *stream5; main() { /* Creat and Open output files */ stream1 = fopen ( "project/hidden.iwt", "w" ); stream2 = fopen ( "project/hidden.ith", "w" ); stream3 = fopen ( "project/output.iwt", "w" ); stream4 = fopen ( "project/output.ith", "w" ); stream5 = fopen ( "project/category.act", "w" ); /* Generate the random numbers */ Random_of_hidden_weight ( HIDDEN_weight ); Random_of_hidden_threshold ( HIDDEN_threshold ); Random_of_output_weight ( OUTPUT_weight ); Random_of_output_threshold ( OUTPUT_threshold ); Category_Degit ( CATEGORY_activity ); /* Print the random numbers onto the output files */ Storage_of_outputs(); /* Close output files and Terminate the process */ /* fcloseall(); */ exit ( 0 ); } /* main */ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + FUNCTIONS + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* Generate the random weights of hidden units */ void Random_of_hidden_weight( HIDDEN ) float HIDDEN [HUNIT][ITUPLE]; { float x; /* Random number */ long now; /* Present time */ long timer; /* Delay time */ register int i; register int j; for ( timer = TIME_DELAY; timer > 0; timer--) ; srand ( time ( &now ) % 37 ); for ( i = 0; i < HUNIT; i++) for ( j = 0; j < (ITUPLE); j++) { x = 2.0 * rand() / 32767.0 - 1.0; /* Between -1.0 and 1.0 */ HIDDEN [i][j] = x; } return; } /* Random_of_hidden_weight */ /* Generate the random thresholds of hidden units */ void Random_of_hidden_threshold ( HTHRESHOLD ) float HTHRESHOLD [HUNIT]; { float x; /* Random number */ long now; /* Present time */ long timer; /* Delay time */ register int i; for ( timer = TIME_DELAY; timer > 0; timer--) ; srand ( time ( &now ) % 37 ); for ( i = 0; i < HUNIT; i++) { x = 2.0 * rand() / 32767.0 - 1.0; /* Between -1.0 and 1.0 */ HTHRESHOLD [i] = x; } return; } /* Random_of_hidden_threshold */ /* Generate the random weights of output units */ void Random_of_output_weight( OUTPUT ) float OUTPUT [CATEGORY][HUNIT]; { float x; /* Random number */ long now; /* Present time */ long timer; /* Delay time */ register int j; register int k; for ( timer = TIME_DELAY; timer > 0; timer--) ; srand ( time ( &now ) % 37 ); for ( j = 0; j < CATEGORY; j++) for ( k = 0; k < HUNIT; k++) { x = 2.0 * rand() / 32767.0 - 1.0; /* Between -1.0 and 1.0 */ OUTPUT [j][k] = x; } return; } /* Random_of_output_weight */ /* Generate the random thresholds of output units */ void Random_of_output_threshold ( OTHRESHOLD ) float OTHRESHOLD [CATEGORY]; { float x; /* Random number */ long now; /* Present time */ long timer; /* Delay time */ register int j; for ( timer = TIME_DELAY; timer > 0; timer--) ; srand ( time ( &now ) % 37 ); for ( j = 0; j < CATEGORY; j++) { x = 2.0 * rand() / 32767.0 - 1.0; /* Between -1.0 and 1.0 */ OTHRESHOLD [j] = x; } return; } /* Random_of_output_threshold */ /* Generate the activity patterns of categories of Degit images */ void Category_Degit ( DgCATEGORY ) float DgCATEGORY [CATEGORY][CATEGORY]; { register int i; register int j; for ( i = 0; i < CATEGORY; i++) { for ( j = 0; j < CATEGORY; j++) { if ( i == j ) DgCATEGORY [i][j] = 1.0; else DgCATEGORY [i][j] = 0.0; } } return; } /* Category_Degit */ /* Print the random numbers onto the output files */ void Storage_of_outputs() { register int i; register int j; register int k; for ( i = 0; i < HUNIT; i++) { fprintf ( stream2, "%10.6f", HIDDEN_threshold [i] ); if( i == HUNIT - 1 ) fprintf ( stream2, "\n" ); for ( j = 0; j < ITUPLE; j++) { fprintf ( stream1, "%10.6f", HIDDEN_weight [i][j] ); if( j == (ITUPLE-1) ) fprintf ( stream1, "\n" ); } } for ( j = 0; j < CATEGORY; j++) { fprintf ( stream4, "%10.6f", OUTPUT_threshold [j] ); if( j == CATEGORY - 1 ) fprintf ( stream4, "\n" ); for ( k = 0; k < HUNIT; k++) { fprintf ( stream3, "%10.6f", OUTPUT_weight [j][k] ); if( k == HUNIT - 1 ) fprintf ( stream3, "\n" ); } } for ( i = 0; i < CATEGORY; i++) for ( j = 0; j < CATEGORY; j++) { fprintf ( stream5, "%10.6f", CATEGORY_activity [i][j] ); if( j == CATEGORY - 1 ) fprintf ( stream5, "\n" ); } return; } /* Storage_of_outputs */ /* END */