Skip to content
Snippets Groups Projects
Commit d0c0619f authored by Erik Strand's avatar Erik Strand
Browse files

Generalize plotting infrastructure

Now each optimizer has 2d and 10d plot targets. But only CGD's work so
far.
parent 78507241
No related branches found
No related tags found
No related merge requests found
......@@ -48,11 +48,13 @@ def add_points(fig, ax, points):
ax.plot(x, y, 'k.')
return fig, ax
# points is a list of numpy arrays of dim n x 2
# polygons is a list of numpy arrays, for which each row gives a vertex
def add_polygons(fig, ax, polygons):
for polygon in polygons:
p = mpl.patches.Polygon(polygon, True, fill=False, color="black", zorder=2)
# only plot first two dims
p = mpl.patches.Polygon(polygon[:,0:2], True, fill=False, color="black", zorder=2)
ax.add_patch(p)
# theoretically patch collections could be more efficient
#p = PatchCollection(patches, alpha=0.4)
#ax.add_collection(p)
return fig, ax
......
# TODO Enable arguments to be passed to the C++ executable
function(make_plot_target TARGET)
function(make_plot_target TARGET ID)
message(${ID})
cmake_parse_arguments(PLOT "" "" "ARGS" ${ARGN})
if (VISUALIZE)
add_custom_command(
OUTPUT ${TARGET}_log.json ${TARGET}_vis.json
COMMAND ${TARGET} ${TARGET}_log.json ${TARGET}_vis.json
OUTPUT ${TARGET}_log_${ID}.json ${TARGET}_vis_${ID}.json
COMMAND ${TARGET} ${TARGET}_log_${ID}.json ${TARGET}_vis_${ID}.json ${PLOT_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${TARGET}
)
add_custom_command(
OUTPUT ${TARGET}_plot.pdf
COMMAND python3 ${CMAKE_SOURCE_DIR}/apps/plots.py ${TARGET}_vis.json ${TARGET}_plot.pdf
OUTPUT ${TARGET}_plot_${ID}.pdf
COMMAND python3 ${CMAKE_SOURCE_DIR}/apps/plots.py ${TARGET}_vis_${ID}.json ${TARGET}_plot_${ID}.pdf
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_SOURCE_DIR}/apps/plots.py ${TARGET}_vis.json
DEPENDS ${CMAKE_SOURCE_DIR}/apps/plots.py ${TARGET}_vis_${ID}.json
)
add_custom_target(${TARGET}_plot
DEPENDS ${TARGET}_plot.pdf
add_custom_target(${TARGET}_plot_${ID}
DEPENDS ${TARGET}_plot_${ID}.pdf
)
endif()
endfunction()
......@@ -3,5 +3,6 @@ if (VISUALIZE)
main.cpp
)
target_link_libraries(conjugate_gradient_descent optimization_lib clara)
make_plot_target(conjugate_gradient_descent)
make_plot_target(conjugate_gradient_descent 2d ARGS -d 2)
make_plot_target(conjugate_gradient_descent 10d ARGS -d 10)
endif()
......@@ -3,5 +3,6 @@ if (VISUALIZE)
main.cpp
)
target_link_libraries(gradient_descent optimization_lib clara)
make_plot_target(gradient_descent)
make_plot_target(gradient_descent 2d ARGS -d 2)
make_plot_target(gradient_descent 10d ARGS -d 10)
endif()
......@@ -3,5 +3,6 @@ if (VISUALIZE)
main.cpp
)
target_link_libraries(nelder_mead optimization_lib clara)
make_plot_target(nelder_mead)
make_plot_target(nelder_mead 2d ARGS -d 2)
make_plot_target(nelder_mead 10d ARGS -d 10)
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment