Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

ArchiveStatistic.cpp

Go to the documentation of this file.
00001 #/***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 //SpikeStream includes
00024 #include "ArchiveStatistic.h"
00025 #include "Debug.h"
00026 
00027 //Other includes
00028 #include <iostream>
00029 using namespace std;
00030 
00031 
00032 //Local version of debug defines
00033 //#define ARCHIVE_STATISTICS_DEBUG
00034 
00035 
00036 //Declare static variables
00037 dense_hash_map<unsigned int, bool, hash<unsigned int> >* ArchiveStatistic::neuronIDHashMap;
00038 
00039 
00040 //-----------------------------------------------------------------------------
00041 //----------------             ARCHIVE STATISTIC          ---------------------
00042 //-----------------------------------------------------------------------------
00043 
00044 /*! Constructor. */
00045 ArchiveStatistic::ArchiveStatistic(unsigned int* fNeurCount, unsigned int* fNeurTotal){
00046         //Store references and the ID
00047         firingNeuronCount = fNeurCount;
00048         firingNeuronTotal = fNeurTotal;
00049 
00050         //Set the default type
00051         type = NEURON_ID;
00052 }
00053 
00054 
00055 /*! Destructor. */
00056 ArchiveStatistic::~ArchiveStatistic(){
00057         #ifdef MEMORY_DEBUG
00058                 cout<<"DESTROYING ARCHIVE STATISTIC"<<endl;
00059         #endif//MEMORY_DEBUG
00060 }
00061 
00062 
00063 /*! Returns the ID given to the class. */
00064 unsigned int ArchiveStatistic::getID(){
00065         return ID;
00066 }
00067 
00068 
00069 /*! Returns the type of the class. */
00070 unsigned int ArchiveStatistic::getType(){
00071         return type;
00072 }
00073 
00074 
00075 /*! Default implementation of this method, which gets called if it is not overridden
00076         by a subclass. */
00077 void ArchiveStatistic::recalculate(){
00078 }
00079 
00080 
00081 /*! Default implementation of this method, which gets called if it is not overridden
00082         by a subclass. */
00083 void ArchiveStatistic::recalculate(unsigned int){
00084 }
00085 
00086 
00087 /*! Default implementation of this method, which gets called if it is not overridden
00088         by a subclass. */
00089 void ArchiveStatistic::recalculateNeuronGrp(){
00090 }
00091 
00092 
00093 /*! Resets the firing neuron count. Generally called when starting to load the 
00094         data for a timestep. */
00095 void ArchiveStatistic::resetFiringNeuronCount(){
00096         *firingNeuronCount = 0;
00097 }
00098 
00099 
00100 /*! Resets the firing neuron total. Generally called when rewinding the archive
00101         or after editing the statistics. */
00102 void ArchiveStatistic::resetFiringNeuronTotal(){
00103         *firingNeuronTotal = 0;
00104 }
00105 
00106 
00107 /*! Sets the id. */
00108 void ArchiveStatistic::setID(unsigned int id){
00109         ID = id;
00110 }
00111 
00112 
00113 //-----------------------------------------------------------------------------
00114 //---------             NEURON GROUP ARCHIVE STATISTIC          ---------------
00115 //-----------------------------------------------------------------------------
00116 
00117 /*! Constructor. */
00118 NeuronGrpArchiveStatistic::NeuronGrpArchiveStatistic(unsigned int* fNeurCount, unsigned int* fNeurTotal, unsigned int nGrpID) : ArchiveStatistic(fNeurCount, fNeurTotal) {
00119         type = NEURON_GROUP;
00120         neuronGrpID = nGrpID;
00121 }
00122 
00123 
00124 /*! Destructor. */
00125 NeuronGrpArchiveStatistic::~NeuronGrpArchiveStatistic(){
00126         #ifdef MEMORY_DEBUG
00127                 cout<<"DESTROYING NEURON GROUP ARCHIVE STATISTIC"<<endl;
00128         #endif//MEMORY_DEBUG
00129 }
00130 
00131 
00132 /*! Accessor for the neuron group id. */
00133 unsigned int NeuronGrpArchiveStatistic::getNeuronGrpID(){
00134         return neuronGrpID;
00135 }
00136 
00137 
00138 /*! Recalculates the statistics being gathered by this class. The neuron group
00139         handling should be carried out by the networkDataXmlHandler, so will assume
00140         that we don't need to check that neuron group id is in range. This method should
00141         be called for each neuron found in the neuron group. */
00142 void NeuronGrpArchiveStatistic::recalculateNeuronGrp(){
00143         ++(*firingNeuronCount);
00144         ++(*firingNeuronTotal);
00145 
00146         #ifdef ARCHIVE_STATISTICS_DEBUG
00147                 cout<<"NeuronGrpArchiveStatistic: Recalculated neuron group. firingNeuronCount = "<<*firingNeuronCount<<"; firingNeuronTotal = "<<*firingNeuronTotal<<endl;
00148         #endif//ARCHIVE_STATISTICS_DEBUG
00149 }
00150 
00151 
00152 /*! Outputs a string that would have been used to create this class. In this
00153         case, no string was used, so returns an error message. */
00154 QString NeuronGrpArchiveStatistic::toQString(){
00155         return QString("Neuron ID Error! This class was not created with a string.");//This class is not created with a string so return an error.
00156 }
00157 
00158 //-----------------------------------------------------------------------------
00159 //-----------             RANGE ARCHIVE STATISTIC                --------------
00160 //-----------------------------------------------------------------------------
00161 
00162 /*! Constructor. */
00163 RangeArchiveStatistic::RangeArchiveStatistic(unsigned int* fNeurCount, unsigned int* fNeurTotal, unsigned int rLow, unsigned int rHigh) : ArchiveStatistic(fNeurCount, fNeurTotal) {
00164         rangeLow = rLow;
00165         rangeHigh = rHigh;
00166 }
00167 
00168 
00169 /*! Destructor. */
00170 RangeArchiveStatistic::~RangeArchiveStatistic(){
00171         #ifdef MEMORY_DEBUG
00172                 cout<<"DESTROYING RANGE ARCHIVE STATISTIC"<<endl;
00173         #endif//MEMORY_DEBUG
00174 }
00175 
00176 
00177 /*! Examines the hash map for neuron ids that are in range. */
00178 void RangeArchiveStatistic::recalculate(){
00179         for(unsigned int i=rangeLow; i <= rangeHigh; ++i){
00180                 if(neuronIDHashMap->count(i)){
00181                         ++(*firingNeuronCount);
00182                         ++(*firingNeuronTotal);
00183                 }
00184         }
00185         #ifdef ARCHIVE_STATISTICS_DEBUG
00186                 cout<<"RangeArchiveStatistic: Recalculated neuron group. firingNeuronCount = "<<*firingNeuronCount<<"; firingNeuronTotal = "<<*firingNeuronTotal<<endl;
00187         #endif//ARCHIVE_STATISTICS_DEBUG
00188 }
00189 
00190 
00191 /*! Outputs a string that would have been used to create this class. */
00192 QString RangeArchiveStatistic::toQString(){
00193         QString tempStr(QString::number(rangeLow));
00194         tempStr += "-";
00195         tempStr += QString::number(rangeHigh);
00196         return tempStr;
00197 }
00198 
00199 
00200 //-----------------------------------------------------------------------------
00201 //-------------             AND ARCHIVE STATISTIC                --------------
00202 //-----------------------------------------------------------------------------
00203 
00204 /*! Constructor. */
00205 AndArchiveStatistic::AndArchiveStatistic(unsigned int* fNeurCount, unsigned int* fNeurTotal, unsigned int fNeurID, unsigned int sNeurID) : ArchiveStatistic(fNeurCount, fNeurTotal) {
00206         firstNeuronID = fNeurID;
00207         secondNeuronID = sNeurID;
00208 }
00209 
00210 
00211 /*! Destructor. */
00212 AndArchiveStatistic::~AndArchiveStatistic(){
00213         #ifdef MEMORY_DEBUG
00214                 cout<<"DESTROYING AND ARCHIVE STATISTIC"<<endl;
00215         #endif//MEMORY_DEBUG
00216 }
00217 
00218 
00219 /*! Examines the hash map to see if both neuron IDs are present. */
00220 void AndArchiveStatistic::recalculate(){
00221         if(neuronIDHashMap->count(firstNeuronID) && neuronIDHashMap->count(secondNeuronID)){
00222                 ++(*firingNeuronCount);
00223                 ++(*firingNeuronTotal);
00224         }
00225         #ifdef ARCHIVE_STATISTICS_DEBUG
00226                 cout<<"AndArchiveStatistic: Recalculated neuron group. firingNeuronCount = "<<*firingNeuronCount<<"; firingNeuronTotal = "<<*firingNeuronTotal<<endl;
00227         #endif//ARCHIVE_STATISTICS_DEBUG
00228 }
00229 
00230 
00231 /*! Outputs a string that would have been used to create this class. */
00232 QString AndArchiveStatistic::toQString(){
00233         QString tempStr(QString::number(firstNeuronID));
00234         tempStr += "&";
00235         tempStr += QString::number(secondNeuronID);
00236         return tempStr;
00237 }
00238 
00239 
00240 //-----------------------------------------------------------------------------
00241 //-------------              OR ARCHIVE STATISTIC                --------------
00242 //-----------------------------------------------------------------------------
00243 
00244 /*! Constructor. */
00245 OrArchiveStatistic::OrArchiveStatistic(unsigned int* fNeurCount, unsigned int* fNeurTotal, unsigned int fNeurID, unsigned int sNeurID) : ArchiveStatistic(fNeurCount, fNeurTotal) {
00246         firstNeuronID = fNeurID;
00247         secondNeuronID = sNeurID;
00248 }
00249 
00250 
00251 /*! Destructor. */
00252 OrArchiveStatistic::~OrArchiveStatistic(){
00253         #ifdef MEMORY_DEBUG
00254                 cout<<"DESTROYING OR ARCHIVE STATISTIC"<<endl;
00255         #endif//MEMORY_DEBUG
00256 }
00257 
00258 
00259 /*! Examines the hash map to see if the first or second neuron IDs are present. */
00260 void OrArchiveStatistic::recalculate(){
00261         if(neuronIDHashMap->count(firstNeuronID) || neuronIDHashMap->count(secondNeuronID)){
00262                 ++(*firingNeuronCount);
00263                 ++(*firingNeuronTotal);
00264         }
00265         #ifdef ARCHIVE_STATISTICS_DEBUG
00266                 cout<<"OrArchiveStatistic: Recalculated neuron group. firingNeuronCount = "<<*firingNeuronCount<<"; firingNeuronTotal = "<<*firingNeuronTotal<<endl;
00267         #endif//ARCHIVE_STATISTICS_DEBUG
00268 }
00269 
00270 
00271 /*! Outputs a string that would have been used to create this class. */
00272 QString OrArchiveStatistic::toQString(){
00273         QString tempStr(QString::number(firstNeuronID));
00274         tempStr += "|";
00275         tempStr += QString::number(secondNeuronID);
00276         return tempStr;
00277 }
00278 
00279 
00280 //-----------------------------------------------------------------------------
00281 //-----------             NEURON ID ARCHIVE STATISTIC              ------------
00282 //-----------------------------------------------------------------------------
00283 
00284 /*! Constructor. */
00285 NeuronIDArchiveStatistic::NeuronIDArchiveStatistic(unsigned int* fNeurCount, unsigned int* fNeurTotal, unsigned int neurID) : ArchiveStatistic(fNeurCount, fNeurTotal) {
00286         neuronID = neurID;
00287 }
00288 
00289 
00290 /*! Destructor. */
00291 NeuronIDArchiveStatistic::~NeuronIDArchiveStatistic(){
00292         #ifdef MEMORY_DEBUG
00293                 cout<<"DESTROYING NEURON ID ARCHIVE STATISTIC"<<endl;
00294         #endif//MEMORY_DEBUG
00295 }
00296 
00297 
00298 /*! Examines the hash map to see if the neuron ID is present. */
00299 void NeuronIDArchiveStatistic::recalculate(){
00300         if(neuronIDHashMap->count(neuronID)){
00301                 ++(*firingNeuronCount);
00302                 ++(*firingNeuronTotal);
00303         }
00304         #ifdef ARCHIVE_STATISTICS_DEBUG
00305                 cout<<"NeuronIDArchiveStatistic: Recalculated neuron group. firingNeuronCount = "<<*firingNeuronCount<<"; firingNeuronTotal = "<<*firingNeuronTotal<<endl;
00306         #endif//ARCHIVE_STATISTICS_DEBUG
00307 }
00308 
00309 
00310 /*! Outputs a string that would have been used to create this class. */
00311 QString NeuronIDArchiveStatistic::toQString(){
00312         return QString::number(neuronID);
00313 }
00314 
00315 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4