예제 #1
0
def run_ards(test_fuction: str,
             N: int,
             noise_std: bool,
             random: bool,
             M: int = 5,
             K: int = 2):
    name = 'rbf'
    store_name = test_fuction + '.{0:d}.{1:.3f}.{2:d}'.format(M, noise_std, N)
    if random:
        store_name += '.random'
    else:
        store_name += '.rom'
    store = data.Store(BASE_PATH / store_name)
    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={
                      'optimizer': 'bfgs',
                      'max_iters': 5000,
                      'gtol': 1E-16
                  },
                  make_ard=True)
예제 #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)
예제 #3
0
def _collect_std(test_function: str, N: int, noise_std: float, random: bool, M: int):
    store = data.Store(store_path(test_function, N, noise_std, random, M))
    destination = store.dir / "results"
    shutil.rmtree(destination, ignore_errors=True)
    destination.mkdir(mode=0o777, parents=True, exist_ok=False)
    result = 0.0
    for k in range(K):
        fold = data.Fold(store, k)
        result += fold.standard.df.iloc[-1, -1]/K
    savetxt(fname=(destination / "std.csv"), X=atleast_2d(result), delimiter=",")
예제 #4
0
def _run_test(test_function: str, N: int, noise_std: float, random: bool, M: int):
    store = data.Store(store_path(test_function, N, noise_std, random, M))
    Mu = choose_Mu(test_function)
    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)
    name = 'rom.reduced'
    model.run.GPs(module=model.run.Module.GPY_, name=name, store=store, M_Used=Mu, 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=Mu, parameters=None, optimize=True, test=True, sobol=True,
                  optimizer_options=gp_optimizer_options, make_ard=True)
예제 #5
0
def test_random3(test_fuction: str, N: int, noise_std: float, M: int = 5, K: int = 2 ):
    random = True
    name = 'derotated.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)
    store_name = test_fuction + '.{0:d}.{1:.3f}.{2:d}'.format(M, noise_std, N)
    store_name += '.random'
    store_name = BASE_PATH / store_name
    store = data.Store(store_name)
    lin_trans = loadtxt(store.dir / "InverseRotation.csv")
    for k in range(K):
        fold = data.Fold(store, k)
        replace_X_with_U(fold, transpose(lin_trans))
    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}}
예제 #6
0

def linear_transformation(model_dir: Path) -> NP.Matrix:
    with open(model_dir / "__meta__.json", mode='r') as file:
        meta = load(file)
    function_with_parameters = meta['origin']['functions_with_parameters'][
        0].split("; matrix=")
    if len(function_with_parameters) > 1:
        function_with_parameters = eval(function_with_parameters[-1][:-1])
        return array(function_with_parameters)
    else:
        return eye(meta['data']['M'], dtype=float)


if __name__ == '__main__':
    store = data.Store((BASE_PATH / NOISELESS_DIR) / "sin.u1.5000.5.random",
                       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)
    print(model_theta)
    print(data_theta)
"""
def rename(dir_: Path):
    for p in dir_.iterdir():
        if p.is_dir():
            if p.name == "rom..optimized":
                p.replace(p.parent / "rom.optimized")
            else:
                rename(p)
"""