Exemplo n.º 1
0
// Fit a quadratic warping function to the given points
// in a least-squares fashion
quadratic_2d find_quadratic(const double *out, const double *x,
                            const double *y, int numPts)
{
  int nTerms = 11;
  matrix *m = matrix_alloc(nTerms, nTerms + 1);
  int row, col;
  int i;
  quadratic_2d c;
  // For each data point, add terms to matrix
  for (i = 0; i < numPts; i++) {
    for (row=0;row<nTerms;row++) {
      double partial_Q = get_term(row, x[i], y[i]);
      for (col = 0; col < nTerms; col++) {
          m->coeff[row][col] += partial_Q * get_term(col, x[i], y[i]);
      }
      m->coeff[row][nTerms] += partial_Q * out[i];
    }
  }
  // Now solve matrix to find coefficients
  // matrix_print(m,"\nLeast-Squares Matrix:\n",stdout);
  matrix_solve(m);
  c.A = m->coeff[0][nTerms];
  c.B = m->coeff[1][nTerms];
  c.C = m->coeff[2][nTerms];
  c.D = m->coeff[3][nTerms];
  c.E = m->coeff[4][nTerms];
  c.F = m->coeff[5][nTerms];
  c.G = m->coeff[6][nTerms];
  c.H = m->coeff[7][nTerms];
  c.I = m->coeff[8][nTerms];
  c.J = m->coeff[9][nTerms];
  c.K = m->coeff[10][nTerms];

  return c;
}
Exemplo n.º 2
0
extern void page_rank(size_t size)
{
	matrix w;
	matrix_init(&w, size);
	gen_web_matrix(&w);

	matrix g;
	matrix_init(&g, size);
	gen_google_matrix(&g, &w);

	matrix_free(&w);

	vector p;
	vector_init(&p, size);

	matrix_transpose(&g);

	matrix_solve(&p, &g);

	vector_sort(&p);

	vector_save(&p);

	matrix_free(&g);
	vector_free(&p);
}