IMPISD_BEGIN_NAMESPACE GaussianProcessInterpolation::GaussianProcessInterpolation( FloatsList x, Floats sample_mean, Floats sample_std, unsigned n_obs, UnivariateFunction *mean_function, BivariateFunction *covariance_function, Particle *sigma, double sparse_cutoff) : Object("GaussianProcessInterpolation%1%"), x_(x), n_obs_(n_obs), mean_function_(mean_function), covariance_function_(covariance_function), sigma_(sigma), cutoff_(sparse_cutoff) { // O(M) // store dimensions M_ = x.size(); N_ = x[0].size(); sigma_val_ = Scale(sigma_).get_nuisance(); // basic checks IMP_USAGE_CHECK(sample_mean.size() == M_, "sample_mean should have the same size as x"); IMP_USAGE_CHECK(sample_std.size() == M_, "sample_std should have the same size as x"); IMP_USAGE_CHECK(mean_function->get_ndims_x() == N_, "mean_function should have " << N_ << " input dimensions"); IMP_USAGE_CHECK(mean_function->get_ndims_y() == 1, "mean_function should have 1 output dimension"); IMP_USAGE_CHECK(covariance_function->get_ndims_x1() == N_, "covariance_function should have " << N_ << " input dimensions for first vector"); IMP_USAGE_CHECK(covariance_function->get_ndims_x2() == N_, "covariance_function should have " << N_ << " input dimensions for second vector"); IMP_USAGE_CHECK(covariance_function->get_ndims_y() == 1, "covariance_function should have 1 output dimension"); // set all flags to false = need update. force_mean_update(); force_covariance_update(); // compute needed matrices compute_I(sample_mean); compute_S(sample_std); }
void _calculate_parameters(double h,my_point p[],double w[],int num) { double H,I,J,K,L,A0, A1; double x,y,d; if (num > MAX_POINTS_NUM) { fprintf(stderr,"Point number is larger than previous set!\n"); return; } is_set_ret = false; compute_Aj(h,w,num); H = compute_H(p,num); I = compute_I(p,num); J = compute_J(p,num); K = compute_K(p,num); L = compute_L(p,num); A0 = H -h*h*J*J-K+h*h*L*L; A1 = 2*(I-h*h*J*L); // printf("H=%.3lf I=%.3lf J=%.3lf K=%.3lf L=%.3lf A0=%.3lf A1=%.3lf\n", // H,I,J,K,L,A0,A1); // printf("Calculated as follows:\n"); if (0 == A0) { if (0 == A1) { // A0 A1 are0 // x,y could be any value #if 1 printf("The distribution of the given points is a circle.\n"); x = y = sqrt(2.0) / 2; d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); #else #endif } else { // A0 is 0 A1 is not 0,x2=1/2,x2+y2=1 double ar[2] = {sqrt(2.0)/2,-sqrt(2.0)/2};// possible values of x,y int i,j; for (i=0;i<2;i++) { x = ar[i]; for (j=0;j<2;j++) { y = ar[j]; d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); } } } } else if (0 == A1) { double x_ar[4] = {0,0,1,-1}; double y_ar[4] = {1,-1,0,0};//possible values of x,y int i; for (i=0;i<4;i++) { x = x_ar[i]; y = y_ar[i]; d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); } } else { // A0!=0 A1!=0 double t = A0 / sqrt (A1*A1+A0*A0); // 0 < t < 1 double x_ar[4] = {sqrt (0.5*(1+t)),sqrt (0.5*(1-t)), -sqrt (0.5*(1+t)),-sqrt (0.5*(1-t))}; // possible values of x , x2 ≠ 0 or 1 int i; for (i=0;i<4;i++) { x = x_ar[i]; y = (A1/A0)* (x - 0.5/x); d = -(h*h*(J*x+L*y)); compute_error(d,x,y,p,num); } } }