void setCounter(char *s, int n) /************************************************************************** purpose: allocates (if necessary) and sets a named TeX counter **************************************************************************/ { int i; i = existsCounter(s); if (i < 0) newCounter(s, n); else Counters[i].number = n; }
void incrementCounter(char *s) /************************************************************************** purpose: increments a TeX counter (or initializes to 1) **************************************************************************/ { int i; i = existsCounter(s); if (i < 0) newCounter(s, 1); else Counters[i].number++; }
bool ClassificationDataStream::addSample(const UINT classLabel,const MatrixFloat &sample){ if( numDimensions != sample.getNumCols() ){ errorLog << "addSample(const UINT classLabel, const MatrixFloat &sample) - the number of columns in the sample (" << sample.getNumCols() << ") does not match the number of dimensions of the dataset (" << numDimensions << ")" << std::endl; return false; } bool searchForNewClass = true; if( trackingClass ){ if( classLabel != lastClassID ){ //The class ID has changed so update the time series tracker timeSeriesPositionTracker[ timeSeriesPositionTracker.size()-1 ].setEndIndex( totalNumSamples-1 ); }else searchForNewClass = false; } if( searchForNewClass ){ bool newClass = true; //Search to see if this class has been found before for(UINT k=0; k<classTracker.size(); k++){ if( classTracker[k].classLabel == classLabel ){ newClass = false; classTracker[k].counter += sample.getNumRows(); } } if( newClass ){ ClassTracker newCounter(classLabel,1); classTracker.push_back( newCounter ); } //Set the timeSeriesPositionTracker start position trackingClass = true; lastClassID = classLabel; TimeSeriesPositionTracker newTracker(totalNumSamples,0,classLabel); timeSeriesPositionTracker.push_back( newTracker ); } ClassificationSample labelledSample( numDimensions ); for(UINT i=0; i<sample.getNumRows(); i++){ data.push_back( labelledSample ); data.back().setClassLabel( classLabel ); for(UINT j=0; j<numDimensions; j++){ data.back()[j] = sample[i][j]; } } totalNumSamples += sample.getNumRows(); return true; }
bool TimeSeriesClassificationDataStream::addSample(const UINT classLabel,const VectorDouble &sample){ if( numDimensions != sample.size() ){ errorLog << "addSample(const UINT classLabel, vector<double> sample) - the size of the new sample (" << sample.size() << ") does not match the number of dimensions of the dataset (" << numDimensions << ")" << endl; return false; } bool searchForNewClass = true; if( trackingClass ){ if( classLabel != lastClassID ){ //The class ID has changed so update the time series tracker timeSeriesPositionTracker[ timeSeriesPositionTracker.size()-1 ].setEndIndex( totalNumSamples-1 ); }else searchForNewClass = false; } if( searchForNewClass ){ bool newClass = true; //Search to see if this class has been found before for(UINT k=0; k<classTracker.size(); k++){ if( classTracker[k].classLabel == classLabel ){ newClass = false; classTracker[k].counter++; } } if( newClass ){ ClassTracker newCounter(classLabel,1); classTracker.push_back( newCounter ); } //Set the timeSeriesPositionTracker start position trackingClass = true; lastClassID = classLabel; TimeSeriesPositionTracker newTracker(totalNumSamples,0,classLabel); timeSeriesPositionTracker.push_back( newTracker ); } ClassificationSample labelledSample(classLabel,sample); data.push_back( labelledSample ); totalNumSamples++; return true; }
/* Agregador */ int runCounter () { char *tmp, *line = NULL; char *name, *parent, *child; int increment, nivel, file; Counter *counter; Childs *childInfo; ChainingHashMap *counters = newChainingHashMap(MAP_SIZE); /* Cria a tabela de hash e counters */ counters->hash = portugueseHash; counters->eq = compareKeys; ChainingHashMap *childs = newChainingHashMap(MAP_SIZE); /* Cria a tabela de hash childs */ childs->hash = portugueseHash; childs->eq = compareKeys; while(1) { tmp = line = nextLine(0); /* Lê a linha vinda do servidor */ if (line != NULL) { if (startsWith(line, "i")) { /* Recebe i A:12 despois i A:B:12 ... ; * Insere nas hash na counter A:12 depois A:B:12 ... * Na childs A depois A:B ... */ strsep(&line, " "); name = strdup(strsep(&line, "!")); increment = atoi(line); counter = (Counter *) getChaining(counters, (void *) name); /* Vai Buscar o elemento á hash */ if (counter == NULL) { putChaining(counters, strdup(name), newCounter(name, increment)); /* Coloca um novo elemento na hash */ putChaining(childs, strdup(name), newChilds(name)); } else { counter->counter += increment; } } else if (startsWith(line, "c")) { /* Recebe c A:B!A:B:C despois c A!A:B; * Coloca a informação dos descendentes na hash */ strsep(&line, " "); parent = strsep(&line, "!"); childInfo = (Childs *) getChaining(childs, parent); if (childInfo == NULL) { perror("Unable to find parent"); } else { childInfo->childs = insertElemHead(childInfo->childs, strdup(line)); /* Coloca a informação de um descendente, ou seja, para um distrito coloca a informação de um concelho e freguesia */ } } else if (startsWith(line, "a")) { /* Recebe a A:B:C!nivel!path; * Abre ou cria o ficheiro, e coloca lá a informação */ strsep(&line, " "); name = strsep(&line, "!"); nivel = atoi(strsep(&line, "!")); file = open(line, O_CREAT | O_WRONLY, S_IRUSR); agrega(counters, childs, name, nivel, file, NULL); close(file); } free(tmp); } } }