コード例 #1
0
def create_training_points_irregular_transformed(n_target, noise_level):
    """ create array of training points
    Discard any training points where turbines are
    not in the correct order and any training points where
    turbines are closer than 2D
    Maximin design in the transformed space

    Parameters
    ----------
    n_target: int
        target number of training points
    noise_level: float
        Level of gaussian noise to be added to
        simulator

    Returns
    -------
    X_train:        ndarray of shape(variable,6)
                    array containing valid training points
    X_train_tran:   ndarray of shape(variable,6)
                    array containing valid transformed training points
    y_train:         ndarray of shape(variable,)
                    value of CT* at test points
    n_train:        int
                    number of valid training points
    """
    X_train_tran = dp.maximin_reconstruction(n_target, 6)
    X_train = np.zeros((len(X_train_tran), 6))
    X_train[:, 0] = expon(scale=10).ppf(X_train_tran[:, 0])
    X_train[:, 1] = norm(0, 2.5).ppf(X_train_tran[:, 1])
    X_train[:, 2] = expon(scale=10).ppf(X_train_tran[:, 2])
    X_train[:, 3] = norm(0, 2.5).ppf(X_train_tran[:, 3])
    X_train[:, 4] = expon(scale=10).ppf(X_train_tran[:, 4])
    X_train[:, 5] = norm(0, 2.5).ppf(X_train_tran[:, 5])
    # exclude training points where turbine 1 is closer than 2D
    X_train_dist = np.sqrt(X_train[:, 0]**2 + X_train[:, 1]**2)
    X_train_real = X_train[X_train_dist > 2]
    X_train_tran = X_train_tran[X_train_dist > 2]
    # exclude training points where turbine 2 is more important"
    # than turbine 1 using distance = sqrt(10*x_1^2 + y_1^2)
    X_train_sig = calculate_distance(X_train_real[:, 2],
                                    X_train_real[:, 3]) \
        - calculate_distance(X_train_real[:, 0], X_train_real[:, 1])
    X_train_real = X_train_real[X_train_sig > 0]
    X_train_tran = X_train_tran[X_train_sig > 0]
    # exclude training points where turbine 3 is more important
    # than turbine 2 using distance = sqrt(10*x_1^2 + y_1^2)
    X_train_sig = calculate_distance(X_train_real[:, 4],
                                    X_train_real[:, 5]) \
        - calculate_distance(X_train_real[:, 2], X_train_real[:, 3])
    X_train_real = X_train_real[X_train_sig > 0]
    X_train_tran = X_train_tran[X_train_sig > 0]
    # run simulations to find data points
    y_train = np.zeros(len(X_train_real))
    for i in range(len(X_train_real)):
        y_train[i] = simulator6d_halved(X_train_real[i, :], noise_level)
    n_train = len(X_train_real)
    X_train = X_train_real
    return X_train, X_train_tran, y_train, n_train
コード例 #2
0
def create_testing_points_transformed():
    """ create array of testing points
    Discard any training points where turbines are
    not in the correct order and any training points where
    turbines are closer than 2D
    X_test is tranformed by the cdf of probability distributions
    expon(scale=10) in the x direction and norm(0, 2.5) in the y
    direction

    Parameters
    ----------
    noise_level: float
        Level of gaussian noise to be added to
        simulator

    Returns
    -------
    X_test:         ndarray of shape(variable,6)
                    array containing valid test points
    X_test_tran:    ndarray of shape(varaible,6)
                    array containing valid transformed test points
    y_test:         ndarray of shape(variable,)
                    value of CT* at test points
    """
    X_test = lhs(6, 10000)
    X_test[:, 0] = 30 * X_test[:, 0]
    X_test[:, 1] = 10 * X_test[:, 1] - 5
    X_test[:, 2] = 30 * X_test[:, 2]
    X_test[:, 3] = 10 * X_test[:, 3] - 5
    X_test[:, 4] = 30 * X_test[:, 4]
    X_test[:, 5] = 10 * X_test[:, 5] - 5
    # exclude test points where turbine 1 is closer than 2D
    X_test_dist = np.sqrt(X_test[:, 0]**2 + X_test[:, 1]**2)
    X_test_real = X_test[X_test_dist > 2]
    # exclude test points where turbine 2 is more "important" than turbine 1
    # using distance = sqrt(x_1^2 + k*y_1^2)
    X_test_sig = calculate_distance(X_test_real[:, 2],
                                    X_test_real[:, 3]) \
        - calculate_distance(X_test_real[:, 0], X_test_real[:, 1])
    X_test_real = X_test_real[X_test_sig > 0]
    # exclude test points where turbine 3 is more "important" than turbine 2
    # using distance = sqrt(x_1^2 + k*y_1^2)
    X_test_sig = calculate_distance(X_test_real[:, 4],
                                    X_test_real[:, 5]) \
        - calculate_distance(X_test_real[:, 2], X_test_real[:, 3])
    X_test_real = X_test_real[X_test_sig > 0]
    y_test = np.zeros(len(X_test_real))
    for i in range(len(X_test_real)):
        y_test[i] = simulator6d_halved(X_test_real[i, :])
    X_test = X_test_real
    X_test_tran = np.zeros((len(X_test_real), 6))
    X_test_tran[:, 0] = expon(scale=10).cdf(X_test_real[:, 0])
    X_test_tran[:, 2] = expon(scale=10).cdf(X_test_real[:, 2])
    X_test_tran[:, 4] = expon(scale=10).cdf(X_test_real[:, 4])
    X_test_tran[:, 1] = norm(0, 2.5).cdf(X_test_real[:, 1])
    X_test_tran[:, 3] = norm(0, 2.5).cdf(X_test_real[:, 3])
    X_test_tran[:, 5] = norm(0, 2.5).cdf(X_test_real[:, 5])
    return X_test, X_test_tran, y_test
コード例 #3
0
def validlhs_regular():
    from pyDOE import lhs as lhsd
    n_samples = 0
    while n_samples != 300:
        lhs = lhsd(6, 2800)
        #expand x, y coordinates to their real values
        lhs[:, 0] = expon(scale=10).ppf(lhs[:, 0])
        lhs[:, 1] = norm(0, 2.5).ppf(lhs[:, 1])
        lhs[:, 2] = expon(scale=10).ppf(lhs[:, 2])
        lhs[:, 3] = norm(0, 2.5).ppf(lhs[:, 3])
        lhs[:, 4] = expon(scale=10).ppf(lhs[:, 4])
        lhs[:, 5] = norm(0, 2.5).ppf(lhs[:, 5])
        #exclude points where turbine 2 is closer than turbine 1
        valid_1_2 = calculate_distance(lhs[:, 2],
                                        lhs[:, 3]) \
            - calculate_distance(lhs[:, 0], lhs[:, 1])
        lhs = lhs[valid_1_2 > 0]
        #exclude points where turbine 3 is closer than turbine 2
        valid_2_3 = calculate_distance(lhs[:, 4],
                                        lhs[:, 5]) \
            - calculate_distance(lhs[:, 2], lhs[:, 3])
        lhs = lhs[valid_2_3 > 0]
        #exclude points where turbines are closer than 2D to origin
        dist_1 = np.sqrt(lhs[:, 0]**2 + lhs[:, 1]**2)
        lhs = lhs[dist_1 > 2]
        dist_2 = np.sqrt(lhs[:, 2]**2 + lhs[:, 3]**2)
        lhs = lhs[dist_2 > 2]
        dist_3 = np.sqrt(lhs[:, 4]**2 + lhs[:, 5]**2)
        lhs = lhs[dist_3 > 2]
        #exclude points where turbines are closer than 2D from
        #each other
        dist_1_2 = np.sqrt((lhs[:, 0] - lhs[:, 2])**2 +
                           (lhs[:, 1] - lhs[:, 3])**2)
        lhs = lhs[dist_1_2 > 2]
        dist_2_3 = np.sqrt((lhs[:, 2] - lhs[:, 4])**2 +
                           (lhs[:, 3] - lhs[:, 5])**2)
        lhs = lhs[dist_2_3 > 2]
        dist_3_1 = np.sqrt((lhs[:, 4] - lhs[:, 0])**2 +
                           (lhs[:, 5] - lhs[:, 1])**2)
        lhs = lhs[dist_3_1 > 2]
        n_samples = len(lhs)
        print(n_samples)
    #return to transformed coordinates
    lhs[:, 0] = expon(scale=10).cdf(lhs[:, 0])
    lhs[:, 1] = norm(0, 2.5).cdf(lhs[:, 1])
    lhs[:, 2] = expon(scale=10).cdf(lhs[:, 2])
    lhs[:, 3] = norm(0, 2.5).cdf(lhs[:, 3])
    lhs[:, 4] = expon(scale=10).cdf(lhs[:, 4])
    lhs[:, 5] = norm(0, 2.5).cdf(lhs[:, 5])
    # replace lhs points with nearest regular arrays
    X_reg_tran = np.loadtxt('regular_arrays_no_rot_transformed.txt')
    min_dist = np.zeros(len(X_reg_tran))
    for i in range(len(lhs)):
        diff = np.linalg.norm(X_reg_tran - lhs[i, :], axis=1)
        lhs[i, :] = X_reg_tran[np.argmin(diff), :]
    return lhs
コード例 #4
0
def validlhs():
    from pyDOE import lhs as lhsd
    n_samples = 0
    while n_samples != 300:
        lhs = lhsd(6, 2800)
        #expand x, y coordinates to their real values
        lhs[:, 0] = expon(scale=10).ppf(lhs[:, 0])
        lhs[:, 1] = norm(0, 2.5).ppf(lhs[:, 1])
        lhs[:, 2] = expon(scale=10).ppf(lhs[:, 2])
        lhs[:, 3] = norm(0, 2.5).ppf(lhs[:, 3])
        lhs[:, 4] = expon(scale=10).ppf(lhs[:, 4])
        lhs[:, 5] = norm(0, 2.5).ppf(lhs[:, 5])
        #exclude points where turbine 2 is closer than turbine 1
        valid_1_2 = calculate_distance(lhs[:, 2],
                                        lhs[:, 3]) \
            - calculate_distance(lhs[:, 0], lhs[:, 1])
        lhs = lhs[valid_1_2 > 0]
        #exclude points where turbine 3 is closer than turbine 2
        valid_2_3 = calculate_distance(lhs[:, 4],
                                        lhs[:, 5]) \
            - calculate_distance(lhs[:, 2], lhs[:, 3])
        lhs = lhs[valid_2_3 > 0]
        #exclude points where turbines are closer than 2D to origin
        dist_1 = np.sqrt(lhs[:, 0]**2 + lhs[:, 1]**2)
        lhs = lhs[dist_1 > 2]
        dist_2 = np.sqrt(lhs[:, 2]**2 + lhs[:, 3]**2)
        lhs = lhs[dist_2 > 2]
        dist_3 = np.sqrt(lhs[:, 4]**2 + lhs[:, 5]**2)
        lhs = lhs[dist_3 > 2]
        #exclude points where turbines are closer than 2D from
        #each other
        dist_1_2 = np.sqrt((lhs[:, 0] - lhs[:, 2])**2 +
                           (lhs[:, 1] - lhs[:, 3])**2)
        lhs = lhs[dist_1_2 > 2]
        dist_2_3 = np.sqrt((lhs[:, 2] - lhs[:, 4])**2 +
                           (lhs[:, 3] - lhs[:, 5])**2)
        lhs = lhs[dist_2_3 > 2]
        dist_3_1 = np.sqrt((lhs[:, 4] - lhs[:, 0])**2 +
                           (lhs[:, 5] - lhs[:, 1])**2)
        lhs = lhs[dist_3_1 > 2]
        n_samples = len(lhs)
        print(n_samples)
    #return to transformed coordinates
    lhs[:, 0] = expon(scale=10).cdf(lhs[:, 0])
    lhs[:, 1] = norm(0, 2.5).cdf(lhs[:, 1])
    lhs[:, 2] = expon(scale=10).cdf(lhs[:, 2])
    lhs[:, 3] = norm(0, 2.5).cdf(lhs[:, 3])
    lhs[:, 4] = expon(scale=10).cdf(lhs[:, 4])
    lhs[:, 5] = norm(0, 2.5).cdf(lhs[:, 5])
    return lhs
コード例 #5
0
def create_testing_points(noise_level):
    """ create array of testing points
    Discard any training points where turbines are
    not in the correct order and any training points where
    turbines are closer than 2D

    Parameters
    ----------
    noise_level: float
        Level of gaussian noise to be added to
        simulator

    Returns
    -------
    X_test_real:    ndarray of shape(variable,6)
                    array containing valid test points
    y_test:         ndarray of shape(variable,)
                    value of CT* at test points
    """
    X_test = lhs(6, 1000, 'maximin')
    X_test[:, 0] = 30 * X_test[:, 0]
    X_test[:, 1] = 10 * X_test[:, 1] - 5
    X_test[:, 2] = 30 * X_test[:, 2]
    X_test[:, 3] = 10 * X_test[:, 3] - 5
    X_test[:, 4] = 30 * X_test[:, 4]
    X_test[:, 5] = 10 * X_test[:, 5] - 5
    # exclude test points where turbine 1 is closer than 2D
    X_test_dist = np.sqrt(X_test[:, 0]**2 + X_test[:, 1]**2)
    X_test_real = X_test[X_test_dist > 2]
    # exclude test points where turbine 2 is more "important" than turbine 1
    # using distance = sqrt(x_1^2 + k*y_1^2)
    X_test_sig = calculate_distance(X_test_real[:, 2],
                                    X_test_real[:, 3]) \
        - calculate_distance(X_test_real[:, 0], X_test_real[:, 1])
    X_test_real = X_test_real[X_test_sig > 0]
    # exclude test points where turbine 3 is more "important" than turbine 2
    # using distance = sqrt(x_1^2 + k*y_1^2)
    X_test_sig = calculate_distance(X_test_real[:, 4],
                                    X_test_real[:, 5]) \
        - calculate_distance(X_test_real[:, 2], X_test_real[:, 3])
    X_test_real = X_test_real[X_test_sig > 0]
    y_test = np.zeros(len(X_test_real))
    for i in range(len(X_test_real)):
        y_test[i] = simulator6d_halved(X_test_real[i, :], noise_level)
    return X_test_real, y_test