Skip to content

Commit 4a3dd26

Browse files
committed
generate images in different directory
1 parent 7cf83bc commit 4a3dd26

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

.github/workflows/generate-plots.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ jobs:
4747
uses: stefanzweifel/git-auto-commit-action@v5
4848
with:
4949
commit_message: "🤖 Auto-update function visualization plots"
50-
file_pattern: "doc/images/*.jpg"
50+
file_pattern: "doc/images/mathematical/*.jpg doc/images/ml_functions/*.jpg"
5151
commit_user_name: "github-actions[bot]"
5252
commit_user_email: "github-actions[bot]@users.noreply.github.com"

scripts/generate_all_plots.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
from surfaces.test_functions.mathematical.test_functions_nd import *
1818
from surfaces.visualize import matplotlib_heatmap, matplotlib_surface
1919

20-
# Ensure output directory exists
20+
# Ensure output directories exist
2121
script_dir = os.path.dirname(os.path.abspath(__file__))
22-
output_dir = os.path.join(script_dir, '..', 'doc', 'images')
23-
os.makedirs(output_dir, exist_ok=True)
22+
main_output_dir = os.path.join(script_dir, '..', 'doc', 'images')
23+
mathematical_output_dir = os.path.join(main_output_dir, 'mathematical')
24+
os.makedirs(main_output_dir, exist_ok=True)
25+
os.makedirs(mathematical_output_dir, exist_ok=True)
2426

2527
# Configuration for each function type
2628
FUNCTION_CONFIGS = {
@@ -163,7 +165,7 @@ def generate_plots():
163165
title=f"{func_instance.name} - Heatmap" if hasattr(func_instance, 'name') else f"{func_name} - Heatmap",
164166
norm=norm
165167
)
166-
heatmap_path = os.path.join(output_dir, f"{file_name}_heatmap.jpg")
168+
heatmap_path = os.path.join(mathematical_output_dir, f"{file_name}_heatmap.jpg")
167169
heatmap_fig.savefig(heatmap_path, dpi=150, bbox_inches='tight')
168170
heatmap_fig.close()
169171

@@ -175,7 +177,7 @@ def generate_plots():
175177
title=f"{func_instance.name} - Surface" if hasattr(func_instance, 'name') else f"{func_name} - Surface",
176178
norm=norm
177179
)
178-
surface_path = os.path.join(output_dir, f"{file_name}_surface.jpg")
180+
surface_path = os.path.join(mathematical_output_dir, f"{file_name}_surface.jpg")
179181
surface_fig.savefig(surface_path, dpi=150, bbox_inches='tight')
180182
surface_fig.close()
181183

@@ -185,7 +187,7 @@ def generate_plots():
185187
print(f" ✗ Error generating plots for {func_name}: {e}")
186188
continue
187189

188-
print(f"\n✓ Mathematical function plot generation complete! Images saved to {output_dir}")
190+
print(f"\n✓ Mathematical function plot generation complete! Images saved to {mathematical_output_dir}")
189191

190192
# Generate ML function plots
191193
print("\nGenerating ML function plots...")

scripts/generate_ml_plots.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424

2525
# Ensure output directories exist
2626
script_dir = os.path.dirname(os.path.abspath(__file__))
27-
output_dir = os.path.join(script_dir, '..', 'doc', 'images')
28-
ml_output_dir = os.path.join(output_dir, 'ml_functions')
29-
os.makedirs(output_dir, exist_ok=True)
30-
os.makedirs(ml_output_dir, exist_ok=True)
27+
main_images_dir = os.path.join(script_dir, '..', 'doc', 'images')
28+
ml_functions_dir = os.path.join(main_images_dir, 'ml_functions')
29+
ml_detailed_dir = os.path.join(ml_functions_dir, 'detailed')
30+
os.makedirs(main_images_dir, exist_ok=True)
31+
os.makedirs(ml_functions_dir, exist_ok=True)
32+
os.makedirs(ml_detailed_dir, exist_ok=True)
3133

3234
# ML Function configurations with reduced parameter spaces for faster evaluation
3335
ML_FUNCTION_CONFIGS = {
@@ -100,9 +102,9 @@ def generate_ml_plots():
100102
reduced_space = config['reduced_search_space']
101103
ml_func = create_reduced_ml_function(func_class, reduced_space)
102104

103-
# Create function-specific output directory
104-
func_output_dir = os.path.join(ml_output_dir, ml_func._name_)
105-
os.makedirs(func_output_dir, exist_ok=True)
105+
# Create function-specific detailed output directory
106+
func_detailed_dir = os.path.join(ml_detailed_dir, ml_func._name_)
107+
os.makedirs(func_detailed_dir, exist_ok=True)
106108

107109
print(f"Search space: {ml_func.search_space()}")
108110

@@ -116,13 +118,13 @@ def generate_ml_plots():
116118
title=f"{ml_func.name} - {param1} vs {param2}"
117119
)
118120

119-
# Save as image
120-
output_path = os.path.join(func_output_dir, f"{param1}_vs_{param2}_heatmap.jpg")
121-
fig.write_image(output_path, format="jpeg", width=900, height=700)
121+
# Save detailed image
122+
detailed_path = os.path.join(func_detailed_dir, f"{param1}_vs_{param2}_heatmap.jpg")
123+
fig.write_image(detailed_path, format="jpeg", width=900, height=700)
122124

123-
# Also save to main images directory for README
124-
main_output_path = os.path.join(output_dir, f"{ml_func._name_}_{param1}_vs_{param2}_heatmap.jpg")
125-
fig.write_image(main_output_path, format="jpeg", width=900, height=700)
125+
# Save main image for README
126+
main_path = os.path.join(ml_functions_dir, f"{ml_func._name_}_{param1}_vs_{param2}_heatmap.jpg")
127+
fig.write_image(main_path, format="jpeg", width=900, height=700)
126128

127129
print(f" ✓ Saved {param1} vs {param2} heatmap")
128130

@@ -136,21 +138,21 @@ def generate_ml_plots():
136138
title=f"{ml_func.name} - Dataset vs {hyperparameter}"
137139
)
138140

139-
# Save as image
140-
output_path = os.path.join(func_output_dir, f"dataset_vs_{hyperparameter}_analysis.jpg")
141-
fig.write_image(output_path, format="jpeg", width=1000, height=700)
141+
# Save detailed image
142+
detailed_path = os.path.join(func_detailed_dir, f"dataset_vs_{hyperparameter}_analysis.jpg")
143+
fig.write_image(detailed_path, format="jpeg", width=1000, height=700)
142144

143-
# Also save to main images directory for README
144-
main_output_path = os.path.join(output_dir, f"{ml_func._name_}_dataset_vs_{hyperparameter}_analysis.jpg")
145-
fig.write_image(main_output_path, format="jpeg", width=1000, height=700)
145+
# Save main image for README
146+
main_path = os.path.join(ml_functions_dir, f"{ml_func._name_}_dataset_vs_{hyperparameter}_analysis.jpg")
147+
fig.write_image(main_path, format="jpeg", width=1000, height=700)
146148

147149
print(f" ✓ Saved dataset vs {hyperparameter} analysis")
148150

149151
print(f"✓ Completed {func_name} analysis")
150152

151153
print(f"\n✓ ML plot generation complete! Images saved to:")
152-
print(f" - Individual function plots: {ml_output_dir}")
153-
print(f" - README plots: {output_dir}")
154+
print(f" - Detailed function plots: {ml_detailed_dir}")
155+
print(f" - README plots: {ml_functions_dir}")
154156

155157
def generate_sample_plots():
156158
"""Generate a few sample plots for testing."""
@@ -175,15 +177,15 @@ def reduced_search_space_method(**kwargs):
175177
ml_func, 'n_neighbors', 'algorithm',
176178
title="Sample: KNN Hyperparameter Analysis"
177179
)
178-
fig1.write_image(os.path.join(output_dir, "sample_knn_hyperparams.jpg"),
180+
fig1.write_image(os.path.join(ml_functions_dir, "sample_knn_hyperparams.jpg"),
179181
format="jpeg", width=900, height=700)
180182

181183
print("Creating sample dataset analysis plot...")
182184
fig2 = plotly_dataset_hyperparameter_analysis(
183185
ml_func, 'n_neighbors',
184186
title="Sample: Dataset vs n_neighbors"
185187
)
186-
fig2.write_image(os.path.join(output_dir, "sample_knn_datasets.jpg"),
188+
fig2.write_image(os.path.join(ml_functions_dir, "sample_knn_datasets.jpg"),
187189
format="jpeg", width=1000, height=700)
188190

189191
print("✓ Sample plots generated successfully!")

0 commit comments

Comments
 (0)