diff --git a/doc/_src_docs/applications/Mixed_Hier_surr.rst b/doc/_src_docs/applications/Mixed_Hier_surr.rst index 09c29327d..93cf61e28 100644 --- a/doc/_src_docs/applications/Mixed_Hier_surr.rst +++ b/doc/_src_docs/applications/Mixed_Hier_surr.rst @@ -61,7 +61,7 @@ Example of mixed integer Polynomial (QP) surrogate # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0000598 + Predicting - done. Time (sec): 0.0000551 Prediction time/pt. (sec) : 0.0000006 @@ -224,9 +224,9 @@ Example of mixed integer Gower Distance model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0083411 + Predicting - done. Time (sec): 0.0078330 - Prediction time/pt. (sec) : 0.0000834 + Prediction time/pt. (sec) : 0.0000783 ___________________________________________________________________________ @@ -235,9 +235,9 @@ Example of mixed integer Gower Distance model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0082445 + Predicting - done. Time (sec): 0.0078776 - Prediction time/pt. (sec) : 0.0000824 + Prediction time/pt. (sec) : 0.0000788 ___________________________________________________________________________ @@ -246,9 +246,9 @@ Example of mixed integer Gower Distance model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0082402 + Predicting - done. Time (sec): 0.0078387 - Prediction time/pt. (sec) : 0.0000824 + Prediction time/pt. (sec) : 0.0000784 .. figure:: Mixed_Hier_surr_TestMixedInteger_run_mixed_gower_example.png @@ -412,9 +412,9 @@ Example of mixed integer Compound Symmetry model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0098972 + Predicting - done. Time (sec): 0.0095315 - Prediction time/pt. (sec) : 0.0000990 + Prediction time/pt. (sec) : 0.0000953 ___________________________________________________________________________ @@ -423,9 +423,9 @@ Example of mixed integer Compound Symmetry model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0098805 + Predicting - done. Time (sec): 0.0095360 - Prediction time/pt. (sec) : 0.0000988 + Prediction time/pt. (sec) : 0.0000954 ___________________________________________________________________________ @@ -434,9 +434,9 @@ Example of mixed integer Compound Symmetry model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0099378 + Predicting - done. Time (sec): 0.0095096 - Prediction time/pt. (sec) : 0.0000994 + Prediction time/pt. (sec) : 0.0000951 .. figure:: Mixed_Hier_surr_TestMixedInteger_run_mixed_cs_example.png @@ -593,9 +593,9 @@ Example of mixed integer Homoscedastic Hypersphere model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0099890 + Predicting - done. Time (sec): 0.0094757 - Prediction time/pt. (sec) : 0.0000999 + Prediction time/pt. (sec) : 0.0000948 ___________________________________________________________________________ @@ -604,9 +604,9 @@ Example of mixed integer Homoscedastic Hypersphere model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0100174 + Predicting - done. Time (sec): 0.0094945 - Prediction time/pt. (sec) : 0.0001002 + Prediction time/pt. (sec) : 0.0000949 ___________________________________________________________________________ @@ -615,9 +615,9 @@ Example of mixed integer Homoscedastic Hypersphere model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0100038 + Predicting - done. Time (sec): 0.0095246 - Prediction time/pt. (sec) : 0.0001000 + Prediction time/pt. (sec) : 0.0000952 .. figure:: Mixed_Hier_surr_TestMixedInteger_run_mixed_homo_hyp_example.png @@ -774,9 +774,9 @@ Example of mixed integer Exponential Homoscedastic Hypersphere model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0099664 + Predicting - done. Time (sec): 0.0095108 - Prediction time/pt. (sec) : 0.0000997 + Prediction time/pt. (sec) : 0.0000951 ___________________________________________________________________________ @@ -785,9 +785,9 @@ Example of mixed integer Exponential Homoscedastic Hypersphere model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0101118 + Predicting - done. Time (sec): 0.0096247 - Prediction time/pt. (sec) : 0.0001011 + Prediction time/pt. (sec) : 0.0000962 ___________________________________________________________________________ @@ -796,9 +796,9 @@ Example of mixed integer Exponential Homoscedastic Hypersphere model # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0099428 + Predicting - done. Time (sec): 0.0095794 - Prediction time/pt. (sec) : 0.0000994 + Prediction time/pt. (sec) : 0.0000958 .. figure:: Mixed_Hier_surr_TestMixedInteger_run_mixed_homo_gaussian_example.png @@ -1000,9 +1000,9 @@ Example of mixed integer Kriging with hierarchical variables # eval points. : 15 Predicting ... - Predicting - done. Time (sec): 0.0084703 + Predicting - done. Time (sec): 0.0085273 - Prediction time/pt. (sec) : 0.0005647 + Prediction time/pt. (sec) : 0.0005685 diff --git a/doc/_src_docs/applications/Mixed_Hier_usage.rst b/doc/_src_docs/applications/Mixed_Hier_usage.rst index 027da06b4..b8c9642c3 100644 --- a/doc/_src_docs/applications/Mixed_Hier_usage.rst +++ b/doc/_src_docs/applications/Mixed_Hier_usage.rst @@ -46,6 +46,7 @@ The design space is then defined from a list of design variables and implements ) from smt.sampling_methods import LHS from smt.applications.mixed_integer import MixedIntegerSamplingMethod + ds = DesignSpace( [ CategoricalVariable( @@ -111,7 +112,10 @@ The hierarchy relationships are specified after instantiating the design space: OrdinalVariable, CategoricalVariable, ) - from smt.applications.mixed_integer import MixedIntegerKrigingModel, MixedIntegerSamplingMethod + from smt.applications.mixed_integer import ( + MixedIntegerKrigingModel, + MixedIntegerSamplingMethod, + ) from smt.surrogate_models import MixIntKernelType, MixHrcKernelType, KRG from smt.sampling_methods import LHS @@ -228,9 +232,9 @@ The hierarchy relationships are specified after instantiating the design space: # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.3314385 + Predicting - done. Time (sec): 0.3353465 - Prediction time/pt. (sec) : 0.0033144 + Prediction time/pt. (sec) : 0.0033535 Pred_RMSE 4.092408537263059e-13 @@ -273,6 +277,7 @@ Example of sampling a mixed-discrete design space ) from smt.sampling_methods import LHS from smt.applications.mixed_integer import MixedIntegerSamplingMethod + float_var = FloatVariable(0, 4) cat_var = CategoricalVariable(["blue", "red"]) @@ -319,7 +324,10 @@ Example of mixed integer context usage import matplotlib.pyplot as plt from smt.surrogate_models import KRG - from smt.applications.mixed_integer import MixedIntegerContext,MixedIntegerSamplingMethod + from smt.applications.mixed_integer import ( + MixedIntegerContext, + MixedIntegerSamplingMethod, + ) from smt.utils.design_space import ( DesignSpace, FloatVariable, @@ -376,9 +384,9 @@ Example of mixed integer context usage # eval points. : 50 Predicting ... - Predicting - done. Time (sec): 0.0133548 + Predicting - done. Time (sec): 0.0130029 - Prediction time/pt. (sec) : 0.0002671 + Prediction time/pt. (sec) : 0.0002601 .. figure:: Mixed_Hier_usage_TestMixedInteger_run_mixed_integer_context_example.png diff --git a/doc/_src_docs/applications/Mixed_Hier_usage_TestMixedInteger_run_mixed_integer_context_example.png b/doc/_src_docs/applications/Mixed_Hier_usage_TestMixedInteger_run_mixed_integer_context_example.png index 216f3d9f9..24d597da8 100644 Binary files a/doc/_src_docs/applications/Mixed_Hier_usage_TestMixedInteger_run_mixed_integer_context_example.png and b/doc/_src_docs/applications/Mixed_Hier_usage_TestMixedInteger_run_mixed_integer_context_example.png differ diff --git a/doc/_src_docs/applications/ego.rst b/doc/_src_docs/applications/ego.rst index 8b6e71c0b..84f8d75d8 100644 --- a/doc/_src_docs/applications/ego.rst +++ b/doc/_src_docs/applications/ego.rst @@ -549,7 +549,7 @@ Usage with mixed variable :: - Minimum in x=[-4.88913486 2. 0. 0. ] with f(x)=-14.7 + Minimum in x=[-4.88374647 2. 0. 0. ] with f(x)=-14.7 .. figure:: ego_TestEGO_run_ego_mixed_integer_example.png :scale: 80 % @@ -605,7 +605,7 @@ Options - ['str'] - Approximated q-EI maximization strategy * - evaluator - - + - - None - ['Evaluator'] - Object used to run function fun to optimize at x points (nsamples, nxdim) @@ -635,7 +635,7 @@ Options - ['bool'] - Enable the penalization of points that have been already evaluated in EI criterion * - surrogate - - + - - None - ['KRG', 'KPLS', 'KPLSK', 'GEKPLS', 'MGP'] - SMT kriging-based surrogate model used internaly diff --git a/doc/_src_docs/applications/mfk.rst b/doc/_src_docs/applications/mfk.rst index c5f1ed673..6d5147def 100644 --- a/doc/_src_docs/applications/mfk.rst +++ b/doc/_src_docs/applications/mfk.rst @@ -103,7 +103,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.9827604 + Training - done. Time (sec): 0.9694319 ___________________________________________________________________________ Evaluation @@ -111,9 +111,9 @@ Usage # eval points. : 101 Predicting ... - Predicting - done. Time (sec): 0.0007160 + Predicting - done. Time (sec): 0.0007062 - Prediction time/pt. (sec) : 0.0000071 + Prediction time/pt. (sec) : 0.0000070 ___________________________________________________________________________ @@ -122,9 +122,9 @@ Usage # eval points. : 101 Predicting ... - Predicting - done. Time (sec): 0.0007083 + Predicting - done. Time (sec): 0.0007169 - Prediction time/pt. (sec) : 0.0000070 + Prediction time/pt. (sec) : 0.0000071 .. figure:: mfk_TestMFK_run_mfk_example.png diff --git a/doc/_src_docs/applications/mfkpls.rst b/doc/_src_docs/applications/mfkpls.rst index c188071ba..42a2b5acd 100644 --- a/doc/_src_docs/applications/mfkpls.rst +++ b/doc/_src_docs/applications/mfkpls.rst @@ -108,7 +108,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.1955945 + Training - done. Time (sec): 0.2026711 ___________________________________________________________________________ Evaluation @@ -116,9 +116,9 @@ Usage # eval points. : 101 Predicting ... - Predicting - done. Time (sec): 0.0007906 + Predicting - done. Time (sec): 0.0007112 - Prediction time/pt. (sec) : 0.0000078 + Prediction time/pt. (sec) : 0.0000070 ___________________________________________________________________________ @@ -127,9 +127,9 @@ Usage # eval points. : 101 Predicting ... - Predicting - done. Time (sec): 0.0007710 + Predicting - done. Time (sec): 0.0007598 - Prediction time/pt. (sec) : 0.0000076 + Prediction time/pt. (sec) : 0.0000075 .. figure:: mfkpls_TestMFKPLS_run_mfkpls_example.png diff --git a/doc/_src_docs/applications/mfkplsk.rst b/doc/_src_docs/applications/mfkplsk.rst index 51deaeaae..0a8df811d 100644 --- a/doc/_src_docs/applications/mfkplsk.rst +++ b/doc/_src_docs/applications/mfkplsk.rst @@ -108,7 +108,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.2852046 + Training - done. Time (sec): 0.2900028 ___________________________________________________________________________ Evaluation @@ -116,7 +116,7 @@ Usage # eval points. : 101 Predicting ... - Predicting - done. Time (sec): 0.0007157 + Predicting - done. Time (sec): 0.0007162 Prediction time/pt. (sec) : 0.0000071 @@ -127,7 +127,7 @@ Usage # eval points. : 101 Predicting ... - Predicting - done. Time (sec): 0.0007243 + Predicting - done. Time (sec): 0.0007234 Prediction time/pt. (sec) : 0.0000072 diff --git a/doc/_src_docs/applications/mgp.rst b/doc/_src_docs/applications/mgp.rst index 188851795..cd7d6cc60 100644 --- a/doc/_src_docs/applications/mgp.rst +++ b/doc/_src_docs/applications/mgp.rst @@ -128,7 +128,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.9149678 + Training - done. Time (sec): 0.9189811 .. figure:: mgp_Test_test_mgp.png :scale: 80 % diff --git a/doc/_src_docs/applications/vfm.rst b/doc/_src_docs/applications/vfm.rst index 8c134b71c..22323a186 100644 --- a/doc/_src_docs/applications/vfm.rst +++ b/doc/_src_docs/applications/vfm.rst @@ -123,7 +123,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.3257585 + Training - done. Time (sec): 0.3460555 .. figure:: vfm_TestVFM_run_vfm_example.png :scale: 80 % diff --git a/doc/_src_docs/applications/vfm_TestVFM_run_vfm_example.png b/doc/_src_docs/applications/vfm_TestVFM_run_vfm_example.png index 5f7984f08..4fb54533c 100644 Binary files a/doc/_src_docs/applications/vfm_TestVFM_run_vfm_example.png and b/doc/_src_docs/applications/vfm_TestVFM_run_vfm_example.png differ diff --git a/doc/_src_docs/examples/b777_engine/b777_engine.png b/doc/_src_docs/examples/b777_engine/b777_engine.png index d3d85390a..dc4142706 100644 Binary files a/doc/_src_docs/examples/b777_engine/b777_engine.png and b/doc/_src_docs/examples/b777_engine/b777_engine.png differ diff --git a/doc/_src_docs/problems/mixedcantileverbeam_Test_test_mixed_cantilever_beam.png b/doc/_src_docs/problems/mixedcantileverbeam_Test_test_mixed_cantilever_beam.png index 89ccfba12..11eeedb41 100644 Binary files a/doc/_src_docs/problems/mixedcantileverbeam_Test_test_mixed_cantilever_beam.png and b/doc/_src_docs/problems/mixedcantileverbeam_Test_test_mixed_cantilever_beam.png differ diff --git a/doc/_src_docs/sampling_methods/lhs_Test_run_lhs.png b/doc/_src_docs/sampling_methods/lhs_Test_run_lhs.png index 211ffd595..378dc4145 100644 Binary files a/doc/_src_docs/sampling_methods/lhs_Test_run_lhs.png and b/doc/_src_docs/sampling_methods/lhs_Test_run_lhs.png differ diff --git a/doc/_src_docs/sampling_methods_Test_run_random.png b/doc/_src_docs/sampling_methods_Test_run_random.png index 7077357b1..5a7a5b944 100644 Binary files a/doc/_src_docs/sampling_methods_Test_run_random.png and b/doc/_src_docs/sampling_methods_Test_run_random.png differ diff --git a/doc/_src_docs/surrogate_models.rst b/doc/_src_docs/surrogate_models.rst index 55738bfba..68fed852b 100644 --- a/doc/_src_docs/surrogate_models.rst +++ b/doc/_src_docs/surrogate_models.rst @@ -67,13 +67,13 @@ Usage Training ... Initializing linear solver ... Performing LU fact. (5 x 5 mtx) ... - Performing LU fact. (5 x 5 mtx) - done. Time (sec): 0.0001042 - Initializing linear solver - done. Time (sec): 0.0001271 + Performing LU fact. (5 x 5 mtx) - done. Time (sec): 0.0001369 + Initializing linear solver - done. Time (sec): 0.0001638 Solving linear system (col. 0) ... Back solving (5 x 5 mtx) ... - Back solving (5 x 5 mtx) - done. Time (sec): 0.0000641 - Solving linear system (col. 0) - done. Time (sec): 0.0000830 - Training - done. Time (sec): 0.0005043 + Back solving (5 x 5 mtx) - done. Time (sec): 0.0000687 + Solving linear system (col. 0) - done. Time (sec): 0.0000892 + Training - done. Time (sec): 0.0008070 ___________________________________________________________________________ Evaluation @@ -81,7 +81,7 @@ Usage # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0000305 + Predicting - done. Time (sec): 0.0000319 Prediction time/pt. (sec) : 0.0000003 diff --git a/doc/_src_docs/surrogate_models/gekpls.rst b/doc/_src_docs/surrogate_models/gekpls.rst index f9657d7fe..531be6092 100644 --- a/doc/_src_docs/surrogate_models/gekpls.rst +++ b/doc/_src_docs/surrogate_models/gekpls.rst @@ -98,7 +98,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.1718783 + Training - done. Time (sec): 0.1667199 .. figure:: gekpls_Test_test_gekpls.png :scale: 80 % diff --git a/doc/_src_docs/surrogate_models/gekpls_Test_test_gekpls.png b/doc/_src_docs/surrogate_models/gekpls_Test_test_gekpls.png index 35ac62a26..a9c58eaf3 100644 Binary files a/doc/_src_docs/surrogate_models/gekpls_Test_test_gekpls.png and b/doc/_src_docs/surrogate_models/gekpls_Test_test_gekpls.png differ diff --git a/doc/_src_docs/surrogate_models/genn.rst b/doc/_src_docs/surrogate_models/genn.rst index 008ee16fd..5cb0af729 100644 --- a/doc/_src_docs/surrogate_models/genn.rst +++ b/doc/_src_docs/surrogate_models/genn.rst @@ -107,27 +107,27 @@ Usage Training Training ... - epoch = 0, mini-batch = 0, avg cost = 15.913 - epoch = 1, mini-batch = 0, avg cost = 0.776 - epoch = 2, mini-batch = 0, avg cost = 0.664 - epoch = 3, mini-batch = 0, avg cost = 0.646 - epoch = 4, mini-batch = 0, avg cost = 0.632 + epoch = 0, mini-batch = 0, avg cost = 15.902 + epoch = 1, mini-batch = 0, avg cost = 0.821 + epoch = 2, mini-batch = 0, avg cost = 0.677 + epoch = 3, mini-batch = 0, avg cost = 0.647 + epoch = 4, mini-batch = 0, avg cost = 0.631 epoch = 5, mini-batch = 0, avg cost = 0.623 - epoch = 6, mini-batch = 0, avg cost = 0.617 - epoch = 7, mini-batch = 0, avg cost = 0.610 - epoch = 8, mini-batch = 0, avg cost = 0.605 - epoch = 9, mini-batch = 0, avg cost = 0.600 - epoch = 10, mini-batch = 0, avg cost = 0.597 - epoch = 11, mini-batch = 0, avg cost = 0.593 - epoch = 12, mini-batch = 0, avg cost = 0.590 - epoch = 13, mini-batch = 0, avg cost = 0.586 - epoch = 14, mini-batch = 0, avg cost = 0.584 - epoch = 15, mini-batch = 0, avg cost = 0.581 - epoch = 16, mini-batch = 0, avg cost = 0.580 + epoch = 6, mini-batch = 0, avg cost = 0.614 + epoch = 7, mini-batch = 0, avg cost = 0.607 + epoch = 8, mini-batch = 0, avg cost = 0.603 + epoch = 9, mini-batch = 0, avg cost = 0.599 + epoch = 10, mini-batch = 0, avg cost = 0.595 + epoch = 11, mini-batch = 0, avg cost = 0.591 + epoch = 12, mini-batch = 0, avg cost = 0.588 + epoch = 13, mini-batch = 0, avg cost = 0.584 + epoch = 14, mini-batch = 0, avg cost = 0.581 + epoch = 15, mini-batch = 0, avg cost = 0.580 + epoch = 16, mini-batch = 0, avg cost = 0.578 epoch = 17, mini-batch = 0, avg cost = 0.578 epoch = 18, mini-batch = 0, avg cost = 0.576 - epoch = 19, mini-batch = 0, avg cost = 0.574 - Training - done. Time (sec): 5.6117277 + epoch = 19, mini-batch = 0, avg cost = 0.575 + Training - done. Time (sec): 5.8601959 ___________________________________________________________________________ Evaluation @@ -135,9 +135,9 @@ Usage # eval points. : 629 Predicting ... - Predicting - done. Time (sec): 0.0006106 + Predicting - done. Time (sec): 0.0005648 - Prediction time/pt. (sec) : 0.0000010 + Prediction time/pt. (sec) : 0.0000009 .. figure:: genn_Test_test_genn.png diff --git a/doc/_src_docs/surrogate_models/genn_Test_test_genn.png b/doc/_src_docs/surrogate_models/genn_Test_test_genn.png index 251f6eca3..a3283b9c2 100644 Binary files a/doc/_src_docs/surrogate_models/genn_Test_test_genn.png and b/doc/_src_docs/surrogate_models/genn_Test_test_genn.png differ diff --git a/doc/_src_docs/surrogate_models/idw.rst b/doc/_src_docs/surrogate_models/idw.rst index 998cabd39..49a02b584 100644 --- a/doc/_src_docs/surrogate_models/idw.rst +++ b/doc/_src_docs/surrogate_models/idw.rst @@ -79,7 +79,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.0001416 + Training - done. Time (sec): 0.0001373 ___________________________________________________________________________ Evaluation @@ -87,7 +87,7 @@ Usage # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0000296 + Predicting - done. Time (sec): 0.0000293 Prediction time/pt. (sec) : 0.0000003 diff --git a/doc/_src_docs/surrogate_models/kpls.rst b/doc/_src_docs/surrogate_models/kpls.rst index f4a337ec0..4d96b7b91 100644 --- a/doc/_src_docs/surrogate_models/kpls.rst +++ b/doc/_src_docs/surrogate_models/kpls.rst @@ -83,7 +83,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.1402104 + Training - done. Time (sec): 0.1393197 ___________________________________________________________________________ Evaluation @@ -91,9 +91,9 @@ Usage # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0025821 + Predicting - done. Time (sec): 0.0027955 - Prediction time/pt. (sec) : 0.0000258 + Prediction time/pt. (sec) : 0.0000280 ___________________________________________________________________________ @@ -102,9 +102,9 @@ Usage # eval points. : 5 Predicting ... - Predicting - done. Time (sec): 0.0004458 + Predicting - done. Time (sec): 0.0004513 - Prediction time/pt. (sec) : 0.0000892 + Prediction time/pt. (sec) : 0.0000903 .. figure:: kpls_Test_test_kpls.png @@ -158,7 +158,7 @@ Usage with an automatic number of components Training Training ... - Training - done. Time (sec): 14.0136063 + Training - done. Time (sec): 13.8389244 The model automatically choose 3 components. ___________________________________________________________________________ @@ -168,9 +168,9 @@ Usage with an automatic number of components # eval points. : 1 Predicting ... - Predicting - done. Time (sec): 0.0011318 + Predicting - done. Time (sec): 0.0010622 - Prediction time/pt. (sec) : 0.0011318 + Prediction time/pt. (sec) : 0.0010622 [[139.34911523]] [[212.53624102]] diff --git a/doc/_src_docs/surrogate_models/kplsk.rst b/doc/_src_docs/surrogate_models/kplsk.rst index 91b1bd0d8..371f1182e 100644 --- a/doc/_src_docs/surrogate_models/kplsk.rst +++ b/doc/_src_docs/surrogate_models/kplsk.rst @@ -85,7 +85,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.2621579 + Training - done. Time (sec): 0.2572036 ___________________________________________________________________________ Evaluation @@ -93,9 +93,9 @@ Usage # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0025518 + Predicting - done. Time (sec): 0.0025406 - Prediction time/pt. (sec) : 0.0000255 + Prediction time/pt. (sec) : 0.0000254 ___________________________________________________________________________ @@ -104,9 +104,9 @@ Usage # eval points. : 5 Predicting ... - Predicting - done. Time (sec): 0.0004759 + Predicting - done. Time (sec): 0.0004628 - Prediction time/pt. (sec) : 0.0000952 + Prediction time/pt. (sec) : 0.0000926 .. figure:: kplsk_Test_test_kplsk.png diff --git a/doc/_src_docs/surrogate_models/krg.rst b/doc/_src_docs/surrogate_models/krg.rst index d4bfab473..850ae0fa0 100644 --- a/doc/_src_docs/surrogate_models/krg.rst +++ b/doc/_src_docs/surrogate_models/krg.rst @@ -39,7 +39,13 @@ Matérn 3/2 correlation function: .. math :: \prod\limits_{l=1}^{nx} \left(1 + \sqrt{3}\theta_{l}\left|x_l^{(i)}-x_l^{(j)}\right|\right) \exp\left(-\sqrt{3}\theta_{l}\left|x_l^{(i)}-x_l^{(j)}\right|\right), \quad \forall\ \theta_l\in\mathbb{R}^+ -These correlation functions are called by 'abs_exp' (exponential), 'squar_exp' (Gaussian), 'matern52' and 'matern32' in SMT. +Exponential Squared Sine correlation function: + +.. math :: + \prod\limits_{l=1}^{nx}\exp\left(-\theta_{l_1} \left( \sin \left( \theta_{l_2} \left( x_l^{(i)}-x_l^{(j)} \right)\right)^{2} \right) \right), \quad \forall\ \theta_l\in\mathbb{R}^+ + + +These correlation functions are called by 'abs_exp' (exponential), 'squar_exp' (Gaussian), 'matern52','matern32' and 'squar_sin_exp' in SMT. The deterministic term :math:`\sum\limits_{i=1}^k\beta_i f_i({\bf x})` can be replaced by a constant, a linear model, or a quadratic model. These three types are available in SMT. @@ -136,7 +142,7 @@ Example 1 Training Training ... - Training - done. Time (sec): 0.1418922 + Training - done. Time (sec): 0.1495888 ___________________________________________________________________________ Evaluation @@ -144,9 +150,9 @@ Example 1 # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0025797 + Predicting - done. Time (sec): 0.0031855 - Prediction time/pt. (sec) : 0.0000258 + Prediction time/pt. (sec) : 0.0000319 ___________________________________________________________________________ @@ -155,9 +161,9 @@ Example 1 # eval points. : 5 Predicting ... - Predicting - done. Time (sec): 0.0004814 + Predicting - done. Time (sec): 0.0004728 - Prediction time/pt. (sec) : 0.0000963 + Prediction time/pt. (sec) : 0.0000946 .. figure:: krg_Test_test_krg.png @@ -223,9 +229,9 @@ Example 2 with mixed variables # eval points. : 500 Predicting ... - Predicting - done. Time (sec): 0.0096698 + Predicting - done. Time (sec): 0.0097091 - Prediction time/pt. (sec) : 0.0000193 + Prediction time/pt. (sec) : 0.0000194 .. figure:: krg_Test_test_mixed_int_krg.png diff --git a/doc/_src_docs/surrogate_models/krg.rstx b/doc/_src_docs/surrogate_models/krg.rstx index 9598a18a3..93c824159 100644 --- a/doc/_src_docs/surrogate_models/krg.rstx +++ b/doc/_src_docs/surrogate_models/krg.rstx @@ -39,7 +39,13 @@ Matérn 3/2 correlation function: .. math :: \prod\limits_{l=1}^{nx} \left(1 + \sqrt{3}\theta_{l}\left|x_l^{(i)}-x_l^{(j)}\right|\right) \exp\left(-\sqrt{3}\theta_{l}\left|x_l^{(i)}-x_l^{(j)}\right|\right), \quad \forall\ \theta_l\in\mathbb{R}^+ -These correlation functions are called by 'abs_exp' (exponential), 'squar_exp' (Gaussian), 'matern52' and 'matern32' in SMT. +Exponential Squared Sine correlation function: + +.. math :: + \prod\limits_{l=1}^{nx}\exp\left(-\theta_{l_1} \left( \sin \left( \theta_{l_2} \left( x_l^{(i)}-x_l^{(j)} \right)\right)^{2} \right) \right), \quad \forall\ \theta_l\in\mathbb{R}^+ + + +These correlation functions are called by 'abs_exp' (exponential), 'squar_exp' (Gaussian), 'matern52','matern32' and 'squar_sin_exp' in SMT. The deterministic term :math:`\sum\limits_{i=1}^k\beta_i f_i({\bf x})` can be replaced by a constant, a linear model, or a quadratic model. These three types are available in SMT. diff --git a/doc/_src_docs/surrogate_models/ls.rst b/doc/_src_docs/surrogate_models/ls.rst index 282d3ef30..fd4a43852 100644 --- a/doc/_src_docs/surrogate_models/ls.rst +++ b/doc/_src_docs/surrogate_models/ls.rst @@ -57,7 +57,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.0009801 + Training - done. Time (sec): 0.0009828 ___________________________________________________________________________ Evaluation @@ -65,7 +65,7 @@ Usage # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0001380 + Predicting - done. Time (sec): 0.0001390 Prediction time/pt. (sec) : 0.0000014 diff --git a/doc/_src_docs/surrogate_models/mgp.rst b/doc/_src_docs/surrogate_models/mgp.rst index 6784c28a7..a1d6c170b 100644 --- a/doc/_src_docs/surrogate_models/mgp.rst +++ b/doc/_src_docs/surrogate_models/mgp.rst @@ -128,7 +128,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.8920083 + Training - done. Time (sec): 0.9160321 .. figure:: mgp_Test_test_mgp.png :scale: 80 % diff --git a/doc/_src_docs/surrogate_models/qp.rst b/doc/_src_docs/surrogate_models/qp.rst index 66fb9c127..72fa8a187 100644 --- a/doc/_src_docs/surrogate_models/qp.rst +++ b/doc/_src_docs/surrogate_models/qp.rst @@ -69,7 +69,7 @@ Usage Training Training ... - Training - done. Time (sec): 0.0004170 + Training - done. Time (sec): 0.0004237 ___________________________________________________________________________ Evaluation diff --git a/doc/_src_docs/surrogate_models/rbf.rst b/doc/_src_docs/surrogate_models/rbf.rst index 0b7dee8af..420046ba7 100644 --- a/doc/_src_docs/surrogate_models/rbf.rst +++ b/doc/_src_docs/surrogate_models/rbf.rst @@ -100,13 +100,13 @@ Usage Training ... Initializing linear solver ... Performing LU fact. (5 x 5 mtx) ... - Performing LU fact. (5 x 5 mtx) - done. Time (sec): 0.0000570 - Initializing linear solver - done. Time (sec): 0.0000799 + Performing LU fact. (5 x 5 mtx) - done. Time (sec): 0.0000374 + Initializing linear solver - done. Time (sec): 0.0000668 Solving linear system (col. 0) ... Back solving (5 x 5 mtx) ... - Back solving (5 x 5 mtx) - done. Time (sec): 0.0000467 - Solving linear system (col. 0) - done. Time (sec): 0.0000653 - Training - done. Time (sec): 0.0004044 + Back solving (5 x 5 mtx) - done. Time (sec): 0.0000293 + Solving linear system (col. 0) - done. Time (sec): 0.0000458 + Training - done. Time (sec): 0.0003612 ___________________________________________________________________________ Evaluation @@ -114,7 +114,7 @@ Usage # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0000284 + Predicting - done. Time (sec): 0.0000274 Prediction time/pt. (sec) : 0.0000003 diff --git a/doc/_src_docs/surrogate_models/rmts.rst b/doc/_src_docs/surrogate_models/rmts.rst index fe21517d9..e5cf5ae28 100644 --- a/doc/_src_docs/surrogate_models/rmts.rst +++ b/doc/_src_docs/surrogate_models/rmts.rst @@ -143,28 +143,28 @@ Usage (RMTB) Training ... Pre-computing matrices ... Computing dof2coeff ... - Computing dof2coeff - done. Time (sec): 0.0000031 + Computing dof2coeff - done. Time (sec): 0.0000029 Initializing Hessian ... - Initializing Hessian - done. Time (sec): 0.0005746 + Initializing Hessian - done. Time (sec): 0.0005782 Computing energy terms ... - Computing energy terms - done. Time (sec): 0.0014744 + Computing energy terms - done. Time (sec): 0.0014732 Computing approximation terms ... - Computing approximation terms - done. Time (sec): 0.0005143 - Pre-computing matrices - done. Time (sec): 0.0026219 + Computing approximation terms - done. Time (sec): 0.0005653 + Pre-computing matrices - done. Time (sec): 0.0026734 Solving for degrees of freedom ... Solving initial startup problem (n=20) ... Solving for output 0 ... Iteration (num., iy, grad. norm, func.) : 0 0 1.549745600e+00 2.530000000e+00 Iteration (num., iy, grad. norm, func.) : 0 0 1.339039325e-15 4.464522395e-16 - Solving for output 0 - done. Time (sec): 0.0040400 - Solving initial startup problem (n=20) - done. Time (sec): 0.0040886 + Solving for output 0 - done. Time (sec): 0.0040596 + Solving initial startup problem (n=20) - done. Time (sec): 0.0041115 Solving nonlinear problem (n=20) ... Solving for output 0 ... Iteration (num., iy, grad. norm, func.) : 0 0 1.533514592e-15 4.464522395e-16 - Solving for output 0 - done. Time (sec): 0.0002468 - Solving nonlinear problem (n=20) - done. Time (sec): 0.0002828 - Solving for degrees of freedom - done. Time (sec): 0.0044224 - Training - done. Time (sec): 0.0074224 + Solving for output 0 - done. Time (sec): 0.0002506 + Solving nonlinear problem (n=20) - done. Time (sec): 0.0002873 + Solving for degrees of freedom - done. Time (sec): 0.0044496 + Training - done. Time (sec): 0.0074899 ___________________________________________________________________________ Evaluation @@ -172,7 +172,7 @@ Usage (RMTB) # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0003743 + Predicting - done. Time (sec): 0.0003741 Prediction time/pt. (sec) : 0.0000037 @@ -234,28 +234,28 @@ Usage (RMTC) Training ... Pre-computing matrices ... Computing dof2coeff ... - Computing dof2coeff - done. Time (sec): 0.0008018 + Computing dof2coeff - done. Time (sec): 0.0007901 Initializing Hessian ... - Initializing Hessian - done. Time (sec): 0.0003910 + Initializing Hessian - done. Time (sec): 0.0003710 Computing energy terms ... - Computing energy terms - done. Time (sec): 0.0014522 + Computing energy terms - done. Time (sec): 0.0014341 Computing approximation terms ... - Computing approximation terms - done. Time (sec): 0.0006340 - Pre-computing matrices - done. Time (sec): 0.0033381 + Computing approximation terms - done. Time (sec): 0.0006251 + Pre-computing matrices - done. Time (sec): 0.0032806 Solving for degrees of freedom ... Solving initial startup problem (n=42) ... Solving for output 0 ... Iteration (num., iy, grad. norm, func.) : 0 0 2.249444376e+00 2.530000000e+00 Iteration (num., iy, grad. norm, func.) : 0 0 2.031017841e-15 4.346868680e-16 - Solving for output 0 - done. Time (sec): 0.0047476 - Solving initial startup problem (n=42) - done. Time (sec): 0.0047956 + Solving for output 0 - done. Time (sec): 0.0046501 + Solving initial startup problem (n=42) - done. Time (sec): 0.0046995 Solving nonlinear problem (n=42) ... Solving for output 0 ... Iteration (num., iy, grad. norm, func.) : 0 0 2.956393318e-15 4.346868680e-16 - Solving for output 0 - done. Time (sec): 0.0002475 - Solving nonlinear problem (n=42) - done. Time (sec): 0.0002840 - Solving for degrees of freedom - done. Time (sec): 0.0051248 - Training - done. Time (sec): 0.0088027 + Solving for output 0 - done. Time (sec): 0.0002449 + Solving nonlinear problem (n=42) - done. Time (sec): 0.0002809 + Solving for degrees of freedom - done. Time (sec): 0.0050263 + Training - done. Time (sec): 0.0086422 ___________________________________________________________________________ Evaluation @@ -263,9 +263,9 @@ Usage (RMTC) # eval points. : 100 Predicting ... - Predicting - done. Time (sec): 0.0003734 + Predicting - done. Time (sec): 0.0003538 - Prediction time/pt. (sec) : 0.0000037 + Prediction time/pt. (sec) : 0.0000035 .. figure:: rmts_Test_test_rmtc.png diff --git a/doc/_src_docs/surrogate_models/sgp.rst b/doc/_src_docs/surrogate_models/sgp.rst index 30c3cebf6..57d43d975 100644 --- a/doc/_src_docs/surrogate_models/sgp.rst +++ b/doc/_src_docs/surrogate_models/sgp.rst @@ -133,7 +133,7 @@ Using FITC method Training Training ... - Training - done. Time (sec): 0.3478031 + Training - done. Time (sec): 0.3440826 ___________________________________________________________________________ Evaluation @@ -141,9 +141,9 @@ Using FITC method # eval points. : 201 Predicting ... - Predicting - done. Time (sec): 0.0004528 + Predicting - done. Time (sec): 0.0004470 - Prediction time/pt. (sec) : 0.0000023 + Prediction time/pt. (sec) : 0.0000022 .. figure:: sgp_Test_test_sgp_fitc.png @@ -223,7 +223,7 @@ Using VFE method Training Training ... - Training - done. Time (sec): 0.3391337 + Training - done. Time (sec): 0.3388634 ___________________________________________________________________________ Evaluation diff --git a/smt/applications/tests/test_mixed_integer.py b/smt/applications/tests/test_mixed_integer.py index 022de35d4..557a96ceb 100644 --- a/smt/applications/tests/test_mixed_integer.py +++ b/smt/applications/tests/test_mixed_integer.py @@ -43,6 +43,153 @@ class TestMixedInteger(unittest.TestCase): + def test_periodic_mixed(self): + # Objective function + def f_obj(X): + """ + s01 objective + + Parameters + ---------- + point: array_like + point to evaluate + """ + design_space = DesignSpace( + [ + FloatVariable(0.0, 1.0), + CategoricalVariable( + values=[ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + ] + ), + ] + ) + + PI = 3.14159265358979323846 + fail = False + x = X[0] + # caté 1 + c = str(design_space.decode_values(X, i_dv=1)[1]) + x = np.abs(x) + c1 = c == "1" + c2 = c == "2" + c3 = c == "3" + c4 = c == "4" + c5 = c == "5" + c6 = c == "6" + c7 = c == "7" + c8 = c == "8" + c9 = c == "9" + c10 = c == "10" + c11 = c == "11" + c12 = c == "12" + c13 = c == "13" + + if np.size(c1) == ( + np.sum(c1) + + np.sum(c2) + + np.sum(c3) + + np.sum(c4) + + np.sum(c5) + + np.sum(c6) + + np.sum(c7) + + np.sum(c8) + + np.sum(c9) + + np.sum(c10) + + np.sum(c11) + + np.sum(c12) + + np.sum(c13) + ): + u = ( + 1 * c1 + + 2 * c2 + + 3 * c3 + + 4 * c4 + + 5 * c5 + + 6 * c6 + + 7 * c7 + + 8 * c8 + + 9 * c9 + + 10 * c10 + + 11 * c11 + + 12 * c12 + + 13 * c13 + ) + hu = (PI * (0.4 + u / 15)) * (c10 + c11 + c12 + c13) - u / 20 + y = np.cos(3.5 * PI * x + hu) + else: + print("type error") + print(X) + fail = True + return (y, fail) + + n_doe = 98 + + design_space = DesignSpace( + [ + FloatVariable(0.0, 1.0), + CategoricalVariable( + values=[ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + ] + ), + ] + ) + + sampling = MixedIntegerSamplingMethod( + LHS, + design_space, + criterion="ese", + random_state=42, + output_in_folded_space=True, + ) + xdoe = sampling(n_doe) + + y_doe = [f_obj(xdoe[i])[0] for i in range(len(xdoe))] + # Surrogate + for m in MixIntKernelType: + sm = MixedIntegerKrigingModel( + surrogate=KRG( + design_space=design_space, + categorical_kernel=m, + hyper_opt="Cobyla", + theta0=[0.01], + corr="squar_sin_exp", + n_start=5, + ), + ) + + sm.set_training_values(xdoe, np.array(y_doe)) + if m in [MixIntKernelType.EXP_HOMO_HSPHERE, MixIntKernelType.CONT_RELAX]: + with self.assertRaises(ValueError): + sm.train() + else: + sm.train() + def test_krg_mixed_3D(self): design_space = DesignSpace( [ diff --git a/smt/surrogate_models/krg_based.py b/smt/surrogate_models/krg_based.py index ec9b7b164..3767bd93e 100644 --- a/smt/surrogate_models/krg_based.py +++ b/smt/surrogate_models/krg_based.py @@ -18,6 +18,7 @@ quadratic, pow_exp, squar_exp, + squar_sin_exp, abs_exp, act_exp, cross_distances, @@ -61,6 +62,7 @@ class KrgBased(SurrogateModel): "pow_exp": pow_exp, "abs_exp": abs_exp, "squar_exp": squar_exp, + "squar_sin_exp": squar_sin_exp, "act_exp": act_exp, "matern52": matern52, "matern32": matern32, @@ -217,7 +219,12 @@ def _final_initialize(self): # initialize default power values if self.options["corr"] == "squar_exp": self.options["pow_exp_power"] = 2.0 - elif self.options["corr"] in ["abs_exp", "matern32", "matern52"]: + elif self.options["corr"] in [ + "abs_exp", + "squar_sin_exp", + "matern32", + "matern52", + ]: self.options["pow_exp_power"] = 1.0 # Check the pow_exp_power is >0 and <=2 @@ -631,6 +638,7 @@ def _matrix_data_corr( "pow_exp": pow_exp, "abs_exp": abs_exp, "squar_exp": squar_exp, + "squar_sin_exp": squar_sin_exp, "act_exp": act_exp, "matern52": matern52, "matern32": matern32, @@ -706,6 +714,18 @@ def _matrix_data_corr( return r else: d_cont = d[:, np.logical_not(cat_features)] + if self.options["corr"] == "squar_sin_exp": + if self.options["categorical_kernel"] != MixIntKernelType.GOWER: + theta_cont_features[-len([self.design_space.is_cat_mask == True]) :] = ( + np.atleast_2d( + np.array([True] * len([self.design_space.is_cat_mask == True])) + ).T + ) + theta_cat_features[1][ + -len([self.design_space.is_cat_mask == True]) : + ] = np.atleast_2d( + np.array([False] * len([self.design_space.is_cat_mask == True])) + ).T theta_cont = theta[theta_cont_features[:, 0]] r_cont = _correlation_types[corr](theta_cont, d_cont) @@ -2096,7 +2116,33 @@ def _check_param(self): mat_dim, ) - self.options["theta0"] *= np.ones(n_param) + if self.options["corr"] == "squar_sin_exp": + if ( + self.is_continuous + or self.options["categorical_kernel"] == MixIntKernelType.GOWER + ): + self.options["theta0"] *= np.ones(2 * n_param) + else: + n_param += len([self.design_space.is_cat_mask == True]) + self.options["theta0"] *= np.ones(n_param) + + else: + self.options["theta0"] *= np.ones(n_param) + if ( + not (self.options["corr"] in ["squar_exp", "abs_exp", "pow_exp"]) + and not (self.is_continuous) + and not ( + self.options["categorical_kernel"] + in [ + MixIntKernelType.GOWER, + MixIntKernelType.COMPOUND_SYMMETRY, + MixIntKernelType.HOMO_HSPHERE, + ] + ) + ): + raise ValueError( + "Categorical kernels should be matrix or exponential based." + ) if len(self.options["theta0"]) != d and ( self.options["categorical_kernel"] @@ -2106,10 +2152,11 @@ def _check_param(self): if len(self.options["theta0"]) == 1: self.options["theta0"] *= np.ones(d) else: - raise ValueError( - "the length of theta0 (%s) should be equal to the number of dim (%s)." - % (len(self.options["theta0"]), d) - ) + if self.options["corr"] != "squar_sin_exp": + raise ValueError( + "the length of theta0 (%s) should be equal to the number of dim (%s)." + % (len(self.options["theta0"]), d) + ) if self.options["eval_noise"] or np.max(self.options["noise0"]) > 1e-12: self.options["hyper_opt"] = "Cobyla" warnings.warn( diff --git a/smt/surrogate_models/tests/test_krg_predictions.py b/smt/surrogate_models/tests/test_krg_predictions.py index f007709f8..10d80a80f 100644 --- a/smt/surrogate_models/tests/test_krg_predictions.py +++ b/smt/surrogate_models/tests/test_krg_predictions.py @@ -9,6 +9,7 @@ from smt.surrogate_models import KRG from smt.sampling_methods import LHS from smt.utils.sm_test_case import SMTestCase +import warnings class Test(SMTestCase): @@ -29,7 +30,14 @@ def pb(x): def test_predictions(self): trends = ["constant", "linear"] - kernels = ["pow_exp", "squar_exp", "abs_exp", "matern32", "matern52"] + kernels = [ + "pow_exp", + "squar_exp", + "abs_exp", + "matern32", + "matern52", + "squar_sin_exp", + ] powers = [1.0, 1.5, 2.0] for trend in trends: @@ -63,7 +71,12 @@ def test_predictions(self): # quality of the surrogate on validation points Test._check_prediction_variances(self, sm) - Test._check_prediction_derivatives(self, sm) + if kernel == "squar_sin_exp": + warnings.warn( + "Spatial derivatives for squar_sin_exp yet to implement!" + ) + else: + Test._check_prediction_derivatives(self, sm) @staticmethod def _check_prediction_variances(self, sm): diff --git a/smt/surrogate_models/tests/test_krg_training.py b/smt/surrogate_models/tests/test_krg_training.py index 96035080b..0b89d01c0 100644 --- a/smt/surrogate_models/tests/test_krg_training.py +++ b/smt/surrogate_models/tests/test_krg_training.py @@ -45,6 +45,7 @@ def setUp(self): "act_exp", "matern32", "matern52", + "squar_sin_exp", ] corr_def = [pow_exp, abs_exp, squar_exp, act_exp, matern32, matern52] power_val = { @@ -54,6 +55,7 @@ def setUp(self): "act_exp": 1.0, "matern32": 1.0, "matern52": 1.0, + "squar_sin_exp": 1.0, } self.eps = eps @@ -173,6 +175,7 @@ def test_corr_hessian(self): def test_likelihood_derivatives(self): for corr_str in [ + "squar_sin_exp", "pow_exp", "abs_exp", "squar_exp", @@ -181,7 +184,10 @@ def test_likelihood_derivatives(self): "matern52", ]: # For every kernel for poly_str in ["constant", "linear", "quadratic"]: # For every method - if corr_str == "act_exp": + if corr_str == "squar_sin_exp": + kr = KRG(print_global=False) + theta = self.random.rand(4) + elif corr_str == "act_exp": kr = MGP(print_global=False) theta = self.random.rand(4) else: @@ -209,7 +215,6 @@ def test_likelihood_derivatives(self): grad_norm_all.append(grad_red[i]) diff_norm_all.append(float(dred_dk)) ind_theta.append(r"$x_%d$" % i) - grad_norm_all = np.atleast_2d(grad_norm_all) diff_norm_all = np.atleast_2d(diff_norm_all).T self.assert_error( @@ -224,9 +229,13 @@ def test_likelihood_hessian(self): "act_exp", "matern32", "matern52", + # "squar_sin_exp", # Yet to implement ]: # For every kernel for poly_str in ["constant", "linear", "quadratic"]: # For every method - if corr_str == "act_exp": + if corr_str == "squar_sin_exp": + kr = KRG(print_global=False) + theta = self.random.rand(4) + elif corr_str == "act_exp": kr = MGP(print_global=False) theta = self.random.rand(4) else: @@ -271,6 +280,7 @@ def test_likelihood_hessian(self): def test_variance_derivatives(self): for corr_str in [ + # "squar_sin_exp", ### Yet to implement "abs_exp", "squar_exp", "matern32", diff --git a/smt/utils/kriging.py b/smt/utils/kriging.py index b1d65ccd6..8cef8e75d 100644 --- a/smt/utils/kriging.py +++ b/smt/utils/kriging.py @@ -663,6 +663,103 @@ def pow_exp(theta, d, grad_ind=None, hess_ind=None, derivative_params=None): return r +def squar_sin_exp(theta, d, grad_ind=None, hess_ind=None, derivative_params=None): + """ + Generative exponential autocorrelation model. + + Parameters + ---------- + + theta : list[small_d * n_comp] + Hyperparameters of the correlation model + d: np.ndarray[n_obs * (n_obs - 1) / 2, n_comp] + d_i otherwise + grad_ind : int, optional + Indice for which component the gradient dr/dtheta must be computed. The default is None. + hess_ind : int, optional + Indice for which component the hessian d²r/d²(theta) must be computed. The default is None. + derivative_paramas : dict, optional + List of arguments mandatory to compute the gradient dr/dx. The default is None. + + Raises + ------ + Exception + Assure that theta is of the good length + + Returns + ------- + r: np.ndarray[n_obs * (n_obs - 1) / 2,1] + An array containing the values of the autocorrelation model. + """ + + r = np.zeros((d.shape[0], 1)) + n_components = d.shape[1] + + # Construct/split the correlation matrix + i, nb_limit = 0, int(1e4) + while i * nb_limit <= d.shape[0]: + theta_array = theta.reshape(1, len(theta)) + r[i * nb_limit : (i + 1) * nb_limit, 0] = np.exp( + -np.sum( + np.atleast_2d(theta_array[0][0 : int(len(theta) / 2)]) + * np.sin( + np.atleast_2d(theta_array[0][int(len(theta) / 2) : int(len(theta))]) + * d[i * nb_limit : (i + 1) * nb_limit, :] + ) + ** 2, + axis=1, + ) + ) + i += 1 + + i = 0 + if grad_ind is not None: + cut = int(len(theta) / 2) + if grad_ind < cut: + grad_ind2 = cut + grad_ind + while i * nb_limit <= d.shape[0]: + r[i * nb_limit : (i + 1) * nb_limit, 0] = ( + -np.sin( + theta_array[0][grad_ind2] + * d[i * nb_limit : (i + 1) * nb_limit, grad_ind] + ) + ** 2 + * r[i * nb_limit : (i + 1) * nb_limit, 0] + ) + i += 1 + else: + grad_ind2 = grad_ind - cut + while i * nb_limit <= d.shape[0]: + r[i * nb_limit : (i + 1) * nb_limit, 0] = ( + -theta_array[0][grad_ind2] + * d[i * nb_limit : (i + 1) * nb_limit, grad_ind2] + * np.sin( + 2 + * d[i * nb_limit : (i + 1) * nb_limit, grad_ind2] + * theta_array[0][grad_ind] + ) + * r[i * nb_limit : (i + 1) * nb_limit, 0] + ) + i += 1 + + i = 0 + if hess_ind is not None: + cut = int(len(theta) / 2) + # if hess_ind == grad_ind : + # else : + raise ValueError( + "Second derivatives for ExpSinSquared not available yet (to implement)." + ) + + if derivative_params is not None: + dx = derivative_params["dx"] + dd = derivative_params["dd"] + raise ValueError( + "Spatial derivatives for ExpSinSquared not available yet (to implement)." + ) + return r + + def matern52(theta, d, grad_ind=None, hess_ind=None, derivative_params=None): """ Matern 5/2 correlation model. @@ -1213,6 +1310,10 @@ def componentwise_distance( ) if corr == "act_exp": raise ValueError("this option is not implemented for active learning") + if corr == "squar_sin_exp": + raise ValueError( + "Spatial derivatives for ExpSinSquared not available yet (to implement)." + ) der = _comp_dist_derivative(D, power) D_corr = power * np.einsum("j,ij->ij", theta.T, der) return D_corr