diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..e7e9d11d --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/SPORF.iml b/.idea/SPORF.iml new file mode 100644 index 00000000..89586141 --- /dev/null +++ b/.idea/SPORF.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..0f896b2c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..0121e833 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/rSettings.xml b/.idea/rSettings.xml new file mode 100644 index 00000000..f48b70e1 --- /dev/null +++ b/.idea/rSettings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Python/rerf/rerfClassifier.py b/Python/rerf/rerfClassifier.py index 362cb610..d5429f2a 100644 --- a/Python/rerf/rerfClassifier.py +++ b/Python/rerf/rerfClassifier.py @@ -230,7 +230,7 @@ def fit(self, X, y): else: forestType = "binnedBaseTern" self.method_to_use_ = 1 - elif self.projection_matrix == "S-RerF": + elif self.projection_matrix in ["S-RerF", "MT-MORF"]: if self.oob_score: warn( "OOB is not currently implemented for the S-RerF" @@ -241,7 +241,12 @@ def fit(self, X, y): self.oob_score = False forestType = "binnedBaseTern" # this should change - self.method_to_use_ = 2 + + if self.projection_matrix == 'S-RerF': + self.method_to_use_ = 2 + elif self.projection_matrix == 'MT-MORF': + self.method_to_use_ = 3 + # Check that image_height and image_width are divisors of # the num_features. This is the most we can do to # prevent an invalid value being passed in. diff --git a/Python/tests/__init__.py b/Python/tests/__init__.py old mode 100644 new mode 100755 diff --git a/packedForest/Makefile b/packedForest/Makefile index 18d184f0..89451465 100644 --- a/packedForest/Makefile +++ b/packedForest/Makefile @@ -1,7 +1,8 @@ #Compiler and Linker #CC := g++-mp-4.7 CC := g++ -std=c++11 -#CC := g++-6 -std=c++11 +# CC := gcc-9 -std=c++11 -c +# CC := g++-6 -std=c++11 #The Target Binary Program TARGET := fp @@ -21,7 +22,7 @@ OBJEXT := o CFLAGS := -fopenmp -Wall -O3 -DNDEBUG -ffast-math CFLAGS := -fopenmp -Wall -O3 -ffast-math #LIB := -fopenmp -lm -lnuma -LIB := -fopenmp -lm -O3 +LIB := -fopenmp -lm -O3 INC := -I$(INCDIR) -I/usr/local/include -I/usr/local/include/eigen3 INCDEP := -I$(INCDIR) diff --git a/packedForest/src/forestTypes/binnedTree/processingNodeBin.h b/packedForest/src/forestTypes/binnedTree/processingNodeBin.h index f0e7a2e9..e792e2d0 100644 --- a/packedForest/src/forestTypes/binnedTree/processingNodeBin.h +++ b/packedForest/src/forestTypes/binnedTree/processingNodeBin.h @@ -81,7 +81,7 @@ namespace fp{ inline void calcMtryForNode(std::vector& featuresToTry){ featuresToTry.resize(fpSingleton::getSingleton().returnMtry()); int methodToUse = fpSingleton::getSingleton().returnMethodToUse(); - assert(methodToUse == 1 || methodToUse == 2); + assert(methodToUse == 1 || methodToUse == 2 || methodToUse == 3 || methodToUse == 4); switch(methodToUse){ case 1:{ @@ -92,6 +92,13 @@ namespace fp{ randMatImagePatch(featuresToTry, paramsRandMatImagePatch()); break; } + case 3:{ + randMatMultivariateTimePatch(featuresToTry, paramsRandMatImagePatch()); + break; + case 4:{ + randMatMultivariateTimePatchv2(featuresToTry, paramsRandMatImagePatch()); + } + } } } @@ -176,6 +183,80 @@ namespace fp{ } // END randMatStructured + inline void randMatMultivariateTimePatch(std::vector& featuresToTry, std::vector > patchPositions){ + assert((int)(patchPositions[0].size()) == fpSingleton::getSingleton().returnMtry()); + + // Preset parameters + const int& imageHeight = fpSingleton::getSingleton().returnImageHeight(); + const int& imageWidth = fpSingleton::getSingleton().returnImageWidth(); + + std::default_random_engine generator(randNum->gen()); + + int pixelIndex = -1; + for (int k = 0; k < fpSingleton::getSingleton().returnMtry(); k++) { + const int& numRowsInPatch = patchPositions[0][k]; + + // fill with values 0, 1, ..., imageHeight - 1 + std::vector rowInds(imageHeight); + std::iota(std::begin(rowInds), std::end(rowInds), 0); + + // shuffle and select row indices + std::shuffle(rowInds.begin(), rowInds.end(), generator); + std::vector selectedRows(rowInds.begin(), rowInds.begin() + numRowsInPatch); + + assert((int) selectedRows.size() == numRowsInPatch); + + for (int row = 0; row < numRowsInPatch; row++) { + for (int col = 0; col < patchPositions[1][k]; col++) { + pixelIndex = (patchPositions[2][k] % imageWidth) + col + (selectedRows[row] * imageWidth); + featuresToTry[k].returnFeatures().push_back(pixelIndex); + featuresToTry[k].returnWeights().push_back(1); // weight hard-coded to 1. + } + } // Could possibly turn this into one for-loop somehow later. [JLP] + } + } // END randMatStructured + + + inline void randMatMultivariateTimePatchv2(std::vector& featuresToTry, std::vector > patchPositions){ + assert((int)(patchPositions[0].size()) == fpSingleton::getSingleton().returnMtry()); + + // Preset parameters + const int& imageHeight = fpSingleton::getSingleton().returnImageHeight(); + const int& imageWidth = fpSingleton::getSingleton().returnImageWidth(); + + std::default_random_engine generator(randNum->gen()); + + int pixelIndex = -1; + for (int k = 0; k < fpSingleton::getSingleton().returnMtry(); k++) { + const int& numRowsInPatch = patchPositions[0][k]; + const int& numColsInPatch = patchPositions[1][k]; + + // fill with values 0, 1, ..., imageHeight - 1 + std::vector rowInds(imageHeight); + std::iota(std::begin(rowInds), std::end(rowInds), 0); + + // fill with values 0, 1, ..., imageWidth - 1 + std::vector colInds(imageWidth); + std::iota(std::begin(colInds), std::end(colInds), 0); + + // shuffle and select indices + std::shuffle(rowInds.begin(), rowInds.end(), generator); + std::shuffle(colInds.begin(), colInds.end(), generator); + std::vector selectedRows(rowInds.begin(), rowInds.begin() + numRowsInPatch); + std::vector selectedCols(colInds.begin(), colInds.begin() + numColsInPatch); + + assert((int) selectedRows.size() == numRowsInPatch); + + for (int row = 0; row < numRowsInPatch; row++) { + for (int col = 0; col < numColsInPatch; col++) { + pixelIndex = (patchPositions[2][k] % imageWidth) + (selectedCols[col] * imageHeight) + (selectedRows[row] * imageWidth); + featuresToTry[k].returnFeatures().push_back(pixelIndex); + featuresToTry[k].returnWeights().push_back(1); // weight hard-coded to 1. + } + } // Could possibly turn this into one for-loop somehow later. [JLP] + } + } // END randMatStructured + inline void resetLeftNode(){ propertiesOfLeftNode.resetClassTotals(); } diff --git a/packedForest/src/fp.cpp b/packedForest/src/fp.cpp index 580cf94a..5f083283 100644 --- a/packedForest/src/fp.cpp +++ b/packedForest/src/fp.cpp @@ -92,6 +92,33 @@ int main(int argc, char* argv[]) { case 14: forest.setParameter("forestType", "urerf"); break; + case 15: + forest.setParameter("forestType", "binnedBaseTern"); + forest.setParameter("numTreeBins", numCores); + forest.setParameter("methodToUse", 3); + forest.setParameter("imageHeight", 28); + forest.setParameter("imageWidth", 28); + forest.setParameter("patchHeightMax", 5); + forest.setParameter("patchHeightMin", 5); + forest.setParameter("patchWidthMax", 5); + forest.setParameter("patchWidthMin", 5); + std::cout << "\nForcing dataset to be MNIST:\n"; + dataSet = 3; + break; + + case 16: + forest.setParameter("forestType", "binnedBaseTern"); + forest.setParameter("numTreeBins", numCores); + forest.setParameter("methodToUse", 4); + forest.setParameter("imageHeight", 28); + forest.setParameter("imageWidth", 28); + forest.setParameter("patchHeightMax", 5); + forest.setParameter("patchHeightMin", 5); + forest.setParameter("patchWidthMax", 5); + forest.setParameter("patchWidthMin", 5); + std::cout << "\nForcing dataset to be MNIST:\n"; + dataSet = 3; + break; default: std::cout << "unknown alg selected" << std::endl; diff --git a/packedForest/src/fpSingleton/fpInfo.h b/packedForest/src/fpSingleton/fpInfo.h index 26ec4ef4..27d22033 100644 --- a/packedForest/src/fpSingleton/fpInfo.h +++ b/packedForest/src/fpSingleton/fpInfo.h @@ -324,8 +324,8 @@ namespace fp { useRowMajor = (bool)parameterValue; }else if(parameterName == "methodToUse"){ methodToUse = parameterValue; - if(!(methodToUse == 1 || methodToUse == 2)){ - throw std::runtime_error("methodToUse outside allowable parameters {1,2}."); + if(!(methodToUse == 1 || methodToUse == 2 || methodToUse == 3)){ + throw std::runtime_error("methodToUse outside allowable parameters {1,2,3}."); } }else if(parameterName == "imageHeight"){ imageHeight = parameterValue; @@ -363,7 +363,7 @@ namespace fp { std::cout << "seed -> " << seed << "\n"; std::cout << "numTreeBins -> " << numTreeBins << "\n"; - if(methodToUse == 2){ + if(methodToUse == 2 || methodToUse == 3){ std::cout << "imageHeight -> " << imageHeight << "\n"; std::cout << "imageWidth -> " << imageWidth << "\n"; std::cout << "patchHeightMax -> " << patchHeightMax << "\n"; diff --git a/packedForest/src/fpSingleton/fpSingleton.h b/packedForest/src/fpSingleton/fpSingleton.h index 6de961dc..c942ddbf 100644 --- a/packedForest/src/fpSingleton/fpSingleton.h +++ b/packedForest/src/fpSingleton/fpSingleton.h @@ -190,7 +190,7 @@ namespace fp { inline void checkDataDependentParameters(){ // For Structured RerF - if(fpForestInfo.returnMethodToUse() == 2){ + if(fpForestInfo.returnMethodToUse() == 2 || fpForestInfo.returnMethodToUse() == 3){ if((fpSingleton::getSingleton().returnNumFeatures() % fpSingleton::getSingleton().returnImageHeight()) != 0){ throw std::runtime_error("Specified image height is not a multiple of the number of features." ); } diff --git a/packedForest/test/googletest/googletest/build-aux/.keep b/packedForest/test/googletest/googletest/build-aux/.keep old mode 100644 new mode 100755