void csimClassInfoDB::listClasses(bool listFields) { int wmax=0,l,c; csimPrintf("\n"); for(c=0; c<nRegClasses; c++) { if ( (l=strlen(regClasses[c]->name)) > wmax ) wmax = l; } for(c=0; c<nRegClasses; c++) { if ( listFields ) { csimPrintf("%s: %s\n",regClasses[c]->name,regClasses[c]->description); regClasses[c]->listFields(); csimPrintf("\n"); } else { csimPrintf("%*s : %s\n",wmax,regClasses[c]->name,regClasses[c]->description); } } csimPrintf("\n"); }
void csimClass::printFields(char *o) { csimClassInfo *info=getClassInfo(); int i,m,l,wname=0; csimPrintf("%i : %s",Id,info->name); if ( info->nRegFields > 0 ) { // determine maximum length of field names for(i=0; i<info->nRegFields; i++) if ( (l=strlen(info->regFields[i]->name)) > wname ) wname = l; // print each field for(i=0; i<info->nRegFields; i++) { if ( (m=getFieldSizeById(o,i)) == 1 ) { // field is a single value double v; getFieldById(o,i,&v); char c = info->regFields[i]->access == READWRITE ? '=' : ':' ; if ( info->regFields[i]->units[0] != 0 ) csimPrintf("\n %*s %c %g (%s)",wname,info->regFields[i]->name,c,v,info->regFields[i]->units); else csimPrintf("\n %*s %c %g",wname,info->regFields[i]->name,c,v); } else if ( m < 6 ) { // field is a short vector // 1) alloc some memory to write values double *v=(double *)malloc(m*sizeof(double)); // 2) get values getFieldById(o,i,v); // 3) print them csimPrintf("\n %*s = [ ",wname,info->regFields[i]->name); for(int j=0; j<m; j++) csimPrintf("%g ",v[j]); csimPrintf("] (%s)",info->regFields[i]->units); // 4) free memory if (v) free(v); v = 0; } else // field to long to print out csimPrintf("\n %*s = [ 1 x %i array ] %s",wname,info->regFields[i]->name,m,info->regFields[i]->units); } csimPrintf("\n"); } else { csimPrintf(" no fields.\n"); } csimPrintf("\n"); }
void csimClassInfo::listFields(void) { int i,l,mnl = 0,mll = 0, mul=0, mUl=0; char ustr[256]; for(i=0; i<nRegFields; i++) { csimFieldInfo *f = regFields[i]; l=strlen(f->name); mnl=max(mnl,l); sprintf(ustr,"%g",f->lb); l=strlen(ustr); mll=max(mll,l); sprintf(ustr,"%g",f->ub); l=strlen(ustr); mul=max(mul,l); l=strlen(f->units); mUl=max(mUl,l); } for(i=0; i<nRegFields; i++) { csimFieldInfo *f = regFields[i]; if ( f->access == READWRITE ) { if ( f->units[0] == '\0' ) csimPrintf(" %*s = %s range: %g to %g\n",mnl,f->name,f->description,f->lb,f->ub); else csimPrintf(" %*s = %s range: %g to %g; units: %s\n",mnl,f->name,f->description,f->lb,f->ub,f->units); } } for(i=0; i<nRegFields; i++) { csimFieldInfo *f = regFields[i]; if ( f->access == READONLY ) { if ( f->units[0] != '\0' ) csimPrintf(" %*s : %s units: %s\n",mnl,f->name,f->description,f->units); else csimPrintf(" %*s : %s\n",mnl,f->name,f->description); } } }
csimInputChannel* csimInputClass::getChannel(uint32 i) { if ( i<channel.n ) { // printf("csimInputClass::getChannel %i\n",i); return channel.elements[i]; } else { if ( !channelIdChecked ) { // TheCsimError.add("csimInputClass::getChannel: no such channel index (%i)!\n",i); csimPrintf("CSIM WARNING: csimInputClass::getChannel: no such channel index (%i)!\n",i); channelIdChecked=1; } return 0; //printf("FATAL: csimInputClass::getChannel: no such channel index (%i)!\n",i); //printf("Exitting!\n"); //exit(-1); } }
void StaticAnalogSynapse::reset(void) { /* ************************ BEGIN MICHAEL PFEIFFER *********************** */ if ( Inoise > 0.0 ) psr = psi * W + normrnd() * Inoise; else psr = psi * W; if (summationPoint) { (*summationPoint) += psr; } else { csimPrintf("StaticAnalogSynapse::reset Synapse %d is not connected to a neuron!\n",getId()); } // advance(); /* ************************* END MICHAEL PFEIFFER *********************** */ }
/** Applies the currently learned function to the filtered and preprocessed input vector. \param S State of the liquid (= filtered and preprocessed response of the neural microcircuit). \param X Target pointer where to save the result. \return -1 if an error occured, 1 for success. */ int linear_classification::apply(const double* S, double* X) { if (S == 0) { // Error TheCsimError.add("linear_classification::apply: Input is a NULL pointer!\n"); return -1; } if (X == 0) { // Error TheCsimError.add("linear_classification::apply: Target is a NULL pointer!\n"); return -1; } if (nClasses == 2) { // binary classification double res = weighted_sum(S, regression_coefficients[0]); *X = (double) (res >= 0); return 1; } else { // multi-class classification double max_v = 0; int max_ind = -1; double res; // Calculate class with highest weighted sum for (int i=0; i<nClasses; i++) { csimPrintf("%d: ", i); res = weighted_sum(S, regression_coefficients[i]); if ((res > max_v) || (max_ind < 0)) { max_v = res; max_ind = i; } } *X = (double) max_ind; return 1; } }
/** Loads the data from a .mat file. */ int ArmModel::loadData(bool onlyReset) { char filename[20]; sprintf(filename, "T%d.mat",inputFileNr); // Open MAT-File MATFile *mf = matOpen(filename, "r"); if (mf == NULL) { TheCsimError.add("ArmModel::loadData Cannot find input file %s\n",filename); return -1; } if (!onlyReset) { /* ********************************************************* READ ALL DATA FROM FILE ********************************************************* */ // Read Xdest and store it mxArray *mxXdest = matGetVariable(mf, "Xdest"); if (mxXdest == NULL) { TheCsimError.add("ArmModel::loadData Cannot find Xdest in input file %s\n",filename); return -1; } TIMESTEPS = mxGetN(mxXdest); csimPrintf("Read data for %d timesteps!\n", TIMESTEPS); Xdest = (double *) realloc(Xdest, TIMESTEPS*50*sizeof(double)); memcpy(Xdest, mxGetPr(mxXdest), TIMESTEPS*50*sizeof(double)); // Read Ydest and store it mxArray *mxYdest = matGetVariable(mf, "Ydest"); if (mxYdest == NULL) { TheCsimError.add("ArmModel::loadData Cannot find Ydest in input file %s\n",filename); return -1; } Ydest = (double *) realloc(Ydest, TIMESTEPS*50*sizeof(double)); memcpy(Ydest, mxGetPr(mxYdest), TIMESTEPS*50*sizeof(double)); mxDestroyArray(mxYdest); // Read Theta1 and store it mxArray *mxTheta1 = matGetVariable(mf, "theta1"); if (mxTheta1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find theta1 in input file %s\n",filename); return -1; } theta1 = (double *) realloc(theta1, TIMESTEPS*50*sizeof(double)); memcpy(theta1, mxGetPr(mxTheta1), TIMESTEPS*50*sizeof(double)); mxDestroyArray(mxTheta1); // Read Theta2 and store it mxArray *mxTheta2 = matGetVariable(mf, "theta2"); if (mxTheta2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find theta2 in input file %s\n",filename); return -1; } theta2 = (double *) realloc(theta2, TIMESTEPS*50*sizeof(double)); memcpy(theta2, mxGetPr(mxTheta2), TIMESTEPS*50*sizeof(double)); mxDestroyArray(mxTheta2); // Read nu1 and store it mxArray *mxNu1 = matGetVariable(mf, "nu1"); if (mxNu1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find nu1 in input file %s\n",filename); return -1; } nu1 = (double *) realloc(nu1, TIMESTEPS*50*sizeof(double)); memcpy(nu1, mxGetPr(mxNu1), TIMESTEPS*50*sizeof(double)); mxDestroyArray(mxNu1); // Read nu2 and store it mxArray *mxNu2 = matGetVariable(mf, "nu2"); if (mxNu2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find nu2 in input file %s\n",filename); return -1; } nu2 = (double *) realloc(nu2, TIMESTEPS*50*sizeof(double)); memcpy(nu2, mxGetPr(mxNu2), TIMESTEPS*50*sizeof(double)); mxDestroyArray(mxNu2); // Read c_theta1 and store it mxArray *mxCTheta1 = matGetVariable(mf, "c_theta1"); if (mxCTheta1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find c_theta1 in input file %s\n",filename); return -1; } c_theta1 = (double *) realloc(c_theta1, TIMESTEPS*sizeof(double)); memcpy(c_theta1, mxGetPr(mxCTheta1), TIMESTEPS*sizeof(double)); mxDestroyArray(mxCTheta1); // Read c_theta2 and store it mxArray *mxCTheta2 = matGetVariable(mf, "c_theta2"); if (mxCTheta2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find c_theta2 in input file %s\n",filename); return -1; } c_theta2 = (double *) realloc(c_theta2, TIMESTEPS*sizeof(double)); memcpy(c_theta2, mxGetPr(mxCTheta2), TIMESTEPS*sizeof(double)); mxDestroyArray(mxCTheta2); // Read c_u1 and store it mxArray *mxCU1 = matGetVariable(mf, "c_u1"); if (mxCU1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find c_u1 in input file %s\n",filename); return -1; } c_u1 = (double *) realloc(c_u1, TIMESTEPS*sizeof(double)); memcpy(c_u1, mxGetPr(mxCU1), TIMESTEPS*sizeof(double)); mxDestroyArray(mxCU1); // Read c_u2 and store it mxArray *mxCU2 = matGetVariable(mf, "c_u2"); if (mxCU2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find c_u2 in input file %s\n",filename); return -1; } c_u2 = (double *) realloc(c_u2, TIMESTEPS*sizeof(double)); memcpy(c_u2, mxGetPr(mxCU2), TIMESTEPS*sizeof(double)); mxDestroyArray(mxCU2); // Get the values which will be added as baselines. int pos = 0; for (int i=0; i<TIMESTEPS; i++) { for (int j=0; j<50; j++) { if (pos == 0) { mintheta1 = theta1[0]; mintheta2 = theta2[0]; minU1 = nu1[0]; minU2 = nu2[0]; // HERE THE GET_ACT_VAL AND MAXU1, MAXU2 ARE MISSING, DO WE NEED IT? } else { if (theta1[pos] < mintheta1) mintheta1 = theta1[pos]; if (theta2[pos] < mintheta2) mintheta2 = theta2[pos]; if (nu1[pos] < minU1) minU1 = nu1[pos]; if (nu2[pos] < minU2) minU2 = nu2[pos]; } pos++; } } mintheta1 = fabs(mintheta1); mintheta2 = fabs(mintheta2); minU1 = fabs(minU1); minU2 = fabs(minU2); } // Do the rest for a simple reset /* ********************************************************* INITIALIZE THE OUTPUTS OF THE MODEL ********************************************************* */ for (int i=0; i<50; i++) { out_buffer[i][0] = Xdest[i]; out_buffer[i+50][0] = Ydest[i]; out_buffer[i+100][0] = theta1[i]; if (out_buffer[i+100][0] != 0) out_buffer[i+100][0] += mintheta1; out_buffer[i+150][0] = theta2[i]; if (out_buffer[i+150][0] != 0) out_buffer[i+150][0] += mintheta2; out_buffer[i+200][0] = nu1[i]; if (out_buffer[i+200][0] != 0) out_buffer[i+200][0] += minU1; out_buffer[i+250][0] = nu2[i]; if (out_buffer[i+250][0] != 0) out_buffer[i+250][0] += minU2; } buffer_position = 0; /* ********************************************************* Calculate initial values for u, t and w ********************************************************* */ // Read u1(1) and store it mxArray *mxU1 = matGetVariable(mf, "u1"); if (mxU1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find u1 in input file %s\n",filename); return -1; } u1 = *(mxGetPr(mxU1)); mxDestroyArray(mxU1); // Read u2(1) and store it mxArray *mxU2 = matGetVariable(mf, "u2"); if (mxU2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find u2 in input file %s\n",filename); return -1; } u2 = *(mxGetPr(mxU2)); mxDestroyArray(mxU2); // Read t1(1) and store it mxArray *mxT1 = matGetVariable(mf, "t1"); if (mxT1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find t1 in input file %s\n",filename); return -1; } t1 = *(mxGetPr(mxT1)); mxDestroyArray(mxT1); // Read t2(1) and store it mxArray *mxT2 = matGetVariable(mf, "t2"); if (mxT2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find t2 in input file %s\n",filename); return -1; } t2 = *(mxGetPr(mxT2)); mxDestroyArray(mxT2); // Read dt1(1) and store it mxArray *mxDT1 = matGetVariable(mf, "dt1"); if (mxDT1 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find dt1 in input file %s\n",filename); return -1; } w1 = *(mxGetPr(mxDT1)); mxDestroyArray(mxDT1); // Read dt2(1) and store it mxArray *mxDT2 = matGetVariable(mf, "dt2"); if (mxDT2 == NULL) { TheCsimError.add("ArmModel::loadData Cannot find dt2 in input file %s\n",filename); return -1; } w2 = *(mxGetPr(mxDT2)); mxDestroyArray(mxDT2); // Close the input file if (matClose(mf) == EOF) { TheCsimError.add("ArmModel::loadData Error while closing the input file!\n"); return -1; } return 0; }