Beispiel #1
0
array_nd<T> repmat(const array_nd<T>& a, const size_array& sz)
{
	CHECK (sz.length() <= a.ndims(), eshape());

	array_nd<T> c(a);

	for (size_t i = 0; i < sz.length(); i++) {
		array_nd<T> tmp(c);
		for (size_t j = 0; j < sz[i]; j++)
			c = cat<T>(i, c, tmp);
	}
	return c;
}
Beispiel #2
0
	void operate(array<T1, S1>& u, array <array <T2, S21>, S22>& p, sep,
					 const array<T3, S3>& a, const size_array& idx = size_array())  // f only used internally!
	{
		if (a.empty()) { u.init(); p.init(); return; }
		size_array first = find(arr(true).cat(diff(a) != 0));
		u = a[first];
		if (idx.empty()) (_, p) = partition++(size_array((0, _, a.length() - 1)), first);  // TODO: remove size_array copy
		else             (_, p) = partition++(idx, first);
	}
Beispiel #3
0
	void operate(array<T1, S1>& u, array <T2, S2>& p, sep,
					 const array<T3, S3>& a, const size_array& idx = size_array())  // f only used internally!
	{
		if (a.empty()) { u.init(); p.init(); return; }
		if (FIRST) (_, p) = find++(arr(true).cat(diff(a) != 0));  // TODO: check speed of cat()
		else       (_, p) = find++((diff(a) != 0).cat(arr(true)));
		u = a[p];
		if (!idx.empty()) force(p) = idx[p];
	}
Beispiel #4
0
Datei: nn.hpp Projekt: iavr/drvq
	void eval(const array <pos>& nn, const nn_options& opt)
	{
		msg::in_line(info, "evaluating");

		const size_array at = (0, _, opt.at_step, _, opt.at_max);
		array <T> recall(at.length(), T());
		T R = .95;
		array <T> rat = (R, _, opt.rat_step, _, opt.rat_max);
		array <T> freq(rat.length());
		size_t FL = freq.length();
		size_t N = nn.length(), C = dist.length(), J = dist[0].columns();
		T rank = 0, lower = 0, upper = 0, approx = 0;

		for (size_t n = 0; n < N; n++)
		{
			msg::progress(info, n, N);
			pos quot = nn[n];

			for (size_t c = 0; c < C; c++)
			{
				array <T> d = dist[c].as_rows()[n];
				T dq = d[quot % J], dl = min(d);
				T r = find(d < dq).length();
				rank   += r;
				recall[r > at]++;
				freq[(min(dq / dl, opt.rat_max) - R) / opt.rat_step]++;
				lower  += dl;
				upper  += max(d);
				approx += dq;
				quot   /= J;
			}
		}
		T S = C * N;
		msg::done(info);
		msg::rank(info, rank / S, J);
		msg::bounds(info, lower / S, approx / S, upper / S);

		if (opt.recall)
			msg::recall(info, at, 1 - recall / S);

		if (opt.ratio)
			msg::ratio(info, rat, freq / S);
	}
Beispiel #5
0
	void operate(array<T1, S1>& u, array <T2, S2>& p, array <T3, S3>& q, sep,
					 const array<T4, S4>& a, const size_array& idx = size_array())  // idx only used internally!
	{
		if (a.empty()) { u.init(); p.init(); q.init(); return; }
		q = arr(true).cat(diff(a) != 0);
		if (FIRST) (_, p) = find++(q);
		else       (_, p) = find++(cshift(q, -1));
		u = a[p];
		if (!idx.empty()) force(p) = idx[p];
		q[0] = T3();
		q = cumsum(q);
	}