All Classes Namespaces Files Functions Variables Typedefs Macros
clizSorter.h
Go to the documentation of this file.
1 // clizSorter.h - ClusterLizard header file - Module: Sorter
2 
3 // Copyright (C) 2013, 2014 Simeon Knieling, M.Sc.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 //
9 
10 //Sorter Class
11 
12 #pragma once
13 #ifndef _INCLUDE_CLIZSORTER
14 #define _INCLUDE_CLIZSORTER
15 
16 #include "clizSave.h"
17 
20 namespace cliz
21 {
22 
26  class Cluster
27  {
28  public:
29  int ID; //Cluster ID number
30  unsigned int nspk; //Number of spikes in cluster
31  unsigned int *indices; //Indices of spikes in cluster
32  float *features; //All features of spikes in cluster
33  float *representative; //Representative of cluster (mean features)
34  uint64_t *timestamps; //Timestamps of spikes in cluster
35 
39  Cluster(float *&iRepresentative, int iID, float *&iFeatures, unsigned int *&iIndices, uint64_t *&iTimestamps, unsigned int iNspk);
40 
46  void destroy(MemoryManager &memMan);
47  };
48 
52  struct ClusterArray
53  {
54  std::vector<Cluster> cluster;
55  };
56 
59  struct SorterHandle
60  {
61  unsigned int numSpikesToConsider; //number of spikes for moving window calculations
62  float fusionCriteriaParams[10]; //thresholds for fusion criteria of adolescent clusters
63  float adultFusionCriteriaParams[10]; //thresholds for fusion criteria of adult clusters
64  unsigned int minSpikes2AdultCluster; //Number of spikes that a cluster needs to be considered adult
65  unsigned int numFeatures; //Number of features for sorting
66  unsigned int corrPadding;
67  unsigned int numAllFeatures; //Number of all available features
68  uint64_t timeUntilForcing; //In sample points!
69  uint64_t forcingDelay; //Should forcing be used? If so, at what time (in datapoints) should it start?
70  unsigned int maxNspk4Forcing; //Clusters with more spikes will not be forced into other clusters
71  float maxDist4Forcing; //If the representative of a cluster has a greater distance to the representative of its closest adult cluster, it will not be fused.
72  unsigned int min_clusters; //Minimal number of clusters the algorithm will produce (due to the many small clusters of 1 or 2 spikes, this number doesn't really do much)
73  };
74 
98  class Sorter
99  {
100  private:
101  SorterHandle handle; //Parameter handle
102  std::vector<IndicesStruct> indicesOut; //Which Modules that receive output from this module need which output?
103  std::vector<Save*> inputSaveVec; //Input Saves
104  std::vector<Save*> outputSaveVec; //Output Saves
105 
106  ClusterArray clusArray; //Array of clusters
107 
108  float *featureStd; //Current Std of all features
109  float *featureWeights; //Current weights of all features
110  unsigned int *featureIDs; //Indices of currently selected features
111 
112  unsigned int *killList; //List of clusters to kill
113  unsigned int killListCount; //Number of clusters in killList
114  unsigned int nspk; //Number of spikes
115  unsigned int numClusterFusions; //Number of cluster fusions
116  unsigned int *clusterFusions; //Cluster fusions
117  unsigned int *clusterIDs; //Cluster IDs
118 
119  uint64_t lastSpikeTimestamp; //Timestamp of last spike
120  uint64_t currentTime; //Current time
121  MemoryManager memMan;
122 
123  public:
127  Sorter(SorterHandle iHandle, std::vector<Save*> &iInputSaveVec, std::vector<Save*> &iOutputSaveVec, std::vector<IndicesStruct> iIndicesOut);
128 
135  inline void calcDist(float &oDist, unsigned int cluster1, unsigned int cluster2);
136 
144  int fusionPossible(unsigned int idMaster, unsigned int idSlave, float diffCrit);
145 
152  void feedSpikeFeatures(float *iFeatures, uint64_t *iTimestamps, int iNspk);
153 
158  void clusteringLoop(unsigned int newClusters);
159 
165  void fuseCluster(unsigned int idMaster, unsigned int idSlave);
166 
171  void killCluster(unsigned int iClusterIndex);
172 
176  void killTheList();
177 
182  void getClusterCount(int &oClusterCount);
183 
187  void threadFunc();
188 
190  {
191  memMan.free(featureIDs);
192  memMan.free(featureStd);
193  memMan.free(featureWeights);
194  memMan.free(killList);
195  }
196  };
197 
198 }
199 
200 #endif
unsigned int numFeatures
Definition: clizSorter.h:65
void killTheList()
Definition: clizSorter.cpp:594
void calcDist(float &oDist, unsigned int cluster1, unsigned int cluster2)
Definition: clizSorter.cpp:226
unsigned int numSpikesToConsider
Definition: clizSorter.h:61
unsigned int corrPadding
Definition: clizSorter.h:66
std::vector< Cluster > cluster
Definition: clizSorter.h:54
Definition: clizSorter.h:59
Definition: cliz.h:55
void threadFunc()
Definition: clizSorter.cpp:73
Definition: clizSorter.h:26
void fuseCluster(unsigned int idMaster, unsigned int idSlave)
Definition: clizSorter.cpp:494
unsigned int minSpikes2AdultCluster
Definition: clizSorter.h:64
uint64_t forcingDelay
Definition: clizSorter.h:69
Definition: clizSorter.h:98
uint64_t timeUntilForcing
Definition: clizSorter.h:68
unsigned int nspk
Definition: clizSorter.h:30
float * representative
Definition: clizSorter.h:33
void feedSpikeFeatures(float *iFeatures, uint64_t *iTimestamps, int iNspk)
Definition: clizSorter.cpp:190
float maxDist4Forcing
Definition: clizSorter.h:71
unsigned int * indices
Definition: clizSorter.h:31
unsigned int min_clusters
Definition: clizSorter.h:72
void getClusterCount(int &oClusterCount)
Definition: clizSorter.cpp:610
Definition: clizSorter.h:52
Sorter(SorterHandle iHandle, std::vector< Save * > &iInputSaveVec, std::vector< Save * > &iOutputSaveVec, std::vector< IndicesStruct > iIndicesOut)
Definition: clizSorter.cpp:50
Definition: clizFunctions.h:268
float adultFusionCriteriaParams[10]
Definition: clizSorter.h:63
uint64_t * timestamps
Definition: clizSorter.h:34
void free(memPtr *memAdr)
Definition: clizFunctions.h:331
float fusionCriteriaParams[10]
Definition: clizSorter.h:62
~Sorter()
Definition: clizSorter.h:189
float * features
Definition: clizSorter.h:32
int fusionPossible(unsigned int idMaster, unsigned int idSlave, float diffCrit)
Definition: clizSorter.cpp:252
void clusteringLoop(unsigned int newClusters)
Definition: clizSorter.cpp:330
unsigned int maxNspk4Forcing
Definition: clizSorter.h:70
int ID
Definition: clizSorter.h:29
void destroy(MemoryManager &memMan)
Definition: clizSorter.cpp:38
Cluster(float *&iRepresentative, int iID, float *&iFeatures, unsigned int *&iIndices, uint64_t *&iTimestamps, unsigned int iNspk)
Definition: clizSorter.cpp:23
void killCluster(unsigned int iClusterIndex)
Definition: clizSorter.cpp:586
unsigned int numAllFeatures
Definition: clizSorter.h:67