@@ -13633,6 +13633,129 @@
1363313633 " print(\" similar low scores, which are clearly better (lower) than the scores for the 'Poor' random designs.\" )\n "
1363413634 ]
1363513635 },
13636+ {
13637+ "cell_type" : " code" ,
13638+ "execution_count" : 1 ,
13639+ "metadata" : {},
13640+ "outputs" : [
13641+ {
13642+ "name" : " stderr" ,
13643+ "output_type" : " stream" ,
13644+ "text" : [
13645+ " Seed set to 123\n " ,
13646+ " Seed set to 123\n "
13647+ ]
13648+ },
13649+ {
13650+ "name" : " stdout" ,
13651+ "output_type" : " stream" ,
13652+ "text" : [
13653+ " spotpython tuning: 0.03443507570516119 [######----] 55.00% \n " ,
13654+ " spotpython tuning: 0.03134345291315803 [######----] 60.00% \n " ,
13655+ " spotpython tuning: 0.0009629463005635346 [######----] 65.00% \n " ,
13656+ " spotpython tuning: 8.540004506728118e-05 [#######---] 70.00% \n " ,
13657+ " spotpython tuning: 6.56169732863907e-05 [########--] 75.00% \n " ,
13658+ " spotpython tuning: 6.56169732863907e-05 [########--] 80.00% \n " ,
13659+ " spotpython tuning: 6.56169732863907e-05 [########--] 85.00% \n " ,
13660+ " spotpython tuning: 6.56169732863907e-05 [#########-] 90.00% \n " ,
13661+ " spotpython tuning: 6.56169732863907e-05 [##########] 95.00% \n " ,
13662+ " spotpython tuning: 6.56169732863907e-05 [##########] 100.00% Done...\n " ,
13663+ " \n " ,
13664+ " Experiment saved to 000_res.pkl\n " ,
13665+ " \n " ,
13666+ " Variable importance values:\n " ,
13667+ " x1: 84.79%\n " ,
13668+ " x2: 100.00%\n " ,
13669+ " x3: 80.70%\n " ,
13670+ " spotpython tuning: 0.0333153284501078 [######----] 55.00% \n " ,
13671+ " spotpython tuning: 0.0060412283350538025 [######----] 60.00% \n " ,
13672+ " spotpython tuning: 0.001518235041814197 [######----] 65.00% \n " ,
13673+ " spotpython tuning: 3.7290664067486496e-05 [#######---] 70.00% \n " ,
13674+ " spotpython tuning: 3.7290664067486496e-05 [########--] 75.00% \n " ,
13675+ " spotpython tuning: 3.7290664067486496e-05 [########--] 80.00% \n " ,
13676+ " spotpython tuning: 3.7290664067486496e-05 [########--] 85.00% \n " ,
13677+ " spotpython tuning: 3.7290664067486496e-05 [#########-] 90.00% \n " ,
13678+ " spotpython tuning: 3.7290664067486496e-05 [##########] 95.00% \n " ,
13679+ " spotpython tuning: 3.7290664067486496e-05 [##########] 100.00% Done...\n " ,
13680+ " \n " ,
13681+ " Experiment saved to 000_res.pkl\n " ,
13682+ " Importance requires more than one theta values (n_theta>1).\n " ,
13683+ " \n " ,
13684+ " Importance values with single theta:\n " ,
13685+ " [0, 0, 0]\n "
13686+ ]
13687+ }
13688+ ],
13689+ "source" : [
13690+ " import numpy as np\n " ,
13691+ " from spotpython.fun.objectivefunctions import Analytical\n " ,
13692+ " from spotpython.spot import spot\n " ,
13693+ " from spotpython.utils.init import (\n " ,
13694+ " fun_control_init, \n " ,
13695+ " surrogate_control_init, \n " ,
13696+ " design_control_init\n " ,
13697+ " )\n " ,
13698+ " \n " ,
13699+ " # Create test function (3D sphere function)\n " ,
13700+ " fun = Analytical().fun_sphere\n " ,
13701+ " \n " ,
13702+ " # Setup control parameters\n " ,
13703+ " fun_control = fun_control_init(\n " ,
13704+ " lower=np.array([-1, -1, -1]),\n " ,
13705+ " upper=np.array([1, 1, 1]),\n " ,
13706+ " fun_evals=20,\n " ,
13707+ " var_name=[\" x1\" , \" x2\" , \" x3\" ], # Give names to variables\n " ,
13708+ " )\n " ,
13709+ " \n " ,
13710+ " # Setup design with initial size\n " ,
13711+ " design_control = design_control_init(init_size=10)\n " ,
13712+ " \n " ,
13713+ " # Setup surrogate model with multiple theta values\n " ,
13714+ " surrogate_control = surrogate_control_init(\n " ,
13715+ " n_theta=\" anisotropic\" , # Use different theta for each dimension\n " ,
13716+ " method=\" interpolation\"\n " ,
13717+ " )\n " ,
13718+ " \n " ,
13719+ " # Initialize and run spot\n " ,
13720+ " S = spot.Spot(\n " ,
13721+ " fun=fun,\n " ,
13722+ " fun_control=fun_control,\n " ,
13723+ " design_control=design_control,\n " ,
13724+ " surrogate_control=surrogate_control\n " ,
13725+ " )\n " ,
13726+ " S.run()\n " ,
13727+ " \n " ,
13728+ " # Get importance values\n " ,
13729+ " importance = S.get_importance()\n " ,
13730+ " print(\"\\ nVariable importance values:\" )\n " ,
13731+ " for var, imp in zip(S.all_var_name, importance):\n " ,
13732+ " print(f\" {var}: {imp:.2f}%\" )\n " ,
13733+ " \n " ,
13734+ " # Example output:\n " ,
13735+ " # Variable importance values:\n " ,
13736+ " # x1: 100.00%\n " ,
13737+ " # x2: 85.32%\n " ,
13738+ " # x3: 76.15%\n " ,
13739+ " \n " ,
13740+ " # Try with single theta (should return zeros)\n " ,
13741+ " surrogate_control = surrogate_control_init(\n " ,
13742+ " n_theta=1, # Single theta for all dimensions\n " ,
13743+ " method=\" interpolation\"\n " ,
13744+ " )\n " ,
13745+ " \n " ,
13746+ " S2 = spot.Spot(\n " ,
13747+ " fun=fun,\n " ,
13748+ " fun_control=fun_control,\n " ,
13749+ " design_control=design_control,\n " ,
13750+ " surrogate_control=surrogate_control\n " ,
13751+ " )\n " ,
13752+ " S2.run()\n " ,
13753+ " \n " ,
13754+ " importance2 = S2.get_importance()\n " ,
13755+ " print(\"\\ nImportance values with single theta:\" )\n " ,
13756+ " print(importance2) # Will print [0, 0, 0]"
13757+ ]
13758+ },
1363613759 {
1363713760 "cell_type" : " code" ,
1363813761 "execution_count" : null ,
0 commit comments