Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Last update: 05.10.2016, 16.00
- #include "CODE.cc"
- #include "Classifier_CODE/runner.cc"
- #include "C:\genn-team-genn-8cacb78\lib\include\hr_time.cpp"
- #include "Eigen/Dense"
- #include <string>
- #define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
- #define MAX_LENGTH_STRING 20
- #define AUTOFEEDBACK_REMOVAL 0.001
- #define SIM_TIME 2000
- #define STOP_TIME 800
- using namespace Eigen;
- typedef struct coordinatesItem{
- int x;
- int y;
- } t_coordinates;
- typedef struct arrayItem{
- int population;
- int indexInPopulation;
- t_coordinates coordinates;
- } t_extendedArray;
- typedef struct rowDataset{
- double * features;
- char * Class;
- } t_row;
- // Prototypes
- void resetNeuronInputLayer(void);
- void LSNconnectivitySetup(t_extendedArray * array, int DIM_EXC, int DIM_INH);
- void associateExtendedArrayToGrid(int * grid, int rows, int cols, t_extendedArray * array);
- t_extendedArray * getExtendedArray(int DIM_EXC, int DIM_INH);
- t_extendedArray getItemFromExtendedArray(t_extendedArray * array, int indexNeuron, int length);
- int * getGrid(int rows, int cols);
- int * scrambleGrid(int * grid, int rows, int cols);
- int getRows(void);
- double * getCurrents(t_row row);
- double getDistance(t_coordinates coordinates_neuron_i, t_coordinates coordinates_neuron_j);
- double getK(t_extendedArray neuron_i, t_extendedArray neuron_j);
- double getC(t_extendedArray neuron_i, t_extendedArray neuron_j);
- double getP(t_extendedArray neuron_i, t_extendedArray neuron_j);
- double getMax(t_row row);
- double getMin(t_row row);
- FILE * IrisDataset = fopen("iris.dat","r");
- // Files for tracing the information about Input Layer
- ofstream I_InputLayer("I_InputLayer.dat");
- // Files for tracing the information about LSN
- ofstream V_LSN_EXC("V_LSN_EXC.dat");
- ofstream V_LSN_INH("V_LSN_INH.dat");
- ofstream I_LSN_EXC("I_LSN_EXC.dat"); // Synaptic current, because no external current is applied!
- ofstream I_LSN_INH("I_LSN_INH.dat"); // Synaptic current, because no external current is applied!
- ofstream K("K.dat");
- ofstream C("C.dat");
- ofstream P("P.dat");
- ofstream Grid("Grid.dat");
- ofstream W_LSN_EXC_EXC("W_LSN_EXC_EXC.dat");
- ofstream W_LSN_EXC_INH("W_LSN_EXC_INH.dat");
- ofstream W_LSN_INH_EXC("W_LSN_INH_EXC.dat");
- ofstream W_LSN_INH_INH("W_LSN_INH_INH.dat");
- // Files for tracing the information about SNs
- ofstream V_SNs("V_SNs.dat");
- ofstream ISyn_SNs("ISyn_SNs.dat");
- // Files for tracing the information about connections from Input Layer to LSN
- ofstream W_INPUT_LSN_EXC("W_INPUT_LSN_EXC.dat");
- ofstream W_INPUT_LSN_INH("W_INPUT_LSN_INH.dat");
- // Files for tracing the information about connections from LSN to SNs
- ofstream W_LSN_EXC_SNs("W_LSN_EXC_SNs.dat");
- ofstream W_LSN_INH_SNs("W_LSN_INH_SNs.dat");
- // Matrices
- ofstream VectorT_SLOW("T_SLOW.dat");
- ofstream VectorT_FAST("T_FAST.dat");
- ofstream MatrixZ("Z.dat");
- ofstream MatrixW("W.dat");
- int main(){
- const int NO_PATTERNS = getRows();
- const int T = (int)(SIM_TIME/DT);
- const int D = (int)(N_NEURONS_LSN*NO_PATTERNS);
- VectorXd T_SLOW(T);
- VectorXd T_FAST((T);
- MatrixXd Z(T,D);
- VectorXd W0(D);
- VectorXd W1(D);
- VectorXd W2(D);
- t_extendedArray * extendedArray = getExtendedArray(DIM_EXC,DIM_INH);
- CStopWatch timer;
- timer.startTimer();
- allocateMem();
- initialize();
- printf("--------------\n\n");
- printf("CLASSIFICATION\n");
- printf("--------------\n\n");
- printf("About the simulation\n");
- printf("- Number of patterns = %d\n",NO_PATTERNS);
- printf("- Input layer dimensions = %d\n",NEURONS_PER_PATTERN);
- printf("- LSN dimensions = %d-by-%d\n",R_LSN,C_LSN);
- printf("- LSN excitatory subpopulation size = %d\n",DIM_EXC);
- printf("- LSN inhibitory subpopulation size = %d\n",DIM_INH);
- printf("------------------------------------------------\n\n");
- // Dataset structure generation
- t_row * Dataset = (t_row *)malloc(NO_PATTERNS*sizeof(t_row));
- for(int indexPattern = 0; indexPattern < NO_PATTERNS; indexPattern++){
- Dataset[indexPattern].features = (double *)malloc(NEURONS_PER_PATTERN * sizeof(double));
- Dataset[indexPattern].Class = (char *)malloc(MAX_LENGTH_STRING * sizeof(char));
- }
- // ---
- // Target signals generation
- const double timeConstant_fast = 800.0; // ms
- const double timeConstant_slow = 8.0; // ms
- for(double t = 0.0; t < SIM_TIME; t += DT){
- T_SLOW((int)(t/DT)) = 1 - exp((-t)/timeConstant_slow);
- T_FAST((int)(t/DT)) = 1 - exp((-t)/timeConstant_fast);
- }
- // ---
- // LSN setup
- printf("LSN neurons spatial organization:\n\n");
- int * grid = getGrid(R_LSN,C_LSN);
- for(int row = 0; row < R_LSN; row++){
- for(int column = 0; column < C_LSN; column++){
- Grid << grid[row * C_LSN + column] << "\t";
- printf("%d\t",grid[row * C_LSN + column]);
- }
- printf("\n");
- Grid << endl;
- }
- associateExtendedArrayToGrid(grid,R_LSN,C_LSN,extendedArray);
- LSNconnectivitySetup(extendedArray,DIM_EXC,DIM_INH);
- free(grid);
- grid = NULL;
- printf("LSN configuration = COMPLETE\n");
- // ---
- // Dataset acquisition
- const char * delimiter = "-";
- char * token;
- if(IrisDataset != NULL){
- char row[150];
- int indexPattern = 0;
- int indexFeature;
- while(fgets(row,sizeof(row),IrisDataset) != NULL){
- indexFeature = 0;
- token = strtok(row,delimiter);
- while(token != NULL){
- if(indexFeature < NEURONS_PER_PATTERN) Dataset[indexPattern].features[indexFeature] = atof(token);
- else strcpy(Dataset[indexPattern].Class,token); // This string comprises carriage return too.
- token = strtok(NULL,delimiter);
- indexFeature++;
- }
- }
- printf("Iris dataset acquisition = COMPLETE\n");
- }
- // ---
- // Learning phase
- printf("\n--- LEARNING PHASE ---\n");
- for(int indexPattern = 0; indexPattern < NO_PATTERNS; indexPattern++){
- printf("\tSimulation no. %d ---\n",indexPattern + 1);
- resetNeuronInputLayer();
- printf("\tReset of all state variables of Input Layer = COMPLETE\n");
- double * Iext_Amplitudes = getCurrents(Dataset[indexPattern]);
- printf("\tExecution...\n");
- for(double t = 0.0; t <= SIM_TIME; t += DT){
- I_InputLayer << indexPattern << "\t" << t << "\t";
- // Applying currents
- for(int indexNeuron = 0; indexNeuron < NEURONS_PER_PATTERN; indexNeuron++){
- IextINPUT[indexNeuron] = Iext_Amplitudes[indexNeuron];
- I_InputLayer << Iext_Amplitudes[indexNeuron] << "\t";
- }
- I_InputLayer << endl;
- pushINPUTStateToDevice();
- // ---
- // Execution
- stepTimeGPU(t);
- // ---
- // Data acquisition from memory
- pullINPUTStateFromDevice();
- pullLSN_EXCStateFromDevice();
- pullLSN_INHStateFromDevice();
- pullLSN_EXC_EXCStateFromDevice();
- pullLSN_EXC_INHStateFromDevice();
- pullLSN_INH_EXCStateFromDevice();
- pullLSN_INH_INHStateFromDevice();
- pullSNStateFromDevice();
- pullINPUT_LSN_EXCStateFromDevice();
- pullINPUT_LSN_INHStateFromDevice();
- pullLSN_INH_SNsStateFromDevice();
- pullLSN_EXC_SNsStateFromDevice();
- // ---
- // Saving LSN data
- V_LSN_EXC << indexPattern << t << "\t";
- I_LSN_EXC << indexPattern << t << "\t";
- for(int indexNeuron = 0; indexNeuron < DIM_EXC; indexNeuron++){
- V_LSN_EXC << VLSN_EXC[indexNeuron] << "\t";
- I_LSN_EXC << yLSN_EXC[indexNeuron] << "\t";
- }
- V_LSN_EXC << endl;
- I_LSN_EXC << endl;
- V_LSN_INH << indexPattern << "\t" << t << "\t";
- I_LSN_INH << indexPattern << "\t" << t << "\t";
- for(int indexNeuron = 0; indexNeuron < DIM_INH; indexNeuron++){
- V_LSN_INH << VLSN_INH[indexNeuron] << "\t";
- I_LSN_INH << yLSN_INH[indexNeuron] << "\t";
- }
- V_LSN_INH << endl;
- I_LSN_INH << endl;
- for(int indexNeuronPre = 0; indexNeuronPre < N_NEURONS_LSN; indexNeuronPre++){
- for(int indexNeuronPost = 0; indexNeuronPost < N_NEURONS_LSN; indexNeuronPost++){
- int indexSynapse;
- t_extendedArray pre = getItemFromExtendedArray(extendedArray,indexNeuronPre,DIM_EXC + DIM_INH);
- t_extendedArray post = getItemFromExtendedArray(extendedArray,indexNeuronPost,DIM_EXC + DIM_INH);
- if((pre.population == 0) && (post.population == 0)){
- indexSynapse = pre.indexInPopulation * DIM_EXC + post.indexInPopulation;
- W_LSN_EXC_EXC << indexPattern << "\t" << t << "\t" << pre.indexInPopulation << "\t" << post.indexInPopulation << "\t" << wLSN_EXC_EXC[indexSynapse] << endl;
- }
- else{
- if((pre.population == 0) && (post.population == 1)){
- indexSynapse = pre.indexInPopulation * DIM_INH + post.indexInPopulation;
- W_LSN_EXC_INH << indexPattern << "\t" << t << "\t" << pre.indexInPopulation << "\t" << post.indexInPopulation << "\t" << wLSN_EXC_INH[indexSynapse] << endl;
- }
- else{
- if((pre.population == 1) && (post.population == 0)){
- indexSynapse = pre.indexInPopulation * DIM_EXC + post.indexInPopulation;
- W_LSN_INH_EXC << indexPattern << "\t" << t << "\t" << pre.indexInPopulation << "\t" << post.indexInPopulation << "\t" << wLSN_INH_EXC[indexSynapse] << endl;
- }
- else{
- indexSynapse = pre.indexInPopulation * DIM_INH + post.indexInPopulation;
- W_LSN_INH_INH << indexPattern << "\t" << t << "\t" << pre.indexInPopulation << "\t" << post.indexInPopulation << "\t" << wLSN_INH_INH[indexSynapse] << endl;
- }
- }
- }
- }
- }
- // ---
- // Saving SNs data
- V_SNs << indexPattern << "\t" << t << "\t";
- ISyn_SNs << indexPattern << "\t" << t << "\t";
- for(int indexNeuron = 0; indexNeuron < N_CLASSES; indexNeuron++){
- V_SNs << VSN[indexNeuron] << "\t";
- ISyn_SNs << ISynSN[indexNeuron] << "\t";
- }
- V_SNs << endl;
- ISyn_SNs << endl;
- // ---
- // Saving weights from INPUT to LSN_EXC/LSN_INH
- for(int indexPre = 0; indexPre < NEURONS_PER_PATTERN; indexPre++){
- for(int indexPost = 0; indexPost < N_NEURONS_LSN; indexPost++){
- int idPost = extendedArray[indexPost].indexInPopulation;
- if(extendedArray[indexPost].population == 0) W_INPUT_LSN_EXC << indexPattern << "\t" << t << "\t" << indexPre << "\t" << idPost << "\t" << wINPUT_LSN_EXC[indexPre * DIM_EXC + idPost] << endl;
- else W_INPUT_LSN_EXC << indexPattern << "\t" << t << "\t" << indexPre << "\t" << idPost << "\t" << wINPUT_LSN_INH[indexPre * DIM_INH + idPost] << endl;
- }
- }
- // ---
- // Saving weights from LSN_EXC/LSN_INH to SNs
- for(int indexPre = 0; indexPre < N_NEURONS_LSN; indexPre++){
- int idPre = extendedArray[indexPre].indexInPopulation;
- for(int indexPost = 0; indexPost < N_CLASSES; indexPost++){
- if(extendedArray[indexPre].population == 0) W_LSN_EXC_SNs << indexPattern << "\t" << t << "\t" << idPre << "\t" << indexPost << "\t" << wLSN_EXC_SNs[idPre * N_CLASSES + indexPost] << endl;
- else W_LSN_INH_SNs << indexPattern << "\t" << t << "\t" << idPre << "\t" << indexPost << "\t" << wLSN_INH_SNs[idPre * N_CLASSES + indexPost] << endl;
- }
- }
- // ---
- // Definition of Z for the given pattern
- for(int indexNeuron = 0; indexNeuron < N_NEURONS_LSN; indexNeuron++) Z((int)t/DT,indexPattern * N_NEURONS_LSN + indexNeuron) = (extendedArray[indexNeuron].population == 0) ? jLSN_EXC_SNs[indexNeuron * N_CLASSES] : jLSN_INH_SNs[indexNeuron * N_CLASSES];
- // ---
- }
- printf(" COMPLETE\n");
- }
- // Matrix computations and saving on file
- MatrixXd Pseudoinverse((int)(N_NEURONS_LSN*NO_PATTERNS),(int)(SIM_TIME/DT));
- Pseudoinverse = (Z.transpose()*Z).inverse()*Z.transpose();
- VectorT_FAST << T_FAST;
- VectorT_SLOW << T_SLOW;
- MatrixZ << Z;
- const char * C1 = "Iris-setosa\n";
- const char * C2 = "Iris-versicolor\n";
- const char * C3 = "Iris-virginica\n";
- char * Class;
- for(int indexPattern = 0; indexPattern < NO_PATTERNS; indexPattern++){
- strcpy(Class,Dataset[indexPattern].Class);
- if(strcmp(Class,C1) == 0){
- W0 = Pseudoinverse * T_FAST;
- W1 = Pseudoinverse * T_SLOW;
- W2 = Pseudoinverse * T_SLOW;
- }
- else{
- if(strcmp(Class,C2) == 0){
- W0 = Pseudoinverse * T_SLOW;
- W1 = Pseudoinverse * T_FAST;
- W2 = Pseudoinverse * T_SLOW;
- }
- else{
- if(strcmp(Class,C3) == 0){
- W0 = Pseudoinverse * T_SLOW;
- W1 = Pseudoinverse * T_SLOW;
- W2 = Pseudoinverse * T_FAST;
- }
- }
- }
- }
- // ---
- printf("\nLEARNING PHASE COMPLETED\n\n");
- // ---
- // ---
- // printf("TESTING PHASE IS STARTED\n\n");
- // Closing files
- IrisDataset.fclose();
- I_InputLayer.close();
- V_LSN_EXC.close();
- V_LSN_INH.close();
- I_LSN_EXC.close();
- I_LSN_INH.close();
- K.close();
- C.close();
- P.close();
- Grid.close();
- W_LSN_EXC_EXC.close();
- W_LSN_EXC_INH.close();
- W_LSN_INH_EXC.close();
- W_LSN_INH_INH.close();
- V_SNs.close();
- ISyn_SNs.close();
- W_INPUT_LSN_EXC.close();
- W_INPUT_LSN_INH.close();
- W_LSN_EXC_SNs.close();
- W_LSN_INH_SNs.close();
- VectorT_SLOW.close();
- VectorT_FAST.close();
- MatrixZ.close();
- MatrixW.close();
- timer.stopTimer();
- return EXIT_SUCCESS;
- }
- // ---------------------- associateExtendedArrayToGrid -----------------------------
- void associateExtendedArrayToGrid(int * grid, int rows, int cols, t_extendedArray * array){
- int index;
- for(int row = 0; row < rows; row++){
- for(int col = 0; col < cols; col++){
- index = grid[row * cols + col];
- array[index].coordinates.x = row;
- array[index].coordinates.y = col;
- }
- }
- }
- // ---------------------------- LSNconnectivitySetup -------------------------------
- void LSNconnectivitySetup(t_extendedArray * array, int DIM_EXC, int DIM_INH){
- int dim = DIM_EXC + DIM_INH;
- int indexSynapse;
- double p;
- double randomNumber;
- double synapticWeight;
- t_extendedArray neuron_i;
- t_extendedArray neuron_j;
- srand(time(NULL));
- for(int index_i = 0; index_i < dim; index_i++){
- neuron_i = getItemFromExtendedArray(array,dim,index_i);
- for(int index_j = 0; index_j < dim; index_j++){
- if(index_i != index_j){
- neuron_j = getItemFromExtendedArray(array,dim,index_j);
- K << neuron_i.indexInPopulation << "\t" << neuron_j.indexInPopulation << "\t" << neuron_i.population << "\t" << neuron_j.population << "\t";
- C << neuron_i.indexInPopulation << "\t" << neuron_j.indexInPopulation << "\t" << neuron_i.population << "\t" << neuron_j.population << "\t";
- P << neuron_i.indexInPopulation << "\t" << neuron_j.indexInPopulation << "\t" << neuron_i.population << "\t" << neuron_j.population << "\t";
- p = getP(neuron_i,neuron_j);
- P << p << endl;
- randomNumber = (double)rand() / (double)RAND_MAX;
- if(randomNumber >= p) synapticWeight = AUTOFEEDBACK_REMOVAL;
- else synapticWeight = (neuron_i.population == 0) ? 10.0 : -10.0;
- if((neuron_i.population == 0) && (neuron_j.population == 0)){
- // Pre-synaptic neuron is excitatory, post-synaptic neuron is excitatory
- indexSynapse = neuron_i.indexInPopulation * DIM_EXC + neuron_j.indexInPopulation;
- wLSN_EXC_EXC[indexSynapse] = synapticWeight;
- pushLSN_EXC_EXCToDevice();
- }
- else{
- if((neuron_i.population == 0) && (neuron_j.population == 1)){
- // Pre-synaptic neuron is excitatory, post-synaptic neuron is inhibitory
- indexSynapse = neuron_i.indexInPopulation * DIM_INH + neuron_j.indexInPopulation;
- wLSN_EXC_INH[indexSynapse] = synapticWeight;
- pushLSN_EXC_INHToDevice();
- }
- else{
- if((neuron_i.population == 1) && (neuron_j.population == 0)){
- // Pre-synaptic neuron is inhibitory, post-synaptic neuron is excitatory
- indexSynapse = neuron_i.indexInPopulation * DIM_EXC + neuron_j.indexInPopulation;
- wLSN_INH_EXC[indexSynapse] = synapticWeight;
- pushLSN_INH_EXCToDevice();
- }
- else{
- // Pre-synaptic neuron is inhibitory, post-synaptic neuron is inhibitory
- indexSynapse = neuron_i.indexInPopulation * DIM_INH + neuron_j.indexInPopulation;
- wLSN_INH_INH[indexSynapse] = synapticWeight;
- pushLSN_INH_INHToDevice();
- }
- }
- }
- }
- else{
- // Autofeedback removal
- if(neuron_i.population == 0){
- wLSN_EXC_EXC[neuron_i.indexInPopulation * (int)(1 + DIM_EXC)] = AUTOFEEDBACK_REMOVAL;
- pushLSN_EXC_EXCToDevice();
- }
- else{
- wLSN_INH_INH[neuron_i.indexInPopulation * (int)(1 + DIM_INH)] = AUTOFEEDBACK_REMOVAL;
- pushLSN_INH_INHToDevice();
- }
- }
- }
- }
- }
- // -------------------------- resetNeuronInputLayer ------------------------------
- void resetNeuronInputLayer(void){
- //
- }
- // ------------------------------- getExtendedArray --------------------------------
- t_extendedArray * getExtendedArray(int DIM_EXC, int DIM_INH){
- int index;
- int dim = DIM_EXC + DIM_INH;
- t_extendedArray * array = (t_extendedArray *)malloc(dim * sizeof(t_extendedArray));
- if (!array){
- perror("getExtendedArray malloc : FAILED\n\n");
- exit(ENOMEM);
- }
- for(index = 0; index < DIM_EXC; index++){
- array[index].population = 0;
- array[index].indexInPopulation = index;
- }
- while(index < dim){
- array[index].population = 1;
- array[index].indexInPopulation = index - DIM_EXC;
- index++;
- }
- return array;
- }
- // ----------------------------------- getGrid -------------------------------------
- int * getGrid(int rows, int cols){
- int * grid = (int *)malloc(rows * cols * sizeof(int));
- if (!grid){
- perror("getGrid malloc : FAILED\n\n");
- exit(ENOMEM);
- }
- return scrambleGrid(grid,rows,cols);
- }
- // -------------------------------- scrambleGrid -----------------------------------
- int * scrambleGrid(int * grid, int rows, int cols){
- int * checkDuplicates = (int *)malloc(rows * cols * 2 * sizeof(int));
- if (!checkDuplicates){
- perror("scrambledGrid malloc : FAILED\n\n");
- exit(ENOMEM);
- }
- int row;
- int column;
- int randomNumber;
- // Initializes matrix checkDuplicates
- for(row = 0; row < cols * rows; row++){
- checkDuplicates[2 * row] = row;
- checkDuplicates[2 * row + 1] = 0;
- }
- // Generates grid
- srand(time(NULL));
- for(row = 0; row < rows; row++){
- for(column = 0; column < cols; column++){
- do{
- randomNumber = rand() % (cols * rows);
- } while(checkDuplicates[2 * randomNumber + 1] == 1);
- checkDuplicates[2 * randomNumber + 1] = 1;
- grid[row * cols + column] = randomNumber;
- }
- }
- free(checkDuplicates);
- checkDuplicates = NULL;
- return grid;
- }
- // -------------------------------- getRows -----------------------------------
- int getRows(void){
- int ch;
- int n = 0;
- do{
- ch = fgetc(IrisDataset);
- if(ch == '\n') n++;
- } while (ch != EOF);
- if(ch != '\n' && n != 0) n++;
- return n;
- }
- // -------------------------------------------- getCurrents ---------------------------------------------------
- double * getCurrents(t_row row){
- const double Iext_Minimum = 10;
- double * currents = (double *)malloc(NEURONS_PER_PATTERN * sizeof(double));
- double max = getMax(row);
- double min = getMin(row);
- for(int i = 0; i < NEURONS_PER_PATTERN; i++) currents[i] = Iext_Minimum * (0.5 + (row.features[i] - min)/(max - min));
- return currents;
- }
- // -------------------------------------------- getDistance ---------------------------------------------------
- double getDistance(t_coordinates coordinates_neuron_i, t_coordinates coordinates_neuron_j){
- return sqrt(pow(coordinates_neuron_i.x - coordinates_neuron_j.x,2) + pow(coordinates_neuron_i.y - coordinates_neuron_j.y,2));
- }
- // -------------------------------------------- getK ----------------------------------------------------------
- double getK(t_extendedArray neuron_i, t_extendedArray neuron_j){
- double distance = getDistance(neuron_i.coordinates, neuron_j.coordinates);
- if(distance <= 1) return 1;
- if((distance > 1) && (distance <= 2)) return 0.5;
- return 0;
- }
- // -------------------------------------------- getC ----------------------------------------------------------
- double getC(t_extendedArray neuron_i, t_extendedArray neuron_j){
- const double percentageNoise = 0.1;
- const double C_INH_EXC = 0.8;
- const double C_EXC_EXC = 0.6;
- const double C_EXC_INH = 0.4;
- const double C_INH_INH = 0.2;
- double x;
- if((neuron_i.population == 0) && (neuron_j.population == 0)) x = C_EXC_EXC;
- if((neuron_i.population == 0) && (neuron_j.population == 1)) x = C_EXC_INH;
- if((neuron_i.population == 1) && (neuron_j.population == 0)) x = C_INH_EXC;
- if((neuron_i.population == 1) && (neuron_j.population == 1)) x = C_INH_INH;
- return (1-percentageNoise)*x+(2*percentageNoise*x)*((double)rand()/(double)RAND_MAX);
- }
- // -------------------------------------------- getP ----------------------------------------------------------
- double getP(t_extendedArray neuron_i, t_extendedArray neuron_j){
- double k = getK(neuron_i, neuron_j);
- double c = getC(neuron_i, neuron_j);
- K << k << endl;
- C << c << endl;
- return k * c;
- }
- // -------------------------------------------- getMax --------------------------------------------------------
- double getMax(t_row row){
- double * features = row.features;
- double max = features[0];
- for(int i = 1; i < NEURONS_PER_PATTERN; i++) if(max < features[i]) max = features[i];
- return max;
- }
- // -------------------------------------------- getMin --------------------------------------------------------
- double getMin(double * vector, int row, int size){
- double * features = row.features;
- double min = features[0];
- for(int i = 1; i < NEURONS_PER_PATTERN; i++) if(min > features[i]) min = features[i];
- return min;
- }
- // ---------------------------------------- getItemFromExtendedArray ---------------------------------
- t_extendedArray getItemFromExtendedArray(t_extendedArray * array, int indexNeuron, int length){
- int index = 0;
- while((index < length) && index != indexNeuron) index++;
- return array[index];
- }
Add Comment
Please, Sign In to add comment