Xtest = original_X[500:, :]
ytest = original_y[500:]

# autoscaling
# autoscaled_X = (original_X - original_X.mean(axis=0)) / original_X.std(axis=0,ddof=1)
autoscaled_Xtrain = (Xtrain - Xtrain.mean(axis=0)) / Xtrain.std(axis=0, ddof=1)
# autoscaled_Xtest = (Xtest - X.mean(axis=0)) / X.std(axis=0,ddof=1)
# autoscaled_ytrain = (ytrain - ytrain.mean()) / ytrain.std(ddof=1)

# construct GTM 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_Xtrain)
if model.success_flag:
    # calculate of responsibilities
    responsibilities = model.responsibility(autoscaled_Xtrain)

    # plot the mean of responsibilities
    means = responsibilities.dot(model.map_grids)
    plt.figure()
    #    plt.figure(figsize=figure.figaspect(1))
    plt.scatter(means[:, 0], means[:, 1], c=ytrain)
    plt.colorbar()
    plt.ylim(-1.1, 1.1)
    plt.xlim(-1.1, 1.1)
    plt.xlabel("z1 (mean)")
    plt.ylabel("z2 (mean)")
    plt.show()

    # plot the mode of responsibilities
    modes = model.map_grids[responsibilities.argmax(axis=1), :]
numbers_of_x = np.arange(numbers_of_y[-1] + 1, variables.shape[1])

# standardize x and y
autoscaled_variables = (variables - variables.mean(axis=0)) / variables.std(
    axis=0, ddof=1)
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]),
for shape_of_map_grid in candidates_of_shape_of_map:
    for shape_of_rbf_centers_grid in candidates_of_shape_of_rbf_centers:
        for variance_of_rbfs_grid in candidates_of_variance_of_rbfs:
            for lambda_in_em_algorithm_grid in candidates_of_lambda_in_em_algorithm:
                calculation_number += 1
                print([calculation_number, all_calculation_numbers])
                # construct GTM model
                model = GTM(
                    [shape_of_map_grid, shape_of_map_grid],
                    [shape_of_rbf_centers_grid, shape_of_rbf_centers_grid],
                    variance_of_rbfs_grid, lambda_in_em_algorithm_grid,
                    number_of_iterations, display_flag)
                model.fit(input_dataset)
                if model.success_flag:
                    # calculate of responsibilities
                    responsibilities = model.responsibility(input_dataset)
                    # calculate the mean of responsibilities
                    means = responsibilities.dot(model.map_grids)
                    # calculate k3n-error
                    k3nerror_of_gtm = k3nerror(input_dataset, means,
                                               k_in_k3nerror)
                else:
                    k3nerror_of_gtm = 10**100
                parameters_and_k3nerror.append([
                    shape_of_map_grid, shape_of_rbf_centers_grid,
                    variance_of_rbfs_grid, lambda_in_em_algorithm_grid,
                    k3nerror_of_gtm
                ])

# optimized GTM
parameters_and_k3nerror = np.array(parameters_and_k3nerror)