In KNNClassifier.h I have the following declarations:
Expand|Select|Wrap|Line Numbers
- class KNNClassifier{
- ...
- map<int, string> classNames;
- map<int, DataStore*> lastDataStores;
- map<int, int*> classificationMap;
- map<int, int> indexMap;
- vector<double> scaleVector;
- ...
- };
Expand|Select|Wrap|Line Numbers
- KNNClassifier::KNNClassifier(int numNeighbors)
- {
- ENTERCONSTRUCTOR;
- statsInitialized = false;
- classificationMatrix = NULL;
- totalClassified = NULL;
- classifiedCorrectly = NULL;
- isTrained = false;
- K = numNeighbors;
- numVectors = 0;
- maxVectors = 10;
- trainedFeatures = (FeatureVector**)malloc(sizeof(FeatureVector*) * maxVectors);
- LEAVECONSTRUCTOR;
- }
==11646== 75 errors in context 53 of 57:
==11646== Invalid read of size 4
==11646== at 0x804F07D: std::vector<double, std::allocator<double> >::begin() const (stl_vector.h:342)
==11646== by 0x805268D: std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&) (stl_vector.h:234)
==11646== by 0x805695B: KNNClassifier::classifyFeatures(std::vector<double , std::allocator<double> >) (KNNClassifier.cc:436)
==11646== by 0x8057B95: KNNClassifier::classifyFromFile(char*, char*, char*) (KNNClassifier.cc:281)
==11646== by 0x805CCD1: main (main.cc:71)
==11646== Address 0x567EB10 is 12 bytes after a block of size 100 alloc'd
==11646== at 0x4021DC5: operator new(unsigned) (vg_replace_malloc.c:163)
==11646== by 0x805CBE4: main (main.cc:55)
==11646==
==11646== 75 errors in context 54 of 57:
==11646== Invalid read of size 4
==11646== at 0x804F0A9: std::vector<double, std::allocator<double> >::end() const (stl_vector.h:360)
==11646== by 0x8052673: std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&) (stl_vector.h:234)
==11646== by 0x805695B: KNNClassifier::classifyFeatures(std::vector<double , std::allocator<double> >) (KNNClassifier.cc:436)
==11646== by 0x8057B95: KNNClassifier::classifyFromFile(char*, char*, char*) (KNNClassifier.cc:281)
==11646== by 0x805CCD1: main (main.cc:71)
==11646== Address 0x567EB14 is not stack'd, malloc'd or (recently) free'd
==11646==
==11646== 75 errors in context 55 of 57:
==11646== Invalid read of size 4
==11646== at 0x804F0A9: std::vector<double, std::allocator<double> >::end() const (stl_vector.h:360)
==11646== by 0x804F134: std::vector<double, std::allocator<double> >::size() const (stl_vector.h:402)
==11646== by 0x805261F: std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&) (stl_vector.h:233)
==11646== by 0x805695B: KNNClassifier::classifyFeatures(std::vector<double , std::allocator<double> >) (KNNClassifier.cc:436)
==11646== by 0x8057B95: KNNClassifier::classifyFromFile(char*, char*, char*) (KNNClassifier.cc:281)
==11646== by 0x805CCD1: main (main.cc:71)
==11646== Address 0x567EB14 is not stack'd, malloc'd or (recently) free'd
==11646==
==11646== 75 errors in context 56 of 57:
==11646== Invalid read of size 4
==11646== at 0x804F07D: std::vector<double, std::allocator<double> >::begin() const (stl_vector.h:342)
==11646== by 0x804F119: std::vector<double, std::allocator<double> >::size() const (stl_vector.h:402)
==11646== by 0x805261F: std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&) (stl_vector.h:233)
==11646== by 0x805695B: KNNClassifier::classifyFeatures(std::vector<double , std::allocator<double> >) (KNNClassifier.cc:436)
==11646== by 0x8057B95: KNNClassifier::classifyFromFile(char*, char*, char*) (KNNClassifier.cc:281)
==11646== by 0x805CCD1: main (main.cc:71)
==11646== Address 0x567EB10 is 12 bytes after a block of size 100 alloc'd
==11646== at 0x4021DC5: operator new(unsigned) (vg_replace_malloc.c:163)
==11646== by 0x805CBE4: main (main.cc:55)
==11646==
==11646== 216 errors in context 57 of 57:
==11646== Invalid read of size 4
==11646== at 0x804F44A: __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >::__normal_iterator(double* const&) (stl_iterator.h:650)
==11646== by 0x804F4C4: std::vector<double, std::allocator<double> >::begin() (stl_vector.h:333)
==11646== by 0x805242D: std::vector<double, std::allocator<double> >::operator[](unsigned) (stl_vector.h:480)
==11646== by 0x80550B2: KNNClassifier::calcFeatureScale() (KNNClassifier.cc:706)
==11646== by 0x8058479: KNNClassifier::trainFromFile(char*, char*) (KNNClassifier.cc:185)
==11646== by 0x805CC93: main (main.cc:65)
==11646== Address 0x567EB10 is 12 bytes after a block of size 100 alloc'd
==11646== at 0x4021DC5: operator new(unsigned) (vg_replace_malloc.c:163)
==11646== by 0x805CBE4: main (main.cc:55)