Index: trunk/npstat/stat/randomTukeyDepth.icc =================================================================== --- trunk/npstat/stat/randomTukeyDepth.icc (revision 904) +++ trunk/npstat/stat/randomTukeyDepth.icc (revision 905) @@ -1,177 +1,238 @@ #include #include #include #include #include "npstat/stat/DistributionsND.hh" #include "npstat/stat/StatUtils.hh" +#include "npstat/stat/StatAccumulatorArr.hh" namespace npstat { template void randomTukeyDepth1(const Matrix& sample, AbsRandomGenerator& rng, const Matrix& covmat, const unsigned nRandom, - double* depth, const unsigned nDepth) + double* depth, const unsigned nDepth, + const bool usePointDirections) { typedef std::pair Pair; const unsigned dim = sample.nColumns(); assert(dim); const unsigned n = sample.nRows(); assert(n); assert(nDepth >= n); assert(depth); std::vector vec(dim, 0.0); const GaussND gauss(&vec[0], dim, covmat); std::vector minOrder(n, n); std::vector ordering(n); + std::vector sampleMean(dim, 0.0); + const bool reallyUsePointDirs = usePointDirections && dim > 1U && n > 2U; + if (reallyUsePointDirs) + { + StatAccumulatorArr acc(dim); + for (unsigned i=0; i(vsum)); - assert(norm > 0.0); - for (unsigned i=0; i 0.0) + { + for (unsigned i=0; i 2U) { unsigned maxPossibleOrder = n/2U; if (n % 2U == 0U) --maxPossibleOrder; const double med = maxPossibleOrder; for (unsigned ipt=0; ipt void randomTukeyDepth2(const Matrix& inSample, const Matrix& refSample, AbsRandomGenerator& rng, const Matrix& covmat, const unsigned nRandom, - double* depth, const unsigned nDepth) + double* depth, const unsigned nDepth, + const bool usePointDirections) { const unsigned dim = inSample.nColumns(); assert(dim); assert(dim == refSample.nColumns()); const unsigned nIn = inSample.nRows(); assert(nIn); assert(nDepth >= nIn); assert(depth); const unsigned nRef = refSample.nRows(); assert(nRef); std::vector vec(dim, 0.0); const GaussND gauss(&vec[0], dim, covmat); std::vector minCdf(nIn, 2.0); std::vector ordering(nRef); + std::vector sampleMean(dim, 0.0); + const bool reallyUsePointDirs = usePointDirections && dim > 1U; + if (reallyUsePointDirs) + { + StatAccumulatorArr acc(dim); + for (unsigned i=0; i(vsum)); - assert(norm > 0.0); - for (unsigned i=0; i 0.0) + { + for (unsigned i=0; i void randomTukeyDepth1(const Matrix& sample, AbsRandomGenerator& rng, const Matrix& covmat, unsigned nRandom, - double* depth, unsigned nDepth); + double* depth, unsigned nDepth, + bool usePointDirections = false); /** // Random Tukey depth for each point in a sample calculated // using another (reference) sample. Function arguments are // as follows: // // sample should be dimensioned n x d, where d is the // point dimensionality and n is the sample size. // - // refSample the depth of each point in the "sample" - // argument will be defined with respect - // to this sample. + // refSample the depth of each point in the "sample" argument + // will be defined with respect to this "reference" + // sample. The size of this sample should normally + // be substantialy larger than n. // // rng random number generator in 1 or d dimensions. // // covmat should be dimensioned d x d. The random directions // will be generated by a multivariate normal // distribution with this covariance matrix. // // nRandom is the number of random directions to generate. // In addition to random directions, the ordering // will also be perfomed according to the marginals. // // depth this array will be filled with depth values // on exit (in the same order of points as in // the "sample" argument). // // nDepth is the length of the "depth" array. Should be // at least as large as the "sample" size. + // + // usePointDirections if this argument is set to "true", + // directions from the center of the + // "refSample" cloud to each point of + // the "sample" will also be utilized + // in the depth calculation. + // + // Assuming that the size of the reference sample is m, + // the CPU time used by this function will scale as + // O(nRandom*(m+n)*log(m)) if "usePointDirections" is false. + // If "usePointDirections" is true, another step will + // be added that scales as O(n*(m+n)*log(m)). */ template void randomTukeyDepth2(const Matrix& sample, const Matrix& refSample, AbsRandomGenerator& rng, const Matrix& covmat, unsigned nRandom, - double* depth, unsigned nDepth); + double* depth, unsigned nDepth, + bool usePointDirections = false); } #include "npstat/stat/randomTukeyDepth.icc" #endif // NPSTAT_RANDOMTUKEYDEPTH_HH_