Index: trunk/tests/test_randomTukeyDepth.cc =================================================================== --- trunk/tests/test_randomTukeyDepth.cc (revision 902) +++ trunk/tests/test_randomTukeyDepth.cc (revision 903) @@ -1,48 +1,85 @@ #include <algorithm> #include "UnitTest++.h" #include "test_utils.hh" #include "npstat/rng/MersenneTwister.hh" #include "npstat/stat/randomTukeyDepth.hh" using namespace npstat; namespace { - TEST(randomTukeyDepth_1d) + TEST(randomTukeyDepth1_1d) { MersenneTwister rng; const Matrix<double> covmat(1, 1, 1); for (unsigned sampleSize=3; sampleSize<10; ++sampleSize) { std::vector<std::pair<double, unsigned> > vec(sampleSize); Matrix<double> sample(sampleSize, 1); for (unsigned i=0; i<sampleSize; ++i) { const double x = test_rng(); vec[i] = std::pair<double, unsigned>(x, i); sample[i][0] = x; } std::vector<double> depth(sampleSize); randomTukeyDepth1(sample, rng, covmat, 1U, &depth[0], depth.size()); CHECK_EQUAL(0.0, *std::min_element(depth.begin(), depth.end())); CHECK_EQUAL(1.0, *std::max_element(depth.begin(), depth.end())); - + unsigned maxPossibleOrder = sampleSize/2U; if (sampleSize % 2U == 0U) --maxPossibleOrder; const double med = maxPossibleOrder; std::sort(vec.begin(), vec.end()); for (unsigned ipt=0, ipt2=sampleSize-1U; ipt<sampleSize; ++ipt, --ipt2) { const unsigned minOrd = std::min(ipt, ipt2); const double ord = minOrd/med; CHECK_CLOSE(ord, depth[vec[ipt].second], 1.0e-12); } } } + + TEST(randomTukeyDepth2_1d) + { + MersenneTwister rng; + const Matrix<double> covmat(1, 1, 1); + + for (unsigned sampleSize=3; sampleSize<10; ++sampleSize) + { + std::vector<std::pair<double, unsigned> > vec(sampleSize); + Matrix<double> sample(sampleSize, 1); + for (unsigned i=0; i<sampleSize; ++i) + { + const double x = test_rng(); + vec[i] = std::pair<double, unsigned>(x, i); + sample[i][0] = x; + } + + std::vector<double> depth(sampleSize); + randomTukeyDepth2(sample, sample, rng, covmat, 1U, + &depth[0], depth.size()); + CHECK_CLOSE(0.0, *std::min_element(depth.begin(), depth.end()), 1.0/sampleSize); + CHECK_CLOSE(1.0, *std::max_element(depth.begin(), depth.end()), 1.0/sampleSize); + + unsigned maxPossibleOrder = sampleSize/2U; + if (sampleSize % 2U == 0U) + --maxPossibleOrder; + const double med = maxPossibleOrder; + + std::sort(vec.begin(), vec.end()); + for (unsigned ipt=0, ipt2=sampleSize-1U; ipt<sampleSize; ++ipt, --ipt2) + { + const unsigned minOrd = std::min(ipt, ipt2); + const double ord = minOrd/med; + CHECK_CLOSE(ord, depth[vec[ipt].second], 1.0/sampleSize + 1.0e-10); + } + } + } }