Made the spacing and columns consistent

This commit is contained in:
RishabhGarg108
2020-11-11 00:19:34 +05:30
parent 8070f12e6e
commit 6914e7b69d
16 changed files with 271 additions and 269 deletions
+4 -4
View File
@@ -66,10 +66,10 @@ namespace math {
* @code
* // This matrix has two columns.
* arma::mat input;
* input << -1.0000 << 0.1429 << arma::endr
* << -0.7143 << 0.4286 << arma::endr
* << -0.4286 << 0.7143 << arma::endr
* << -0.1429 << 1.0000 << arma::endr;
* input = { {-1.0000, 0.1429},
* {-0.7143, 0.4286},
* {-0.4286, 0.7143},
* {-0.1429, 1.0000} };
*
* arma::mat output;
* ColumnsToBlocks ctb(1, 2);
+3 -3
View File
@@ -46,9 +46,9 @@ TEST_CASE("BinarizeOneDimension", "[BinarizeTest]")
TEST_CASE("BinerizeAll", "[BinarizeTest]")
{
mat input;
input = { {1, 2, 3},
{4, 5, 6}, // this row will be tested
{7, 8, 9} };
input = { { 1, 2, 3 },
{ 4, 5, 6 }, // this row will be tested
{ 7, 8, 9 } };
mat output;
const double threshold = 5.0;
+66 -66
View File
@@ -124,17 +124,17 @@ TEST_CASE("ValidConvolution2DTest", "[ConvolutionTest]")
{
// Generate dataset for convolution function tests.
arma::mat input, filter, output;
input = { {1, 2, 3, 4},
{4, 1, 2, 3},
{3, 4, 1, 2},
{2, 3, 4, 1} };
input = { { 1, 2, 3, 4 },
{ 4, 1, 2, 3 },
{ 3, 4, 1, 2 },
{ 2, 3, 4, 1 } };
filter = { {1, 0, -1},
{0, 1, 0},
{-1, 0, 1} };
filter = { { 1, 0, -1 },
{ 0, 1, 0 },
{ -1, 0, 1 } };
output = { {-3, -2},
{8, -3} };
output = { { -3, -2 },
{ 8, -3 } };
// Perform the naive convolution approach.
Convolution2DMethodTest<NaiveConvolution<ValidConvolution> >(input, filter,
@@ -157,21 +157,21 @@ TEST_CASE("FullConvolution2DTest", "[ConvolutionTest]")
{
// Generate dataset for convolution function tests.
arma::mat input, filter, output;
input = { {1, 2, 3, 4},
{4, 1, 2, 3},
{3, 4, 1, 2},
{2, 3, 4, 1} };
input = { { 1, 2, 3, 4 },
{ 4, 1, 2, 3 },
{ 3, 4, 1, 2 },
{ 2, 3, 4, 1 } };
filter = { {1, 0, -1},
{1, 1, 1},
{-1, 0, 1} };
filter = { { 1, 0, -1 },
{ 1, 1, 1 },
{ -1, 0, 1 } };
output = { {1, 2, 2, 2, -3, -4},
{5, 4, 4, 11, 5, 1},
{6, 7, 3, 2, 7, 5},
{1, 9, 12, 3, 1, 4},
{-1, 1, 11, 10, 6, 3},
{-2, -3, -2, 2, 4, 1} };
output = { { 1, 2, 2, 2, -3, -4 },
{ 5, 4, 4, 11, 5, 1 },
{ 6, 7, 3, 2, 7, 5 },
{ 1, 9, 12, 3, 1, 4 },
{ -1, 1, 11, 10, 6, 3 },
{ -2, -3, -2, 2, 4, 1 } };
// Perform the naive convolution approach.
Convolution2DMethodTest<NaiveConvolution<FullConvolution> >(input, filter,
@@ -194,17 +194,17 @@ TEST_CASE("ValidConvolution3DTest", "[ConvolutionTest]")
{
// Generate dataset for convolution function tests.
arma::mat input, filter, output;
input = { {1, 2, 3, 4},
{4, 1, 2, 3},
{3, 4, 1, 2},
{2, 3, 4, 1} };
input = { { 1, 2, 3, 4 },
{ 4, 1, 2, 3 },
{ 3, 4, 1, 2 },
{ 2, 3, 4, 1 } };
filter = { {1, 0, -1},
{0, 1, 0},
{-1, 0, 1} };
filter = { { 1, 0, -1 },
{ 0, 1, 0 },
{ -1, 0, 1 } };
output = { {-3, -2},
{8, -3} };
output = { { -3, -2 },
{ 8, -3 } };
arma::cube inputCube(input.n_rows, input.n_cols, 2);
inputCube.slice(0) = input;
@@ -239,21 +239,21 @@ TEST_CASE("FullConvolution3DTest", "[ConvolutionTest]")
{
// Generate dataset for convolution function tests.
arma::mat input, filter, output;
input = { {1, 2, 3, 4},
{4, 1, 2, 3},
{3, 4, 1, 2},
{2, 3, 4, 1} };
input = { { 1, 2, 3, 4 },
{ 4, 1, 2, 3 },
{ 3, 4, 1, 2 },
{ 2, 3, 4, 1 } };
filter = { {1, 0, -1},
{1, 1, 1},
{-1, 0, 1} };
filter = { { 1, 0, -1 },
{ 1, 1, 1 },
{ -1, 0, 1 } };
output = { {1, 2, 2, 2, -3, -4},
{5, 4, 4, 11, 5, 1},
{6, 7, 3, 2, 7, 5},
{1, 9, 12, 3, 1, 4},
{-1, 1, 11, 10, 6, 3},
{-2, -3, -2, 2, 4, 1} };
output = { { 1, 2, 2, 2, -3, -4 },
{ 5, 4, 4, 11, 5, 1 },
{ 6, 7, 3, 2, 7, 5 },
{ 1, 9, 12, 3, 1, 4 },
{ -1, 1, 11, 10, 6, 3 },
{ -2, -3, -2, 2, 4, 1 } };
arma::cube inputCube(input.n_rows, input.n_cols, 2);
inputCube.slice(0) = input;
@@ -289,17 +289,17 @@ TEST_CASE("ValidConvolutionBatchTest", "[ConvolutionTest]")
{
// Generate dataset for convolution function tests.
arma::mat input, filter, output;
input = { {1, 2, 3, 4},
{4, 1, 2, 3},
{3, 4, 1, 2},
{2, 3, 4, 1} };
input = { { 1, 2, 3, 4 },
{ 4, 1, 2, 3 },
{ 3, 4, 1, 2 },
{ 2, 3, 4, 1 } };
filter = { {1, 0, -1},
{0, 1, 0},
{-1, 0, 1} };
filter = { { 1, 0, -1 },
{ 0, 1, 0 },
{ -1, 0, 1 } };
output = { {-3, -2},
{8, -3} };
output = { { -3, -2 },
{ 8, -3 } };
arma::cube filterCube(filter.n_rows, filter.n_cols, 2);
filterCube.slice(0) = filter;
@@ -331,21 +331,21 @@ TEST_CASE("FullConvolutionBatchTest", "[ConvolutionTest]")
{
// Generate dataset for convolution function tests.
arma::mat input, filter, output;
input = { {1, 2, 3, 4},
{4, 1, 2, 3},
{3, 4, 1, 2},
{2, 3, 4, 1} };
input = { { 1, 2, 3, 4 },
{ 4, 1, 2, 3 },
{ 3, 4, 1, 2 },
{ 2, 3, 4, 1 } };
filter = { {1, 0, -1},
{1, 1, 1},
{-1, 0, 1} };
filter = { { 1, 0, -1 },
{ 1, 1, 1 },
{ -1, 0, 1 } };
output = { {1, 2, 2, 2, -3, -4},
{5, 4, 4, 11, 5, 1},
{6, 7, 3, 2, 7, 5},
{1, 9, 12, 3, 1, 4},
{-1, 1, 11, 10, 6, 3},
{-2, -3, -2, 2, 4, 1} };
output = { { 1, 2, 2, 2, -3, -4 },
{ 5, 4, 4, 11, 5, 1 },
{ 6, 7, 3, 2, 7, 5 },
{ 1, 9, 12, 3, 1, 4 },
{ -1, 1, 11, 10, 6, 3 },
{ -2, -3, -2, 2, 4, 1 } };
arma::cube filterCube(filter.n_rows, filter.n_cols, 2);
filterCube.slice(0) = filter;
+4 -4
View File
@@ -750,10 +750,10 @@ TEST_CASE("KFoldCVWithDTTestUnevenBinsWeighted", "[CVTest]")
TEST_CASE("SilhouetteScoreTest", "[CVTest]")
{
arma::mat X;
X = { {0, 1, 1, 0, 0},
{0, 1, 2, 0, 0},
{1, 1, 3, 2, 0} };
arma::Row<size_t> labels = {0, 1, 2, 0, 0};
X = { { 0, 1, 1, 0, 0 },
{ 0, 1, 2, 0, 0 },
{ 1, 1, 3, 2, 0 } };
arma::Row<size_t> labels = { 0, 1, 2, 0, 0 };
metric::EuclideanDistance metric;
double silhouetteScore = SilhouetteScore::Overall(X, labels, metric);
REQUIRE(silhouetteScore == Approx(0.1121684822489150).epsilon(1e-7));
+31 -31
View File
@@ -30,16 +30,16 @@ TEST_CASE("OneClass", "[DecisionStumpTest]")
const size_t inpBucketSize = 6;
mat trainingData;
trainingData = { {2.4, 3.8, 3.8},
{1, 1, 2},
{1.3, 1.9, 1.3} };
trainingData = { { 2.4, 3.8, 3.8 },
{ 1, 1, 2 },
{ 1.3, 1.9, 1.3 } };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {1, 1, 1};
labelsIn = { 1, 1, 1 };
mat testingData;
testingData = {2.4, 2.5, 2.6};
testingData = { 2.4, 2.5, 2.6 };
DecisionStump<> ds(trainingData, labelsIn.row(0), numClasses, inpBucketSize);
@@ -65,13 +65,13 @@ TEST_CASE("CorrectDimensionChosen", "[DecisionStumpTest]")
// found on page 176 (and a description of the correct splitting dimension is
// given below that).
mat trainingData;
trainingData = { {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2},
{70, 90, 85, 95, 70, 90, 78, 65, 75, 80, 70, 80, 80, 96},
{1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0} };
trainingData = { { 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2 },
{ 70, 90, 85, 95, 70, 90, 78, 65, 75, 80, 70, 80, 80, 96 },
{ 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0 } };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0};
labelsIn = { 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 };
DecisionStump<> ds(trainingData, labelsIn.row(0), numClasses, inpBucketSize);
@@ -92,14 +92,14 @@ TEST_CASE("PerfectSplitOnZero", "[DecisionStumpTest]")
const size_t inpBucketSize = 2;
mat trainingData;
trainingData = {-1, 1, -2, 2, -3, 3};
trainingData = { -1, 1, -2, 2, -3, 3 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 1, 0, 1, 0, 1};
labelsIn = { 0, 1, 0, 1, 0, 1 };
mat testingData;
testingData = {-4, 7, -7, -5, 6};
testingData = { -4, 7, -7, -5, 6 };
DecisionStump<> ds(trainingData, labelsIn.row(0), numClasses, inpBucketSize);
@@ -123,11 +123,11 @@ TEST_CASE("BinningTesting", "[DecisionStumpTest]")
const size_t inpBucketSize = 10;
mat trainingData;
trainingData = {-1, 1, -2, 2, -3, 3, -4};
trainingData = { -1, 1, -2, 2, -3, 3, -4 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 1, 0, 1, 0, 1, 0};
labelsIn = { 0, 1, 0, 1, 0, 1, 0 };
mat testingData;
testingData = {5};
@@ -151,14 +151,14 @@ TEST_CASE("PerfectMultiClassSplit", "[DecisionStumpTest]")
const size_t inpBucketSize = 3;
mat trainingData;
trainingData = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};
trainingData = { -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3};
labelsIn = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 };
mat testingData;
testingData = {-6.1, -2.1, 1.1, 5.1};
testingData = { -6.1, -2.1, 1.1, 5.1 };
DecisionStump<> ds(trainingData, labelsIn.row(0), numClasses, inpBucketSize);
@@ -183,16 +183,16 @@ TEST_CASE("MultiClassSplit", "[DecisionStumpTest]")
const size_t inpBucketSize = 3;
mat trainingData;
trainingData = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10};
trainingData = { -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2};
labelsIn = { 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2 };
mat testingData;
testingData = {-6.1, -5.9, -2.1, -0.7, 2.5, 4.7, 7.2, 9.1};
testingData = { -6.1, -5.9, -2.1, -0.7, 2.5, 4.7, 7.2, 9.1 };
DecisionStump<> ds(trainingData, labelsIn.row(0), numClasses, inpBucketSize);
@@ -320,16 +320,16 @@ TEST_CASE("EmptyConstructorTest", "[DecisionStumpTest]")
// Now train on another dataset and make sure something kind of makes sense.
mat trainingData;
trainingData = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10};
trainingData = { -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2};
labelsIn = { 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2 };
mat testingData;
testingData = {-6.1, -5.9, -2.1, -0.7, 2.5, 4.7, 7.2, 9.1};
testingData = { -6.1, -5.9, -2.1, -0.7, 2.5, 4.7, 7.2, 9.1 };
DecisionStump<> ds(trainingData, labelsIn.row(0), 4, 3);
@@ -354,17 +354,17 @@ TEST_CASE("IntTest", "[DecisionStumpTest]")
{
// Train on a dataset and make sure something kind of makes sense.
imat trainingData;
trainingData = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10};
trainingData = { -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2};
labelsIn = { 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 2 };
DecisionStump<arma::imat> ds(trainingData, labelsIn.row(0), 4, 3);
imat testingData;
testingData = {-6, -6, -2, -1, 3, 5, 7, 9};
testingData = { -6, -6, -2, -1, 3, 5, 7, 9 };
arma::Row<size_t> predictedLabels;
ds.Classify(testingData, predictedLabels);
@@ -388,11 +388,11 @@ TEST_CASE("DecisionStumpTrainReturnEntropy", "[DecisionStumpTest]")
const size_t inpBucketSize = 2;
mat trainingData;
trainingData = {-1, 1, -2, 2, -3, 3};
trainingData = { -1, 1, -2, 2, -3, 3 };
// No need to normalize labels here.
Mat<size_t> labelsIn;
labelsIn = {0, 1, 0, 1, 0, 1};
labelsIn = { 0, 1, 0, 1, 0, 1 };
arma::Row<double> weights = arma::ones<arma::Row<double>>(labelsIn.n_elem);
+69 -69
View File
@@ -40,9 +40,9 @@ TEST_CASE("TestGetMaxMinVals", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
DTree<arma::mat> tree(testData);
@@ -81,11 +81,11 @@ TEST_CASE("TestWithinRange", "[DETTest]")
DTree<arma::mat> testDTree(maxVals, minVals, 5);
arma::vec testQuery(3);
testQuery = {4.5, 2.5, 2};
testQuery = { 4.5, 2.5, 2 };
REQUIRE(testDTree.WithinRange(testQuery) == true);
testQuery = {8.5, 2.5, 2};
testQuery = { 8.5, 2.5, 2 };
REQUIRE(testDTree.WithinRange(testQuery) == false);
}
@@ -94,9 +94,9 @@ TEST_CASE("TestFindSplit", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
DTree<arma::mat> testDTree(testData);
@@ -124,14 +124,14 @@ TEST_CASE("TestSplitData", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
DTree<arma::mat> testDTree(testData);
arma::Col<size_t> oTest(5);
oTest = {1, 2, 3, 4, 5};
oTest = { 1, 2, 3, 4, 5 };
size_t splitDim = 2;
double trueSplitVal = 5.5;
@@ -152,10 +152,10 @@ TEST_CASE("TestSparseFindSplit", "[DETTest]")
{
arma::mat realData(4, 7);
realData = { {.0, 4, 5, 7, 0, 5, 0},
{.0, 5, 0, 0, 1, 7, 1},
{.0, 5, 6, 7, 1, 0, 8},
{-1, 2, 5, 0, 0, 0, 0} };
realData = { { .0, 4, 5, 7, 0, 5, 0 },
{ .0, 5, 0, 0, 1, 7, 1 },
{ .0, 5, 6, 7, 1, 0, 8 },
{ -1, 2, 5, 0, 0, 0, 0 } };
arma::sp_mat testData(realData);
@@ -186,17 +186,17 @@ TEST_CASE("TestSparseSplitData", "[DETTest]")
{
arma::mat realData(4, 7);
realData = { {.0, 4, 5, 7, 0, 5, 0},
{.0, 5, 0, 0, 1, 7, 1},
{.0, 5, 6, 7, 1, 0, 8},
{-1, 2, 5, 0, 0, 0, 0} };
realData = { { .0, 4, 5, 7, 0, 5, 0 },
{ .0, 5, 0, 0, 1, 7, 1 },
{ .0, 5, 6, 7, 1, 0, 8 },
{ -1, 2, 5, 0, 0, 0, 0 } };
arma::sp_mat testData(realData);
DTree<arma::sp_mat> testDTree(testData);
arma::Col<size_t> oTest(7);
oTest = {1, 2, 3, 4, 5, 6, 7};
oTest = { 1, 2, 3, 4, 5, 6, 7 };
size_t splitDim = 1;
double trueSplitVal = .5;
@@ -223,12 +223,12 @@ TEST_CASE("TestGrow", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
double rootError, lError, rError, rlError, rrError;
@@ -289,9 +289,9 @@ TEST_CASE("TestPruneAndUpdate", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
@@ -315,19 +315,19 @@ TEST_CASE("TestComputeValue", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
arma::vec q1(3), q2(3), q3(3), q4(3);
q1 = {4, 2, 2};
q2 = {5, 0.25, 6};
q3 = {5, 3, 7};
q4 = {2, 3, 3};
q1 = { 4, 2, 2 };
q2 = { 5, 0.25, 6 };
q3 = { 5, 3, 7 };
q4 = { 2, 3, 3 };
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
DTree<arma::mat> testDTree(testData);
double alpha = testDTree.Grow(testData, oTest, false, 2, 1);
@@ -355,9 +355,9 @@ TEST_CASE("TestVariableImportance", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
double rootError, lError, rError, rlError, rrError;
@@ -370,7 +370,7 @@ TEST_CASE("TestVariableImportance", "[DETTest]")
rrError = -1.0 * exp(2 * log(2.0 / 5.0) - (log(6.5) + log(4.0) + log(2.5)));
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
DTree<arma::mat> testDTree(testData);
testDTree.Grow(testData, oTest, false, 2, 1);
@@ -390,14 +390,14 @@ TEST_CASE("TestSparsePruneAndUpdate", "[DETTest]")
{
arma::mat realData(3, 5);
realData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
realData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
arma::sp_mat testData(realData);
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
DTree<arma::sp_mat> testDTree(testData);
double alpha = testDTree.Grow(testData, oTest, false, 2, 1);
@@ -419,22 +419,22 @@ TEST_CASE("TestSparseComputeValue", "[DETTest]")
{
arma::mat realData(3, 5);
realData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
realData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
arma::vec q1d(3), q2d(3), q3d(3), q4d(3);
q1d = {4, 2, 2};
q2d = {5, 0.25, 6};
q3d = {5, 3, 7};
q4d = {2, 3, 3};
q1d = { 4, 2, 2 };
q2d = { 5, 0.25, 6 };
q3d = { 5, 3, 7 };
q4d = { 2, 3, 3 };
arma::sp_mat testData(realData);
arma::sp_vec q1(q1d), q2(q2d), q3(q3d), q4(q4d);
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
DTree<arma::sp_mat> testDTree(testData);
double alpha = testDTree.Grow(testData, oTest, false, 2, 1);
@@ -465,9 +465,9 @@ TEST_CASE("TestTagTree", "[DETTest]")
{
MatType testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
DTree<>* testDTree = new DTree<>(&testData);
@@ -478,9 +478,9 @@ TEST_CASE("TestFindBucket", "[DETTest]")
{
MatType testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
DTree<>* testDTree = new DTree<>(&testData);
@@ -510,13 +510,13 @@ TEST_CASE("CopyConstructorAndOperatorTest", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
// Construct another DTree for testing the children.
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
DTree<arma::mat> *testDTree = new DTree<arma::mat>(testData);
testDTree->Grow(testData, oTest, false, 2, 1);
@@ -622,13 +622,13 @@ TEST_CASE("MoveConstructorTest", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
// Construct another DTree for testing the children.
arma::Col<size_t> oTest(5);
oTest = {0, 1, 2, 3, 4};
oTest = { 0, 1, 2, 3, 4 };
DTree<arma::mat> *testDTree = new DTree<arma::mat>(testData);
testDTree->Grow(testData, oTest, false, 2, 1);
@@ -705,9 +705,9 @@ TEST_CASE("MoveOperatorTest", "[DETTest]")
{
arma::mat testData(3, 5);
testData = { {4, 5, 7, 3, 5},
{5, 0, 1, 7, 1},
{5, 6, 7, 1, 8} };
testData = { { 4, 5, 7, 3, 5 },
{ 5, 0, 1, 7, 1 },
{ 5, 6, 7, 1, 8 } };
// Construct another DTree for testing the children.
arma::Col<size_t> oTest(5);
+4 -4
View File
@@ -981,8 +981,8 @@ TEST_CASE("GammaDistributionProbabilityTest", "[DistributionTest]")
// Combine into one 2-dimensional distribution.
const arma::vec a3("2.0 3.1"), b3("0.9 1.4");
arma::mat x3(2, 2);
x3 = { {2.0, 2.94},
{2.0, 2.94} };
x3 = { { 2.0, 2.94 },
{ 2.0, 2.94 } };
arma::vec prob3;
// Expect that the 2-dimensional distribution returns the product of the
@@ -1017,8 +1017,8 @@ TEST_CASE("GammaDistributionLogProbabilityTest", "[DistributionTest]")
// Combine into one 2-dimensional distribution.
const arma::vec a3("2.0 3.1"), b3("0.9 1.4");
arma::mat x3(2, 2);
x3 = { {2.0, 2.94},
{2.0, 2.94} };
x3 = { { 2.0, 2.94 },
{ 2.0, 2.94 } };
arma::vec logprob3;
// Expect that the 2-dimensional distribution returns the product of the
+3 -3
View File
@@ -47,9 +47,9 @@ BOOST_AUTO_TEST_CASE(AssertSizesTest)
BOOST_AUTO_TEST_CASE(PairwiseDistanceTest)
{
arma::mat X;
X = { {0, 1, 1, 0, 0},
{0, 1, 2, 0, 0},
{1, 1, 3, 2, 0} };
X = { { 0, 1, 1, 0, 0 },
{ 0, 1, 2, 0, 0 },
{ 1, 1, 3, 2, 0 } };
metric::EuclideanDistance metric;
arma::mat dist = PairwiseDistances(X, metric);
BOOST_REQUIRE_EQUAL(dist(0, 0), 0);
+4 -4
View File
@@ -73,8 +73,8 @@ TEST_CASE("LinearRegressionTestCase", "[LinearRegressionTest]")
TEST_CASE("ComputeErrorTest", "[LinearRegressionTest]")
{
arma::mat predictors;
predictors = { {0, 1, 2, 4, 8, 16},
{16, 8, 4, 2, 1, 0} };
predictors = { { 0, 1, 2, 4, 8, 16 },
{ 16, 8, 4, 2, 1, 0 } };
arma::rowvec responses = "0 2 4 3 8 8";
// http://www.mlpack.org/trac/ticket/298
@@ -92,8 +92,8 @@ TEST_CASE("ComputeErrorPerfectFitTest", "[LinearRegressionTest]")
{
// Linear regression should perfectly model this dataset.
arma::mat predictors;
predictors = { {0, 1, 2, 1, 6, 2},
{0, 1, 2, 2, 2, 6} };
predictors = { { 0, 1, 2, 1, 6, 2 },
{ 0, 1, 2, 2, 2, 6 } };
arma::rowvec responses = "0 2 4 3 8 8";
LinearRegression lr(predictors, responses);
@@ -1011,9 +1011,9 @@ BOOST_AUTO_TEST_CASE(ConstructionThenTraining)
arma::mat myMatrix;
// Four points, three dimensions.
myMatrix = { {0.555950, 0.274690, 0.540605, 0.798938},
{0.948014, 0.973234, 0.216504, 0.883152},
{0.023787, 0.675382, 0.231751, 0.450332} };
myMatrix = { { 0.555950, 0.274690, 0.540605, 0.798938 },
{ 0.948014, 0.973234, 0.216504, 0.883152 },
{ 0.023787, 0.675382, 0.231751, 0.450332 } };
arma::Row<size_t> myTargets("1 0 1 0");
+13 -13
View File
@@ -39,16 +39,16 @@ void GetPointset(const size_t N, arma::mat& rdata)
arma::mat c4(d, N / 4, arma::fill::randu);
arma::colvec offset1;
offset1 = { {0},
{3} };
offset1 = { { 0 },
{ 3 } };
arma::colvec offset2;
offset2 = { {3},
{3} };
offset2 = { { 3 },
{ 3 } };
arma::colvec offset4;
offset4 = { {3},
{0} };
offset4 = { { 3 },
{ 0 } };
// Spread points in plane.
for (size_t p = 0; p < N / 4; ++p)
@@ -132,8 +132,8 @@ BOOST_AUTO_TEST_CASE(NumTablesTest)
fail = false;
const int lSize = 6; // Number of runs.
const int lValue[] = {1, 8, 16, 32, 64, 128}; // Number of tables.
double lValueRecall[lSize] = {0.0}; // Recall of each LSH run.
const int lValue[] = { 1, 8, 16, 32, 64, 128 }; // Number of tables.
double lValueRecall[lSize] = { 0.0 }; // Recall of each LSH run.
for (size_t l = 0; l < lSize; ++l)
{
@@ -198,8 +198,8 @@ BOOST_AUTO_TEST_CASE(HashWidthTest)
arma::mat groundDistances;
knn.Search(qdata, k, groundTruth, groundDistances);
const int hSize = 7; // Number of runs.
const double hValue[] = {0.1, 0.5, 1, 5, 10, 50, 500}; // Hash width.
double hValueRecall[hSize] = {0.0}; // Recall of each run.
const double hValue[] = { 0.1, 0.5, 1, 5, 10, 50, 500 }; // Hash width.
double hValueRecall[hSize] = { 0.0 }; // Recall of each run.
for (size_t h = 0; h < hSize; ++h)
{
@@ -260,8 +260,8 @@ BOOST_AUTO_TEST_CASE(NumProjTest)
// LSH test parameters for numProj.
const int pSize = 5; // Number of runs.
const int pValue[] = {1, 10, 20, 50, 100}; // Number of projections.
double pValueRecall[pSize] = {0.0}; // Recall of each run.
const int pValue[] = { 1, 10, 20, 50, 100 }; // Number of projections.
double pValueRecall[pSize] = { 0.0 }; // Recall of each run.
for (size_t p = 0; p < pSize; ++p)
{
@@ -490,7 +490,7 @@ BOOST_AUTO_TEST_CASE(MultiprobeTest)
const size_t repetitions = 5; // Train five objects.
const size_t probeTrials = 5;
const size_t numProbes[probeTrials] = {0, 1, 2, 3, 4};
const size_t numProbes[probeTrials] = { 0, 1, 2, 3, 4 };
// Algorithm parameters.
const int k = 4;
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(LRNoTrainingData)
{
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
SetInputParam("labels", std::move(trainY));
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(LRPridictionSizeCheck)
arma::mat trainX = arma::randu<arma::mat>(D, N);
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
arma::mat testX = arma::randu<arma::mat>(D, M);
SetInputParam("training", std::move(trainX));
@@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(LRWrongResponseSizeTest)
arma::Row<size_t> trainY; // Response vector with wrong size.
// 8 responses - incorrect size.
trainY = {0, 0, 1, 0, 1, 1, 1, 0};
trainY = { 0, 0, 1, 0, 1, 1, 1, 0 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(LRModelReload)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
arma::mat testX = arma::randu<arma::mat>(D, M);
@@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(LRWrongDimOfTestData)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
// Test data with wrong dimensionality.
arma::mat testX = arma::randu<arma::mat>(D-1, N);
@@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(LRWrongDimOfTestData2)
arma::mat trainX = arma::randu<arma::mat>(D, N);
arma::Row<size_t> trainY;
// 10 responses
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(LRTrainWithMoreThanTwoClasses)
arma::Row<size_t> trainY;
// 8 responses containing more than two classes.
trainY = {0, 1, 0, 1, 2, 1, 3, 1};
trainY = { 0, 1, 0, 1, 2, 1, 3, 1 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(LRNonNegativeMaxIterationTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE(LRNonNegativeStepSizeTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
trainY = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(LRNonNegativeToleranceTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {1, 1, 0, 1, 0, 0, 0, 1, 0, 1};
trainY = { 1, 1, 0, 1, 0, 0, 0, 1, 0, 1 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -405,7 +405,7 @@ BOOST_AUTO_TEST_CASE(LRMaxIterationsChangeTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {1, 0, 0, 1, 0, 1, 0, 1, 0, 1};
trainY = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 1 };
SetInputParam("training", trainX);
SetInputParam("labels", trainY);
@@ -454,7 +454,7 @@ BOOST_AUTO_TEST_CASE(LRLambdaChangeTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {1, 0, 0, 1, 0, 1, 0, 1, 0, 1};
trainY = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 1 };
SetInputParam("training", trainX);
SetInputParam("labels", trainY);
@@ -503,7 +503,7 @@ BOOST_AUTO_TEST_CASE(LRStepSizeChangeTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {1, 0, 0, 1, 0, 1, 0, 1, 0, 1};
trainY = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 1 };
SetInputParam("training", trainX);
SetInputParam("labels", trainY);
@@ -554,7 +554,7 @@ BOOST_AUTO_TEST_CASE(LROptimizerChangeTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {1, 0, 0, 1, 0, 1, 0, 1, 0, 1};
trainY = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 1 };
SetInputParam("training", trainX);
SetInputParam("labels", trainY);
@@ -606,7 +606,7 @@ BOOST_AUTO_TEST_CASE(LRDecisionBoundaryTest)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {1, 0, 0, 1, 0, 1, 0, 1, 0, 1};
trainY = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 1 };
arma::mat testX = arma::randu<arma::mat>(D, M);
@@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(PerceptronReTrainWithWrongClasses)
arma::Row<size_t> labelsX2;
// 10 responses.
labelsX2 = {0, 1, 4, 1, 2, 1, 0, 3, 3, 0};
labelsX2 = { 0, 1, 4, 1, 2, 1, 0, 3, 3, 0 };
// Last column of trainX2 contains the class labels.
SetInputParam("training", std::move(trainX2));
@@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(PerceptronWrongDimOfTestData)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0 , 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0 , 1, 0, 1, 1, 1, 0, 1, 0, 0 };
// Test data with wrong dimensionality.
arma::mat testX = arma::randu<arma::mat>(D-3, M);
@@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(PerceptronWrongResponseSizeTest)
arma::Row<size_t> trainY; // Response vector with wrong size.
// 8 responses.
trainY = {0, 0, 1, 0, 1, 1, 1, 0};
trainY = { 0, 0, 1, 0, 1, 1, 1, 0 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
@@ -395,7 +395,7 @@ BOOST_AUTO_TEST_CASE(PerceptronNoResponsesTest)
BOOST_AUTO_TEST_CASE(PerceptronNoTrainingDataTest)
{
arma::Row<size_t> trainY;
trainY = {1, 1, 0, 1, 0, 0};
trainY = { 1, 1, 0, 1, 0, 0 };
SetInputParam("labels", std::move(trainY));
@@ -418,7 +418,7 @@ BOOST_AUTO_TEST_CASE(PerceptronWrongDimOfTestData2)
arma::Row<size_t> trainY;
// 10 responses.
trainY = {0, 1, 0, 1, 1, 1, 0, 1, 0, 0};
trainY = { 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 };
SetInputParam("training", std::move(trainX));
SetInputParam("labels", std::move(trainY));
+10 -8
View File
@@ -53,10 +53,10 @@ BOOST_AUTO_TEST_CASE(ColumnToBlocksEvaluate)
ctb.Transform(CreateMaximalInput(), output);
arma::mat matlabResults;
matlabResults = { {-1, -1, -1, -1, -1, -1, -1},
{-1, -1, -0.42857, -1, 0.14286, 0.71429, -1},
{-1, -0.71429, -0.14286, -1, 0.42857, 1, -1},
{-1, -1, -1, -1, -1, -1, -1} };
matlabResults = { { -1, -1, -1, -1, -1, -1, -1 },
{ -1, -1, -0.42857, -1, 0.14286, 0.71429, -1 },
{ -1, -0.71429, -0.14286, -1, 0.42857, 1, -1 },
{ -1, -1, -1, -1, -1, -1, -1 } };
TestResults(output, matlabResults);
}
@@ -71,10 +71,12 @@ BOOST_AUTO_TEST_CASE(ColumnToBlocksChangeBlockSize)
ctb.Transform(CreateMaximalInput(), output);
arma::mat matlabResults;
matlabResults = { {-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3},
{-3, -1, -0.71429, -0.42857, -0.14286, -3, 0.14286,
0.42857, 0.71429, 1, -3},
{-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3} };
matlabResults = { { -3, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -3 },
{ -3, -1, -0.71429, -0.42857, -0.14286, -3, 0.14286,
0.42857, 0.71429, 1, -3 },
{ -3, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -3 } };
TestResults(output, matlabResults);
}
+28 -28
View File
@@ -110,16 +110,16 @@ TEST_CASE("SimpleWeightUpdateInstanceWeight", "[PerceptronTest]")
TEST_CASE("And", "[PerceptronTest]")
{
mat trainData;
trainData = { {0, 1, 1, 0},
{1, 0, 1, 0} };
trainData = { { 0, 1, 1, 0 },
{ 1, 0, 1, 0 } };
Mat<size_t> labels;
labels = {0, 0, 1, 0};
labels = { 0, 0, 1, 0 };
Perceptron<> p(trainData, labels.row(0), 2, 1000);
mat testData;
testData = { {0, 1, 1, 0},
{1, 0, 1, 0} };
testData = { { 0, 1, 1, 0 },
{ 1, 0, 1, 0 } };
Row<size_t> predictedLabels(testData.n_cols);
p.Classify(testData, predictedLabels);
@@ -135,17 +135,17 @@ TEST_CASE("And", "[PerceptronTest]")
TEST_CASE("Or", "[PerceptronTest]")
{
mat trainData;
trainData = { {0, 1, 1, 0},
{1, 0, 1, 0} };
trainData = { { 0, 1, 1, 0 },
{ 1, 0, 1, 0 } };
Mat<size_t> labels;
labels = {1, 1, 1, 0};
labels = { 1, 1, 1, 0 };
Perceptron<> p(trainData, labels.row(0), 2, 1000);
mat testData;
testData = { {0, 1, 1, 0},
{1, 0, 1, 0} };
testData = { { 0, 1, 1, 0 },
{ 1, 0, 1, 0 } };
Row<size_t> predictedLabels(testData.n_cols);
p.Classify(testData, predictedLabels);
@@ -162,17 +162,17 @@ TEST_CASE("Or", "[PerceptronTest]")
TEST_CASE("Random3", "[PerceptronTest]")
{
mat trainData;
trainData = { {0, 1, 1, 4, 5, 4, 1, 2, 1},
{1, 0, 1, 1, 1, 2, 4, 5, 4} };
trainData = { { 0, 1, 1, 4, 5, 4, 1, 2, 1 },
{ 1, 0, 1, 1, 1, 2, 4, 5, 4 } };
Mat<size_t> labels;
labels = {0, 0, 0, 1, 1, 1, 2, 2, 2};
labels = { 0, 0, 0, 1, 1, 1, 2, 2, 2 };
Perceptron<> p(trainData, labels.row(0), 3, 1000);
mat testData;
testData = { {0, 1, 1},
{1, 0, 1} };
testData = { { 0, 1, 1 },
{ 1, 0, 1 } };
Row<size_t> predictedLabels(testData.n_cols);
p.Classify(testData, predictedLabels);
@@ -187,17 +187,17 @@ TEST_CASE("Random3", "[PerceptronTest]")
TEST_CASE("TwoPoints", "[PerceptronTest]")
{
mat trainData;
trainData = { {0, 1},
{1, 0} };
trainData = { { 0, 1 },
{ 1, 0 } };
Mat<size_t> labels;
labels = {0, 1};
labels = { 0, 1 };
Perceptron<> p(trainData, labels.row(0), 2, 1000);
mat testData;
testData = { {0, 1},
{1, 0} };
testData = { { 0, 1 },
{ 1, 0 } };
Row<size_t> predictedLabels(testData.n_cols);
p.Classify(testData, predictedLabels);
@@ -212,17 +212,17 @@ TEST_CASE("TwoPoints", "[PerceptronTest]")
TEST_CASE("NonLinearlySeparableDataset", "[PerceptronTest]")
{
mat trainData;
trainData = { {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8},
{1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2} };
trainData = { { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 } };
Mat<size_t> labels;
labels = {0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1};
labels = { 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1 };
Perceptron<> p(trainData, labels.row(0), 2, 1000);
mat testData;
testData = { {3, 4, 5, 6},
{3, 2.3, 1.7, 1.5} };
testData = { { 3, 4, 5, 6 },
{ 3, 2.3, 1.7, 1.5 } };
Row<size_t> predictedLabels(testData.n_cols);
p.Classify(testData, predictedLabels);
@@ -235,11 +235,11 @@ TEST_CASE("NonLinearlySeparableDataset", "[PerceptronTest]")
TEST_CASE("SecondaryConstructor", "[PerceptronTest]")
{
mat trainData;
trainData = { {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8},
{1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2} };
trainData = { { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 } };
Mat<size_t> labels;
labels = {0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1};
labels = { 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1 };
Perceptron<> p1(trainData, labels.row(0), 2, 1000);
+9 -9
View File
@@ -309,7 +309,7 @@ template<typename MatType>
void ReberReverseTranslation(const MatType& translation, char& symbol)
{
arma::Col<char> symbols;
symbols = {'B', 'T', 'S', 'X', 'P', 'V', 'E'};
symbols = { 'B', 'T', 'S', 'X', 'P', 'V', 'E' };
const int idx = arma::as_scalar(arma::find(translation == 1, 1, "first"));
symbol = symbols(idx);
@@ -324,7 +324,7 @@ void ReberReverseTranslation(const MatType& translation, char& symbol)
void ReberTranslation(const char symbol, arma::colvec& translation)
{
arma::Col<char> symbols;
symbols = {'B', 'T', 'S', 'X', 'P', 'V', 'E'};
symbols = { 'B', 'T', 'S', 'X', 'P', 'V', 'E' };
const int idx = arma::as_scalar(arma::find(symbols == symbol, 1, "first"));
translation = arma::zeros<arma::colvec>(7);
@@ -464,12 +464,12 @@ arma::Mat<char> GenerateReberGrammarData(
// Reber state transition matrix. (The last two columns are the indices to the
// next path).
arma::Mat<char> transitions;
transitions = { {'T', 'P', '1', '2'},
{'X', 'S', '3', '1'},
{'V', 'T', '4', '2'},
{'X', 'S', '2', '5'},
{'P', 'V', '3', '5'},
{'E', 'E', '0', '0'} };
transitions = { { 'T', 'P', '1', '2' },
{ 'X', 'S', '3', '1' },
{ 'V', 'T', '4', '2' },
{ 'X', 'S', '2', '5' },
{ 'P', 'V', '3', '5' },
{ 'E', 'E', '0', '0' } };
std::string trainReber, testReber;
@@ -1422,7 +1422,7 @@ TEST_CASE("LargeRhoValueRnnTest", "[RecurrentNetworkTest]")
using MatType = arma::cube;
std::vector<std::string>trainingData = { "THIS IS THE INPUT 0" ,
"THIS IS THE INPUT 1" ,
"THIS IS THE INPUT 3"};
"THIS IS THE INPUT 3" };
RNN<> model(rho);