def run_rbfs(test_fuction: str, N: int, noise_std: bool, random: bool, M: int = 5, K: int = 2 ):
    name = 'rbf'
    kernel_parameters = model.gpy_.Kernel.ExponentialQuadratic.Parameters(lengthscale=full((1, 1), 0.2, dtype=float))
    parameters = model.gpy_.GP.DEFAULT_PARAMETERS._replace(kernel=kernel_parameters, e_floor=1E-6, e=0.003)
    CDF_scale = 2 * pi
    CDF_loc = pi
    if test_fuction == 'sin.1':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 0.0, 'b': 0.0})
    elif test_fuction == 'sin.2':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 2.0, 'b': 0.0})
    elif test_fuction == 'ishigami':
        function_with_parameters = function.callable_with_parameters(function.ishigami)
    else:
        CDF_scale = 1.0
        CDF_loc = 0.0
        function_with_parameters = function.callable_with_parameters(function.sobol_g)
    store_name = test_fuction + '.{0:d}.{1:.3f}.{2:d}'.format(M, noise_std, N)
    if random:
        pre_function_with_parameters = function.CallableWithParameters(function=function.linear, parameters={'matrix': ortho_group.rvs(M)})
        store_name += '.random'
    else:
        pre_function_with_parameters = None
        store_name += '.rom'
    store_name = BASE_PATH / store_name
    store = scalar_function_of_normal(store_name=store_name, N=N, M=M, X_std=1.0, noise_std=noise_std, CDF_scale=CDF_scale, CDF_loc=CDF_loc,
                                      pre_function_with_parameters=pre_function_with_parameters,
                                      function_with_parameters=function_with_parameters)
    data.Fold.into_K_folds(parent=store, K=K, shuffled_before_folding=False, standard=data.Store.Standard.mean_and_std,
                           replace_empty_test_with_data_=True)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=parameters, optimize=True, test=True, sobol=True)
    sobol_options = {'semi_norm': model.base.Sobol.SemiNorm.DEFAULT_META, 'N_exploit': 3, 'N_explore': 4096, 'options': {'gtol': 1.0E-12}}
    rom_options = {'iterations': 6, 'guess_identity_after_iteration': 2, 'sobol_optimizer_options': sobol_options,
                                 'gp_initializer': model.base.ROM.GP_Initializer.ORIGINAL,
                                 'gp_optimizer_options': model.run.Module.GPY_.value.GP.DEFAULT_OPTIMIZER_OPTIONS}
    model.run.ROMs(module=model.run.Module.GPY_, name='rom', store=store, source_gp_name=name, Mu=-1, Mx=-1, optimizer_options=rom_options)
Example #2
0
def predict_roms(M: int, N: int, random: bool, noisy: bool):
    store_name = 'sin.u1.'
    CDF_scale = 2 * pi
    CDF_loc = pi
    function_with_parameters = function.CallableWithParameters(
        function=function.ishigami, parameters={
            'a': 0,
            'b': 0
        })
    store_name = store_name + '{0:d}.{1:d}'.format(N, M)
    store_name += '.random' if random else '.rom'
    noise_std = 0.0001 if noisy else 0
    store = data.Store(store_dir(store_name, noise_std, CDF_scale),
                       data.Store.InitMode.READ_META_ONLY)
    fold = data.Fold(store, 0)
    rom = model.gpy_.ROM.from_ROM(fold=fold, name='rom', suffix='.test.full')
    model_theta = rom.sobol.parameters_read.Theta
    data_theta = function.linear_matrix_from_meta(store)
    pre_function_with_parameters = (function.CallableWithParameters(
        function=function.linear, parameters={'matrix': data_theta})
                                    if random else None)
    test_store = scalar_function_of_normal(
        store_name=store_name + "\\test",
        N=N,
        M=M,
        X_std=1.0,
        noise_std=noise_std,
        CDF_scale=CDF_scale,
        CDF_loc=CDF_loc,
        pre_function_with_parameters=pre_function_with_parameters,
        function_with_parameters=function_with_parameters)
    fold.set_test_data(df=test_store.data.df)
    rom.sobol.gp.test()
    result = matmul(model_theta, data_theta.T)
    print(result)
Example #3
0
def run_rbfs(test_fuction: str, N: int, noise_std: bool, random: bool, M: int = 5, K: int = 2 ):
    name = 'rbf'
    kernel_parameters = model.gpy_.Kernel.ExponentialQuadratic.Parameters(lengthscale=full((1, 1), 2.0**(M/5), dtype=float))
    parameters = model.gpy_.GP.DEFAULT_PARAMETERS._replace(kernel=kernel_parameters, e_floor=1E-6, e=0.003)
    CDF_scale = 2 * pi
    CDF_loc = pi
    if test_fuction == 'sin.1':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 0.0, 'b': 0.0})
    elif test_fuction == 'sin.2':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 2.0, 'b': 0.0})
    elif test_fuction == 'ishigami':
        function_with_parameters = function.callable_with_parameters(function.ishigami)
    else:
        CDF_scale = 1.0
        CDF_loc = 0.0
        function_with_parameters = function.callable_with_parameters(function.sobol_g)
    store_name = test_fuction + '.{0:d}.{1:.3f}.{2:d}'.format(M, noise_std, N)
    if random:
        pre_function_with_parameters = function.CallableWithParameters(function=function.linear, parameters={'matrix': ortho_group.rvs(M)})
        store_name += '.random'
    else:
        pre_function_with_parameters = None
        store_name += '.rom'
    store_name = BASE_PATH / store_name
    store = scalar_function_of_normal(store_name=store_name, N=N, M=M, X_std=1.0, noise_std=noise_std, CDF_scale=CDF_scale, CDF_loc=CDF_loc,
                                      pre_function_with_parameters=pre_function_with_parameters,
                                      function_with_parameters=function_with_parameters)
    data.Fold.into_K_folds(parent=store, K=K, shuffled_before_folding=False, standard=data.Store.Standard.mean_and_std,
                           replace_empty_test_with_data_=True)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=parameters, optimize=True, test=True, sobol=True,
                  optimizer_options={'optimizer': 'bfgs', 'max_iters': 5000, 'gtol': 1E-16})
Example #4
0
def test_random(test_fuction: str, N: int, noise_std: float, M: int = 5, K: int = 2 ):
    random = True
    name = 'rbf'
    gp_optimizer_options = {'optimizer': 'bfgs', 'max_iters': 5000, 'gtol': 1E-16}
    kernel_parameters = model.gpy_.Kernel.ExponentialQuadratic.Parameters(lengthscale=full((1, 1), 2.5**(M/5), dtype=float))
    parameters = model.gpy_.GP.DEFAULT_PARAMETERS._replace(kernel=kernel_parameters, e_floor=1E-6, e=0.003)
    CDF_scale = 2 * pi
    CDF_loc = pi
    if test_fuction == 'sin.1':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 0.0, 'b': 0.0})
    elif test_fuction == 'sin.2':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 2.0, 'b': 0.0})
    elif test_fuction == 'ishigami':
        function_with_parameters = function.callable_with_parameters(function.ishigami)
    else:
        CDF_scale = 1.0
        CDF_loc = 0.0
        function_with_parameters = function.CallableWithParameters(function.sobol_g,
                                                                   parameters={'m_very_important': 2, 'm_important': 3, 'm_unimportant': 4})
    store_name = test_fuction + '.{0:d}.{1:.3f}.{2:d}'.format(M, noise_std, N)
    if random:
        lin_trans = ortho_group.rvs(M)
        pre_function_with_parameters = function.CallableWithParameters(function=function.linear, parameters={'matrix': lin_trans})
        store_name += '.random'
    else:
        pre_function_with_parameters = None
        store_name += '.rom'
    store_name = BASE_PATH / store_name
    store = scalar_function_of_normal(store_name=store_name, N=N, M=M, X_std=1.0, noise_std=noise_std, CDF_scale=CDF_scale, CDF_loc=CDF_loc,
                                      pre_function_with_parameters=pre_function_with_parameters,
                                      function_with_parameters=function_with_parameters)
    # lin_trans = transpose(lin_trans)
    savetxt(store.dir / "InverseRotation.csv", lin_trans)
    data.Fold.into_K_folds(parent=store, K=K, shuffled_before_folding=False, standard=data.Store.Standard.mean_and_std,
                           replace_empty_test_with_data_=True)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=parameters, optimize=True, test=True, sobol=True,
                  optimizer_options=gp_optimizer_options)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=None, optimize=True, test=True, sobol=True,
                  optimizer_options=gp_optimizer_options, make_ard=True)
    sobol_options = {'semi_norm': model.base.Sobol.SemiNorm.DEFAULT_META, 'N_exploit': 3, 'N_explore': 4096, 'options': {'gtol': 1.0E-16}}
    for k in range(K):
        sobol = model.gpy_.Sobol.from_GP(data.Fold(store, k), 'rbf.ard', 'rbf.ard.derotated')
        for sobol.m in reversed(range(M)):
            sobol.Theta_old = lin_trans
        sobol.write_parameters(sobol.Parameters(Mu=sobol.Mu, Theta=sobol.Theta, D=sobol.Tensor3AsMatrix(sobol.D), S1=None,
                                                S=sobol.Tensor3AsMatrix(sobol.S)))
Example #5
0
def run_roms(test_fuction: str, N: int, noise_std: float, random: bool, M: int = 5, K: int = 2 ):
    name = 'rbf'
    gp_optimizer_options = {'optimizer': 'bfgs', 'max_iters': 5000, 'gtol': 1E-16}
    kernel_parameters = model.gpy_.Kernel.ExponentialQuadratic.Parameters(lengthscale=full((1, 1), 2.5**(M/5), dtype=float))
    parameters = model.gpy_.GP.DEFAULT_PARAMETERS._replace(kernel=kernel_parameters, e_floor=1E-6, e=0.003)
    CDF_scale = 2 * pi
    CDF_loc = pi
    if test_fuction == 'sin.1':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 0.0, 'b': 0.0})
    elif test_fuction == 'sin.2':
        function_with_parameters = function.CallableWithParameters(function.ishigami, parameters={'a': 2.0, 'b': 0.0})
    elif test_fuction == 'ishigami':
        function_with_parameters = function.callable_with_parameters(function.ishigami)
    else:
        CDF_scale = 1.0
        CDF_loc = 0.0
        function_with_parameters = function.CallableWithParameters(function.sobol_g,
                                                                   parameters={'m_very_important': 2, 'm_important': 3, 'm_unimportant': 4})
    store_name = test_fuction + '.{0:d}.{1:.3f}.{2:d}'.format(M, noise_std, N)
    if random:
        lin_trans = ortho_group.rvs(M)
        pre_function_with_parameters = function.CallableWithParameters(function=function.linear, parameters={'matrix': lin_trans})
        store_name += '.random'
    else:
        pre_function_with_parameters = None
        store_name += '.rom'
    store_name = BASE_PATH / store_name
    store = scalar_function_of_normal(store_name=store_name, N=N, M=M, X_std=1.0, noise_std=noise_std, CDF_scale=CDF_scale, CDF_loc=CDF_loc,
                                      pre_function_with_parameters=pre_function_with_parameters,
                                      function_with_parameters=function_with_parameters)
    savetxt(store.dir / "InverseRotation.csv", transpose(lin_trans))
    data.Fold.into_K_folds(parent=store, K=K, shuffled_before_folding=False, standard=data.Store.Standard.mean_and_std,
                           replace_empty_test_with_data_=True)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=parameters, optimize=True, test=True, sobol=True,
                  optimizer_options=gp_optimizer_options)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=None, optimize=True, test=True, sobol=True,
                  optimizer_options=gp_optimizer_options, make_ard=True)
    sobol_options = {'semi_norm': model.base.Sobol.SemiNorm.DEFAULT_META, 'N_exploit': 3, 'N_explore': 4096, 'options': {'gtol': 1.0E-16}}
    rom_options = {'iterations': 1, 'guess_identity_after_iteration': -1, 'sobol_optimizer_options': sobol_options,
                                 'gp_initializer': model.base.ROM.GP_Initializer.RBF,
                                 'gp_optimizer_options': gp_optimizer_options}
    model.run.ROMs(module=model.run.Module.GPY_, name='rom', store=store, source_gp_name=name, Mu=-1, Mx=-1, optimizer_options=rom_options,
                   rbf_parameters=parameters)
Example #6
0
def run_roms(M: int, N: int, K:int, ishigami: bool, random: bool, noisy: bool):
    name = 'ard'
    kernel_parameters = model.gpy_.Kernel.ExponentialQuadratic.Parameters(lengthscale=full((1, M), 0.2, dtype=float))
    if ishigami:
        store_name = 'sin.2.'
        CDF_scale = 2 * pi
        CDF_loc = pi
        function_with_parameters = function.CallableWithParameters(function=function.ishigami, parameters={'a': 2.0, 'b': 0})
    else:
        store_name = 'sin.1.'
        CDF_scale = 2 * pi
        CDF_loc = pi
        function_with_parameters = function.CallableWithParameters(function=function.ishigami, parameters={'a': 0, 'b': 0})
    store_name = store_name + '{0:d}.{1:d}'.format(N, M)
    if random:
        pre_function_with_parameters = function.CallableWithParameters(function=function.linear, parameters={'matrix': ortho_group.rvs(M)})
        store_name += '.random'
    else:
        pre_function_with_parameters = None
        store_name += '.rom'
    if noisy:
        noise_std = 0.025
        parameters = model.gpy_.GP.DEFAULT_PARAMETERS._replace(kernel=kernel_parameters, e_floor=1E-5, e=0.01)
    else:
        noise_std = 0
        parameters = model.gpy_.GP.DEFAULT_PARAMETERS._replace(kernel=kernel_parameters, e_floor=1E-5, e=1E-10)
    store = scalar_function_of_normal(store_name=store_name, N=N, M=M, X_std=1.0, noise_std=noise_std, CDF_scale=CDF_scale, CDF_loc=CDF_loc,
                                      pre_function_with_parameters=pre_function_with_parameters,
                                      function_with_parameters=function_with_parameters)
    data.Fold.into_K_folds(parent=store, K=K, shuffled_before_folding=False, standard=data.Store.Standard.mean_and_std,
                           replace_empty_test_with_data_=True)
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=-1, parameters=parameters, optimize=True, test=True, sobol=True)
    sobol_options = {'semi_norm': model.base.Sobol.SemiNorm.DEFAULT_META, 'N_exploit': 3, 'N_explore': 4096, 'options': {'gtol': 1.0E-16}}
    rom_options = {'iterations': 4, 'guess_identity_after_iteration': 2, 'sobol_optimizer_options': sobol_options,
                                 'gp_initializer': model.base.ROM.GP_Initializer.CURRENT_WITH_GUESSED_LENGTHSCALE,
                                 'gp_optimizer_options': model.run.Module.GPY_.value.GP.DEFAULT_OPTIMIZER_OPTIONS}
    model.run.ROMs(module=model.run.Module.GPY_, name='rom', store=store, source_gp_name='ard', Mu=-1, Mx=-1, optimizer_options=rom_options)