predictions,MSE,boundL,boundU = \ gcp.predict(candidates,eval_MSE=True,eval_confidence_bounds=True,coef_bound = 1.96,integratedPrediction=integratedPrediction) pred_error = np.mean( (predictions - np.asarray(real_y) ) **2. ) print 'MSE', pred_error / (np.std(real_y) **2.) idx = np.argsort(candidates[:,0]) s_candidates = candidates[idx,0] s_boundL = boundL[idx] s_boundU = boundU[idx] pred,MSE_bis = gcp.predict(np.atleast_2d(s_candidates).T,eval_MSE=True,transformY=False,eval_confidence_bounds=False,coef_bound = 1.96) gp_boundL = pred - 1.96*np.sqrt(MSE_bis) gp_boundU = pred + 1.96*np.sqrt(MSE_bis) t_f_plot = [gcp.mapping(abs[i],f_plot[i],normalize=True) for i in range(len(f_plot))] t_y_training = [gcp.mapping(x_training[i],y_training[i],normalize=True) for i in range(len(y_training))] if(save_plots): save_data = np.asarray([s_candidates,boundL,boundU,predictions,f_plot]).T np.savetxt('data_plot.csv',save_data,delimiter=',') ax.plot(abs,f_plot) l1, = ax.plot(candidates,predictions,'r+',label='GCP predictions') l3, = ax.plot(x_training,y_training,'bo',label='Training points') ax.fill(np.concatenate([s_candidates,s_candidates[::-1]]),np.concatenate([s_boundL,s_boundU[::-1]]),alpha=.5, fc='c', ec='None') ax = fig.add_subplot(len(all_n_clusters),2,count+1) ax.set_title('GP space') ax.plot(abs,t_f_plot)
mapWithNoise = GCP_mapWithNoise, useAllNoisyY = False, model_noise = model_noise , try_optimize = True) gcp.fit(x_training,y_training,y_detailed,obs_noise=noise_obs) print 'GCP fitted' print 'Theta', gcp.theta predictions,MSE,boundL,boundU = \ gcp.predict(abs,eval_MSE=True,eval_confidence_bounds=True,coef_bound = 1.96) pred,MSE_bis = gcp.predict(abs,eval_MSE=True,transformY=False,eval_confidence_bounds=False,coef_bound = 1.96) gp_boundL = pred - 1.96*np.sqrt(MSE_bis) gp_boundU = pred + 1.96*np.sqrt(MSE_bis) t_f_plot = [gcp.mapping(abs[i],f_plot[i],normalize=True) for i in range(len(f_plot))] t_y_training = [gcp.mapping(x_training[i],y_training[i],normalize=True) for i in range(len(y_training))] t_all_y_training = [gcp.mapping(all_x[i],array_y_detailed[i],normalize=True) for i in range(array_y_detailed.shape[0])] print pred.shape idx = np.argsort(abs[:,0]) s_candidates = abs[idx,0] s_boundL = boundL[idx] s_boundU = boundU[idx] if(save_plots): save_data = np.asarray([s_candidates,boundL,boundU,predictions,f_plot]).T np.savetxt('noisy_data_plot.csv',save_data,delimiter=',') ax.plot(abs,f_plot)
predictions,MSE,boundL,boundU = \ gcp.predict(candidates,eval_MSE=True,eval_confidence_bounds=True,coef_bound = 1.96,integratedPrediction=integratedPrediction) pred_error = np.mean((predictions - np.asarray(real_y))**2.) print 'MSE', pred_error print 'Normalized error', np.sqrt(pred_error) / np.std(real_y) pred, MSE_bis = gcp.predict(candidates, eval_MSE=True, transformY=False, eval_confidence_bounds=False, coef_bound=1.96) t_f_plot = [ gcp.mapping(candidates[i], real_y[i], normalize=True) for i in range(real_y.shape[0]) ] t_y_training = [ gcp.mapping(x_training[i], y_training[i], normalize=True) for i in range(len(y_training)) ] ax.scatter(x_training[:, 0], x_training[:, 1], y_training, c='g', label='Training points', alpha=0.5) ax.scatter(candidates[:, 0], candidates[:, 1],
candidates = np.atleast_2d(range(80)).T * 5 prediction = gcp.predict(candidates) # plot results abs = range(0,400) f_plot = [scoring_function(i) for i in abs] ax2 = fig2.add_subplot(n_rows,2,n_clusters) plt.plot(abs,f_plot) plt.plot(x_training,y_training,'bo') #plt.plot(candidates,simple_prediction,'go',label='Simple prediction') plt.plot(candidates,prediction,'r+',label='n_clusters == ' + str(n_clusters)) plt.axis([0,400,0,1.]) ax2.set_title('Likelihood = ' + str(likelihood)) plt.legend() mapping_functions_plot.append( [gcp.mapping(200,mf_plt_axis[i],normalize=True) for i in range(100)]) ## with GP ## gp = GaussianProcess(theta0=.1 , thetaL = 0.001, thetaU = 10., random_start = 5, nugget=nugget) gp.fit(x_training,y_training) likelihood = gp.reduced_likelihood_function_value_ print 'GP' print 'Theta',gp.theta_ print 'Likelihood',likelihood candidates = np.atleast_2d(range(80)).T * 5 prediction = gp.predict(candidates)
abs = range(0, 400) f_plot = [scoring_function(i) for i in abs] ax2 = fig2.add_subplot(n_rows, 2, n_clusters) plt.plot(abs, f_plot) plt.plot(x_training, y_training, 'bo') #plt.plot(candidates,simple_prediction,'go',label='Simple prediction') plt.plot(candidates, prediction, 'r+', label='n_clusters == ' + str(n_clusters)) plt.axis([0, 400, 0, 1.]) ax2.set_title('Likelihood = ' + str(likelihood)) plt.legend() mapping_functions_plot.append( [gcp.mapping(200, mf_plt_axis[i], normalize=True) for i in range(100)]) ## with GP ## gp = GaussianProcess(theta0=.1, thetaL=0.001, thetaU=10., random_start=5, nugget=nugget) gp.fit(x_training, y_training) likelihood = gp.reduced_likelihood_function_value_ print 'GP' print 'Theta', gp.theta_ print 'Likelihood', likelihood candidates = np.atleast_2d(range(80)).T * 5 prediction = gp.predict(candidates)
print 'GCP fitted' print 'Theta', gcp.theta predictions,MSE,boundL,boundU = \ gcp.predict(abs,eval_MSE=True,eval_confidence_bounds=True,coef_bound = 1.96) pred, MSE_bis = gcp.predict(abs, eval_MSE=True, transformY=False, eval_confidence_bounds=False, coef_bound=1.96) gp_boundL = pred - 1.96 * np.sqrt(MSE_bis) gp_boundU = pred + 1.96 * np.sqrt(MSE_bis) t_f_plot = [ gcp.mapping(abs[i], f_plot[i], normalize=True) for i in range(len(f_plot)) ] t_y_training = [ gcp.mapping(x_training[i], y_training[i], normalize=True) for i in range(len(y_training)) ] t_all_y_training = [ gcp.mapping(all_x[i], array_y_detailed[i], normalize=True) for i in range(array_y_detailed.shape[0]) ] print pred.shape idx = np.argsort(abs[:, 0]) s_candidates = abs[idx, 0] s_boundL = boundL[idx]
try_optimize = True) gcp.fit(x_training,y_training) print '\nGCP fitted' print 'Theta', gcp.theta print 'Likelihood', np.exp(gcp.reduced_likelihood_function_value_) predictions,MSE,boundL,boundU = \ gcp.predict(candidates,eval_MSE=True,eval_confidence_bounds=True,coef_bound = 1.96,integratedPrediction=integratedPrediction) pred_error = np.mean( (predictions - np.asarray(real_y) ) **2. ) print 'MSE', pred_error print 'Normalized error', np.sqrt(pred_error) /np.std(real_y) pred,MSE_bis = gcp.predict(candidates,eval_MSE=True,transformY=False,eval_confidence_bounds=False,coef_bound = 1.96) t_f_plot = [gcp.mapping(candidates[i],real_y[i],normalize=True) for i in range(real_y.shape[0])] t_y_training = [gcp.mapping(x_training[i],y_training[i],normalize=True) for i in range(len(y_training))] ax.scatter(x_training[:,0],x_training[:,1],y_training,c='g',label='Training points',alpha=0.5) ax.scatter(candidates[:,0],candidates[:,1],real_y,c='b',label='Branin function',alpha=0.5) ax.scatter(candidates[:,0],candidates[:,1],predictions,c='r',label='predictions',marker='+') ax = fig.add_subplot(1,2,2, projection='3d') ax.set_title('GP space') ax.scatter(x_training[:,0],x_training[:,1],t_y_training,c='g',label='Training points',alpha=0.5) ax.scatter(candidates[:,0],candidates[:,1],t_f_plot,c='b',label='Branin function',alpha=0.5) ax.scatter(candidates[:,0],candidates[:,1],pred,c='r',label='predictions',marker='+') plt.legend() plt.show()
print 'MSE', pred_error / (np.std(real_y)**2.) idx = np.argsort(candidates[:, 0]) s_candidates = candidates[idx, 0] s_boundL = boundL[idx] s_boundU = boundU[idx] pred, MSE_bis = gcp.predict(np.atleast_2d(s_candidates).T, eval_MSE=True, transformY=False, eval_confidence_bounds=False, coef_bound=1.96) gp_boundL = pred - 1.96 * np.sqrt(MSE_bis) gp_boundU = pred + 1.96 * np.sqrt(MSE_bis) t_f_plot = [ gcp.mapping(abs[i], f_plot[i], normalize=True) for i in range(len(f_plot)) ] t_y_training = [ gcp.mapping(x_training[i], y_training[i], normalize=True) for i in range(len(y_training)) ] if (save_plots): save_data = np.asarray( [s_candidates, boundL, boundU, predictions, f_plot]).T np.savetxt('data_plot.csv', save_data, delimiter=',') ax.plot(abs, f_plot) l1, = ax.plot(candidates, predictions, 'r+', label='GCP predictions') l3, = ax.plot(x_training, y_training, 'bo', label='Training points')