예제 #1
0
// constructive heuristics for orthogonal representation OR
void LongestPathCompaction::constructiveHeuristics(
	PlanRep &PG,
	OrthoRep &OR,
	const RoutingChannel<int> &rc,
	GridLayoutMapped &drawing)
{
	OGDF_ASSERT(OR.isOrientated());

	// x-coordinates of vertical segments
	CompactionConstraintGraph<int> Dx(OR, PG, odEast, rc.separation());
	Dx.insertVertexSizeArcs(PG, drawing.width(), rc);

	NodeArray<int> xDx(Dx.getGraph(), 0);
	computeCoords(Dx, xDx);

	// y-coordinates of horizontal segments
	CompactionConstraintGraph<int> Dy(OR, PG, odNorth, rc.separation());
	Dy.insertVertexSizeArcs(PG, drawing.height(), rc);

	NodeArray<int> yDy(Dy.getGraph(), 0);
	computeCoords(Dy, yDy);

	// final coordinates of vertices
	for(node v : PG.nodes) {
		drawing.x(v) = xDx[Dx.pathNodeOf(v)];
		drawing.y(v) = yDy[Dy.pathNodeOf(v)];
	}
}
예제 #2
0
// improvement heuristics for orthogonal drawing
void LongestPathCompaction::improvementHeuristics(
	PlanRep &PG,
	OrthoRep &OR,
	const RoutingChannel<int> &rc,
	GridLayoutMapped &drawing)
{
	OGDF_ASSERT(OR.isOrientated());

	int costs, lastCosts;
	int steps = 0, maxSteps = m_maxImprovementSteps;
	if (maxSteps == 0) maxSteps = numeric_limits<int>::max();

	// OPTIMIZATION POTENTIAL:
	// update constraint graphs "incrementally" by only re-inserting
	// visibility arcs
	costs = 0;
	do {
		lastCosts = costs;
		++steps;

		// x-coordinates of vertical segments
		CompactionConstraintGraph<int> Dx(OR, PG, odEast, rc.separation());
		Dx.insertVertexSizeArcs(PG, drawing.width(), rc);
		Dx.insertVisibilityArcs(PG, drawing.x(),drawing.y());

		NodeArray<int> xDx(Dx.getGraph(), 0);
		computeCoords(Dx, xDx);

		// final x-coordinates of vertices
		for(node v : PG.nodes) {
			drawing.x(v) = xDx[Dx.pathNodeOf(v)];
		}


		// y-coordinates of horizontal segments
		CompactionConstraintGraph<int> Dy(OR, PG, odNorth, rc.separation());
		Dy.insertVertexSizeArcs(PG, drawing.height(), rc);
		Dy.insertVisibilityArcs(PG, drawing.y(),drawing.x());

		NodeArray<int> yDy(Dy.getGraph(), 0);
		computeCoords(Dy, yDy);

		// final y-coordinates of vertices
		for(node v : PG.nodes) {
			drawing.y(v) = yDy[Dy.pathNodeOf(v)];
		}

		costs = Dx.computeTotalCosts(xDx) + Dy.computeTotalCosts(yDy);

	} while (steps < maxSteps && (steps == 1 || costs < lastCosts));
}
예제 #3
0
//[[Rcpp::export]]
mat one_pred_gp_gdp(mat X, vec y, mat param_row) {
  vec param = vectorise(param_row);

  double s2 = param[0];
  double phi = param[1];
  double tau = param[2];

  vec d = param.tail(param.size()-3);
  int n = X.n_rows;

  mat XdX = xDx(X,d % d);
  mat K = tau * exp(-phi*XdX);

  mat Xt = X.t();
  mat I = eye(n,n);

  mat S_i = (K.i() + I / s2).i();
  vec mu = S_i*y / s2;

  vec pred_y = mvrnorm(mu,S_i);

  return reshape(pred_y,1,n);
}
예제 #4
0
double log_like_plus_log_prior(vec y, mat X, vec param, mat I, vec priors) {
  double ls2 = param[0];
  double w = param[1];
  double ltau = param[2];
  vec d_vec = param.tail( param.size()-3 );
  vec d2 = d_vec % d_vec;
  mat D_mat = xDx(X,d2); // ORIGINAL and best so far
  //mat D_mat = xDx(X,d2/sum(d2));

  double a_s2 = priors[0];//2;
  double b_s2 = priors[1];//5;
  double a_phi = priors[2];//0;
  double b_phi = priors[3];//5;
  double a_tau = priors[4];//2;
  double b_tau = priors[5];//5;
  double a_d = priors[6]; //1;
  double b_d = priors[7]; //1;

  double s2 = exp(ls2);
  double phi = (b_phi*exp(w) + a_phi) / (exp(w)+1); // inverse logit
  double tau = exp(ltau);

  mat K = tau * exp(-phi*D_mat);

  double ldet_K,sign;
  mat s2I_plus_K = s2*I + K;

  log_det(ldet_K, sign, s2I_plus_K);
  
  double sum_log_dj_prior = sum( (-b_d-1) * log(1+abs(d_vec) / (a_d * b_d)) );

  double log_prior = ( w-2*log(exp(w)+1) ) - a_s2*ls2 - b_s2/s2 - a_tau*ltau - b_tau/tau + sum_log_dj_prior;
  double log_like = (-.5 * ldet_K - .5 * y.t() * s2I_plus_K.i() * y)[0];

  return log_like + log_prior;
}