Exemple #1
0
static double valid_distance(DPOINT *a, DPOINT *b, double max, 
		int symmetric, DATA *d1, DATA *d2, GRIDMAP *map) {
	double ddist, dX, dX2, inprod;
	DPOINT p;
	int mode = 0, i;
	unsigned int row, col;

	assert(a != NULL);
	assert(b != NULL);
	assert(d1 != NULL);
	assert(d2 != NULL);

	mode = d1->mode & d2->mode;
/*
 * even if modes don't correspond, valid_direction() will 
 * calculate valid distances 
 */
	p.x = a->x - b->x;
	p.y = a->y - b->y;
	p.z = a->z - b->z;
	if (map) {
		/* transform here p to allow directional 2d cuts in a 3d world */
		if (map_xy2rowcol(map, p.x, p.y, &row, &col))
			return -1.0;
		else
			ddist = (1.0 * row) * map->cols + col + 0.5;
	} else {
		if (p.x > max || p.y > max || p.z > max) 
			return -1.0;
		/* Changed K.M. Fri Feb 27 15:56:57 1998 */
		/* if ddist < 0.0 then we don't need to check for dX! */
		if ((ddist = valid_direction(&p, symmetric, d1)) > max || ddist < 0.0) 
			return -1.0;
	}
	dX = MIN(d1->dX, d2->dX);
	if (dX < DBL_MAX) {
		dX2 = dX * dX;
		/* allow only points for which 2-norm ||x_i-x_j|| < dX */
		if (d1->n_X != d2->n_X)
			ErrMsg(ER_IMPOSVAL, "valid_distance(): d1->n_X != d2->n_X");
		for (i = 0, inprod = 0.0; i < d1->n_X; i++)
			inprod += SQR(a->X[i] - b->X[i]);
		if (inprod > dX2)
			ddist = -1.0;
	}
	/*
	if (d1->coln_id > 0 && d2->coln_id > 0 && strcmp())
		return -1.0;
	*/
	return ddist;
}
Exemple #2
0
void predict_all(DATA **data) {
	int i = 0, random_path = 0;
	DPOINT *here = NULL, *where = NULL;
	PRED_AT at_what;
	unsigned int row, col;

	n_done = 0;
	val_data = get_dataval();
	if (val_data->id > -1) {
		at_what = AT_POINTS;
		n_pred_locs = val_data->n_list;
		if (val_data->colns)
			strata_min = val_data->minstratum;
	} else if (get_n_masks() > 0) {
		at_what = AT_GRIDMAP;
		here = (DPOINT *) emalloc(sizeof(DPOINT));
		here->u.stratum = -2; /* only NON-MV cells */
		if (max_block_dimension(0) > 0.0)
			SET_BLOCK(here);
		else
			SET_POINT(here);
	} else /* what else ? */
		return;

	if (at_what == AT_GRIDMAP && get_n_outfile() == 0) {
		pr_warning("no output maps defined");
		return;
	}

	init_predictions(at_what);

	if (at_what == AT_GRIDMAP && !data[0]->dummy) { 
		if (data[0]->maxX < masks[0]->x_ul ||
				data[0]->minX > (masks[0]->x_ul + masks[0]->cols * masks[0]->cellsizex) ||
				data[0]->minY > masks[0]->y_ul ||
				data[0]->maxY < (masks[0]->y_ul - masks[0]->rows * masks[0]->cellsizey)) {
			pr_warning("ALL data are outside the map boundaries");
			printlog("data x[%g,%g], y[%g,%g]; map x[%g,%g], y[%g,%g]\n",
				data[0]->minX, data[0]->maxX, data[0]->minY, data[0]->maxY,
				masks[0]->x_ul,
				masks[0]->x_ul + masks[0]->cols * masks[0]->cellsizex,
				masks[0]->y_ul - masks[0]->rows * masks[0]->cellsizey,
				masks[0]->y_ul
				);
		}
		else if (map_xy2rowcol(masks[0], data[0]->minX, data[0]->minY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->maxX, data[0]->minY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->minX, data[0]->maxY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->maxX, data[0]->maxY, &row, &col))
			pr_warning("at least some data are outside the map boundaries");
			/* this is not a sufficient test! */
	}

	if (gl_rp) /* Yes, by default */
		random_path = is_simulation(get_method());
	row = col = 0;
	while ((where = next_location(here, at_what, random_path,
			&row, &col, data)) != NULL) {
		for (i = 0; i < get_n_outfile(); i++)
			set_mv_double(&(est[i])); /* initialize estimates */
		if (where->u.stratum >= 0) {
			if (get_mode() != STRATIFY) {
				for (i = 0; i < get_n_vars(); i++)
					select_at(data[i], where);
			} else if (where->u.stratum < get_n_vars())
				select_at(data[where->u.stratum], where);
			get_est(data, get_method(), where, est);
		}
		/* printf("%g %g\n", est[0], est[1]); */
		write_output(est, at_what, where, row, col);
	}
	exit_predictions(at_what);
	if (here != NULL)
		efree(here);
	print_progress(100, 100);
}