Exemple #1
0
  void BrentMinimizer::minimize(
      double starting_value, double second_candidate) {
    double a = starting_value;
    double b = second_candidate;
    if (b < a) std::swap(a, b);

    bracket_minimum(target_, &a, &b);

    minimizing_x_ = fminbr(a, b, target_, tolerance_);
    minimum_value_ = target_(minimizing_x_);
  }
Exemple #2
0
double opt_knot_psgold(void){
	int   j;
	double oldgcv, currgcv, a, b; 
	
      oldgcv = gcv_fit( dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD);

      for(j=0; j<99; j++){
	for(iknot_psgold = sp_psgold->order; iknot_psgold < sp_psgold->n  ; iknot_psgold++){
		a = sp_psgold->knot[iknot_psgold-1], b = sp_psgold->knot[iknot_psgold+1];
		sp_psgold->knot[iknot_psgold] = fminbr(a, b, fknot_psgold, KNOT_TOL_PSGOLD);
	
	}

	for(iknot_psgold = sp_psgold->n -1; iknot_psgold >= sp_psgold->order  ; iknot_psgold--){
		a = sp_psgold->knot[iknot_psgold-1], b = sp_psgold->knot[iknot_psgold+1];
		sp_psgold->knot[iknot_psgold] = fminbr(a, b, fknot_psgold, KNOT_TOL_PSGOLD);
		
	}
	

	for(iknot_psgold = sp_psgold->n -1; iknot_psgold >= sp_psgold->order  ; iknot_psgold--){
		a = sp_psgold->knot[iknot_psgold-1], b = sp_psgold->knot[iknot_psgold+1];
		sp_psgold->knot[iknot_psgold] = fminbr(a, b, fknot_psgold, KNOT_TOL_PSGOLD);
		
	}

	for(iknot_psgold = sp_psgold->order; iknot_psgold < sp_psgold->n  ; iknot_psgold++){
		a = sp_psgold->knot[iknot_psgold-1], b = sp_psgold->knot[iknot_psgold+1];
		sp_psgold->knot[iknot_psgold] = fminbr(a, b, fknot_psgold, KNOT_TOL_PSGOLD);
	
	}
		currgcv = gcv_fit( dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD );
		if( fabs( (currgcv-oldgcv)/(oldgcv + .0001) ) < .0001 )
			break;
		oldgcv = currgcv;
}

	currgcv = gcv_fit( dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD );
	return currgcv;
}
Exemple #3
0
double lambda_loop_psgold(double shift, double scale)
{
int i, j;

double glob_min_gcv, loc_min_gcv, currgcv;
double loc_best_lambda = 0, glob_best_lambda = 0;
double oldgcv, a, b;

glob_min_gcv = INFINITY;

for (j = 0; j < NUMBER_LAMBDA_LOOPS_PSGOLD; j++)
{
     loc_min_gcv = INFINITY;
     for (i = 0; i < NUMBER_LAMBDA_ITER_PSGOLD; i++)
     {
          lambda_psgold = exp(RandomDouble(MIN_LOG_LAMBDA_PSGOLD, MAX_LOG_LAMBDA_PSGOLD)); 
          currgcv = gcv_fit(dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD);
          if (currgcv < loc_min_gcv)
          {
              loc_best_lambda = lambda_psgold;
              loc_min_gcv = currgcv;
          }
      }

      lambda_psgold = loc_best_lambda;
      currgcv = loc_min_gcv;
      get_pen_1D_spline(dat_psgold, sp_psgold, lambda_psgold);

      if (currgcv < glob_min_gcv)
      {
          glob_best_lambda = lambda_psgold;
          glob_min_gcv = currgcv;
      }

      for(i=0; i<99; i++)
      {
          oldgcv = currgcv;
          a = log(lambda_psgold) + log(LAMBDA_MULT_PSGOLD);
          b = log(lambda_psgold) - log(LAMBDA_MULT_PSGOLD); 
          lambda_psgold = exp(fminbr(a, b, flambda_psgold, LAMBDA_TOL_PSGOLD));
          currgcv = gcv_fit( dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD );
          if( fabs( (currgcv-oldgcv)/(oldgcv + .0001) ) < .0001 )
	         break;
      }	

      currgcv = gcv_fit(dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD );

      if (currgcv < glob_min_gcv)
      {
          glob_best_lambda = lambda_psgold;
          glob_min_gcv = currgcv;
      }

}  /* end j loop */

lambda_psgold = glob_best_lambda;
currgcv = gcv_fit(dat_psgold, sp_psgold, lambda_psgold, MIN_SPACE_PSGOLD);

/* printf("The overall best GCV is %e\n", currgcv);
printf("The value of lambda is %e \n", lambda_psgold*pow(scale, 2*sp_psgold->order-2));
for(i=0; i< sp_psgold->n + sp_psgold->order; i++)
      printf("%f ", shift + scale * sp_psgold->knot[i]);
printf("\n\n"); */

return currgcv;
}