plt.xlabel('z1 (mean)') plt.ylabel('z2 (mean)') plt.show() # plot the mode of responsibilities plt.scatter(modes[:, 0], modes[:, 1], c=variables_train[:, y_number]) plt.colorbar() plt.ylim(-1.1, 1.1) plt.xlim(-1.1, 1.1) plt.xlabel('z1 (mode)') plt.ylabel('z2 (mode)') plt.show() # GTMR prediction # Forward analysis (Regression) mean_of_estimated_mean_of_y, mode_of_estimated_mean_of_y, responsibilities_y, py = \ model.gtmr_predict(autoscaled_variables_test[:, numbers_of_x], numbers_of_x, numbers_of_y) # Inverse analysis mean_of_estimated_mean_of_x, mode_of_estimated_mean_of_x, responsibilities_y, py = \ model.gtmr_predict(autoscaled_variables_test[:, numbers_of_y], numbers_of_y, numbers_of_x) # Check results of forward analysis (regression) print('Results of forward analysis (regression)') predicted_y_test_all = mode_of_estimated_mean_of_y.copy() plt.rcParams['font.size'] = 18 for y_number in range(len(numbers_of_y)): predicted_y_test = np.ndarray.flatten(predicted_y_test_all[:, y_number]) predicted_y_test = predicted_y_test * variables_train[:, numbers_of_y[ y_number]].std( ddof=1) + variables_train[:, numbers_of_y[y_number]].mean()
autoscaled_target_y_value = (target_y_value - variables.mean( axis=0)[numbers_of_y]) / variables.std(axis=0, ddof=1)[numbers_of_y] # construct GTMR model model = GTM(shape_of_map, shape_of_rbf_centers, variance_of_rbfs, lambda_in_em_algorithm, number_of_iterations, display_flag) model.fit(autoscaled_variables) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(autoscaled_variables) means = responsibilities.dot(model.map_grids) modes = model.map_grids[responsibilities.argmax(axis=1), :] mean_of_estimated_mean_of_y, mode_of_estimated_mean_of_y, responsibilities_y, py = \ model.gtmr_predict(autoscaled_variables.iloc[:, numbers_of_x], numbers_of_x, numbers_of_y) plt.rcParams['font.size'] = 18 for index, y_number in enumerate(numbers_of_y): predicted_y_test = mode_of_estimated_mean_of_y[:, index] * variables.iloc[:, y_number].std( ) + variables.iloc[:, y_number].mean() # yy-plot plt.figure(figsize=figure.figaspect(1)) plt.scatter(variables.iloc[:, y_number], predicted_y_test) y_max = np.max( np.array([np.array(variables.iloc[:, y_number]), predicted_y_test])) y_min = np.min( np.array([np.array(variables.iloc[:, y_number]), predicted_y_test])) plt.plot(
plt.xlim(-1.1, 1.1) plt.xlabel('z1 (mean)') plt.ylabel('z2 (mean)') plt.show() # plot the mode of responsibilities plt.scatter(modes[:, 0], modes[:, 1], c=variables[:, y_number]) plt.colorbar() plt.ylim(-1.1, 1.1) plt.xlim(-1.1, 1.1) plt.xlabel('z1 (mode)') plt.ylabel('z2 (mode)') plt.show() # GTMR prediction for inverse analysis mean_of_estimated_mean_of_x, mode_of_estimated_mean_of_x, responsibilities_y, py = \ model.gtmr_predict(autoscaled_target_y_value, numbers_of_y, numbers_of_x) # Check results of inverse analysis print('Results of inverse analysis') mean_of_estimated_mean_of_x = mean_of_estimated_mean_of_x * x.std( axis=0, ddof=1) + x.mean(axis=0) mode_of_estimated_mean_of_x = mode_of_estimated_mean_of_x * x.std( axis=0, ddof=1) + x.mean(axis=0) # print('estimated x-mean: {0}'.format(mean_of_estimated_mean_of_x)) print('estimated x-mode: {0}'.format(mode_of_estimated_mean_of_x)) estimated_x_mean_on_map = responsibilities_y.dot(model.map_grids) estimated_x_mode_on_map = model.map_grids[np.argmax(responsibilities_y), :] # print('estimated x-mean on map: {0}'.format(estimated_x_mean_on_map)) print('estimated x-mode on map: {0}'.format(estimated_x_mode_on_map))