Skip to content

At least one option is reset when loading a GPX surrogate from file: print_global #733

Description

@esnguyenvan

Hey!

After playing with #732 I realised that at least one option is reset when loading a GPX from a saved file. In my case, it's the print_global option that gets reset, I haven't investigated further but it may be the case for other options.

I re-used Enrico's sample code:

from pathlib import Path

import pandas as pd
from smt.surrogate_models import GPX, KRG

PATH_DOE = Path(__file__).parent / "doe_example.csv"
PATH_SURROGATE = Path(__file__).parent / "surrogate.json"

data = pd.read_csv(PATH_DOE)

y_train = data["out1"].to_numpy()
x_train = data.drop(columns="out1").to_numpy()

surrogate = GPX(
    theta0=[1e-1],
    theta_bounds=[1e-6, 20e0],
    print_global = False,
)
surrogate.set_training_values(x_train, y_train)
surrogate.train()

# Check the value of print_global
print("Initial value of print_global: ", surrogate.options._dict['print_global'])

# Save
surrogate.save(PATH_SURROGATE.as_posix())

#Load
surrogate_loaded_smt = GPX.load(PATH_SURROGATE.as_posix())

print("Value of print_global, after reload from file: ", surrogate_loaded_smt.options._dict['print_global'])

# Retry with KRG
surrogate_krg = KRG(
    theta0=[1e-1],
    theta_bounds=[1e-6, 20e0],
    print_global = False,
)
surrogate_krg.set_training_values(x_train, y_train)
surrogate_krg.train()

surrogate_krg.save(PATH_SURROGATE.as_posix())
surrogate_krg_loaded = KRG.load(PATH_SURROGATE.as_posix())

print("Initial value of print_global with KRG: ", surrogate_krg.options._dict['print_global'])
print("Value of print_global, after reload from file with KRG: ", surrogate_krg_loaded.options._dict['print_global'])

With the same data in deo_example.csv file:

,in1,in2,in3,in4,in5,out1
0,17.29527629,0.299723272,0.119148789,0.121477063,0.089776587,0.5
1,12.31335104,0.063619377,0.127541093,0.11526527,0.110776079,0.6
2,17.02670356,0.013510148,0.123028355,0.131023021,0.116939302,0.7
3,14.44708333,0.14615784,0.126824464,0.123176709,0.122047058,0.8
4,12.67327884,0.164918608,0.131369514,0.105941044,0.09386734,0.9

Give the following output:

Initial value of print_global:  False
Value of print_global, after reload from file:  True
Initial value of print_global with KRG:  False
Value of print_global, after reload from file with KRG:  False

Current version of SMT: 2.9.3 and egobox: 0.29.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions