Beispiel #1
0
/* 
 * Assumes the data is gaussian, rejects outliers that are nsigma away from the mean.
 * Sets outlier values to be NAN in the input data array.
 * returns the number of rejected values.
 */
int reject_outliers(double data[], int size, float nsigma)
{
	double mean, sigma;
	int i, reject_count;

	mean = compute_mean(data, 0,size);
	sigma = compute_sigma(data, size, mean);
	reject_count = 0;
	for (i=0; i<size; i++) {
		if (isnan(data[i])) continue;
		if (fabs(mean - data[i]) > nsigma*sigma) {
			data[i] = NAN;
			reject_count++;
		}
	}
	return reject_count;
}
void householders(
    orthotope<T> const& A
    )
{
    BOOST_ASSERT(2 == A.order());
    BOOST_ASSERT(A.hypercube());

    std::size_t const n = A.extent(0);

    orthotope<T> R = A.copy();
    orthotope<T> Q({n, n});

    for (std::size_t l = 0; l < n; ++l)
        Q(l, l) = 1.0;

    for (std::size_t l = 0; l < (n - 1); ++l)
    {
        T const sigma = compute_sigma(R, n, l);
        boost::int16_t const sign = compute_sign(R(l, l));

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            std::cout << (std::string(80, '#') + "\n")
                      << "ROUND " << l << "\n\n";

            print(sigma, "sigma");
            print(sign, "sign");
        #endif

        orthotope<T> w({n});

        w(l) = R(l, l) + sign * sigma;
 
        for (std::size_t i = (l + 1); i < w.extent(0); ++i)
            w(i) = R(i, l);

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            print(w, "u");
        #endif

        T const w_norm = euclidean_norm(w);

        for (std::size_t i = l; i < n; ++i)
            w(i) /= w_norm;

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            print(w, "v");
        #endif

        orthotope<T> H = compute_H(w);

        #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
            print(H, "H");
        #endif

        R = matrix_multiply(H, R);

        Q = matrix_multiply(Q, H);

        for (std::size_t i = l + 1; i < n; ++i)
            R(i, l) = 0;
    }

    #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
        std::cout << std::string(80, '#') << "\n";
    #endif

    print(A, "A");
    print(Q, "Q");
    print(R, "R");

    #if defined(HPXLA_DEBUG_HOUSEHOLDERS)
        check_QR(A, Q, R);
    #endif
}