Giter Club home page Giter Club logo

Comments (4)

relf avatar relf commented on June 26, 2024

The following code works for me:

import numpy as np
import matplotlib.pyplot as plt

from smt.surrogate_models import KRG
from smt.applications.mixed_integer import MixedIntegerKrigingModel
from smt.utils.design_space import DesignSpace, IntegerVariable

import pickle

xt = np.array([0.0, 2.0, 3.0])
yt = np.array([0.0, 1.5, 0.9])

design_space = DesignSpace(
    [
        IntegerVariable(0, 4),
    ]
)
sm = MixedIntegerKrigingModel(
    surrogate=KRG(design_space=design_space, theta0=[1e-2])
)
sm.set_training_values(xt, yt)
sm.train()

num = 500
x = np.linspace(0.0, 4.0, num)
y = sm.predict_values(x)
# estimated variance
s2 = sm.predict_variances(x)

filename = "kriging.pkl"
with open(filename, "wb") as f:
   pickle.dump(sm, f)

sm2 = None
filename = "kriging.pkl"
with open(filename, "rb") as f:
   sm2 = pickle.load(f)

y_2 = sm2.predict_values(x)
# estimated variance
s2_2 = sm2.predict_variances(x)

np.testing.assert_almost_equal(y, y_2)
np.testing.assert_almost_equal(s2, s2_2)

Could you try it? (Please copy/paste the error message if any)
I guess you may have saved and loaded with different SMT installation.

from smt.

nrthlxne avatar nrthlxne commented on June 26, 2024

Thank you for the fast response, I will give your code a try and report back later today.

You are right, the model was generated and saved using version 2.1.0. There was no issue loading and using the model with version 2.0.1 and the above described error was returned when using version 2.2.1.

from smt.

relf avatar relf commented on June 26, 2024

The self._cs attribute was introduced in #474 in SMT 2.2, it makes a model pickled with previous versions incompatible (sorry for that!). So I guess either you generate your model again with SMT 2.2+ or you just keep SMT 2.1 or... you patch like you did.

from smt.

relf avatar relf commented on June 26, 2024

Closing. Hope you found your way.

from smt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.