Skip to content

Commit 293f1f2

Browse files
committed
Added rmse computations and skip mesh options to the pipeline
1 parent eb6c34f commit 293f1f2

File tree

10 files changed

+126
-16
lines changed

10 files changed

+126
-16
lines changed

CMakeLists.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,22 @@ if(NOT USE_MULTIPRECISION)
152152
include(Catch2)
153153

154154
# Build testing libraries
155-
add_library(CurvatureMetricTestsLib
156-
src/tests/test_area.cpp
157-
src/tests/test_energies.cpp
158-
src/tests/test_optimize.cpp
159-
)
160-
target_link_libraries(CurvatureMetricTestsLib PUBLIC
161-
MetricOptimizationLib
162-
Catch2::Catch2WithMain
163-
)
164-
set(TEST_DATA_ROOT "${PROJECT_SOURCE_DIR}/src/tests/regression/")
165-
target_compile_definitions(CurvatureMetricTestsLib PUBLIC TEST_DATA_DIR=\"${TEST_DATA_ROOT}\")
155+
#add_library(CurvatureMetricTestsLib
156+
#)
157+
#target_link_libraries(CurvatureMetricTestsLib PUBLIC
158+
# MetricOptimizationLib
159+
# Catch2::Catch2WithMain
160+
#)
166161

167162
# Build testing executable
168163
add_executable(CurvatureMetricTests
169164
src/tests/tests.cpp
170165
)
171166
target_link_libraries(CurvatureMetricTests PRIVATE
172-
CurvatureMetricTestsLib
167+
MetricOptimizationLib
173168
Catch2::Catch2WithMain
174169
)
170+
set(TEST_DATA_ROOT "${PROJECT_SOURCE_DIR}/src/tests/regression/")
171+
target_compile_definitions(CurvatureMetricTests PUBLIC TEST_DATA_DIR=\"${TEST_DATA_ROOT}\")
175172
endif()
176173
endif()

cmake/suitesparse.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
if(TARGET SuiteSparse::SuiteSparseConfig)
2+
return()
3+
endif()
4+
15
include(FetchContent)
26
FetchContent_Declare(
37
suitesparse
48
SYSTEM
59
GIT_REPOSITORY https://github.com/DrTimothyAldenDavis/SuiteSparse.git
610
GIT_TAG stable
711
)
8-
FetchContent_MakeAvailable(suitesparse)
12+
FetchContent_MakeAvailable(suitesparse)
93 Bytes
Binary file not shown.

scripts/script_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def add_mesh_arguments(parser):
2323
# Input and output directories
2424
parser.add_argument("-f", "--fname", help="filenames of the obj file",
2525
nargs='+')
26+
parser.add_argument("--skip_fname", help="filenames of the obj files to skip",
27+
nargs='+')
2628
parser.add_argument("-i", "--input_dir", help="input folder that stores obj files and Th_hat")
2729
parser.add_argument("--lambdas_dir", help="directory for initial lambdas")
2830
parser.add_argument("--free_bd_angles", help="let boundary angles be free",
@@ -348,7 +350,7 @@ def count_running_processes(p_list):
348350
return count
349351

350352
def run_many(method, args):
351-
args_list = [(args, fname) for fname in args['fname']]
353+
args_list = [(args, fname) for fname in args['fname'] if fname not in args['skip_fname']]
352354
with multiprocessing.Pool(processes=args['num_processes']) as pool:
353355
pool.starmap(method, args_list, chunksize=1)
354356

src/optimization/energies.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,60 @@ namespace CurvatureMetric
563563
return energy;
564564
}
565565

566+
Scalar
567+
root_mean_square_error(const VectorX &x, const VectorX &x0)
568+
{
569+
assert(x.size() == x0.size());
570+
int num_var = x.size();
571+
if (num_var == 0) return 0.0;
572+
573+
Scalar error = 0.0;
574+
for (int i = 0; i < num_var; ++i)
575+
{
576+
Scalar diff = x[i] - x0[i];
577+
error += diff * diff;
578+
}
579+
580+
return std::sqrt(error / num_var);
581+
}
582+
583+
Scalar
584+
relative_root_mean_square_error(const VectorX &x, const VectorX &x0)
585+
{
586+
assert(x.size() == x0.size());
587+
int num_var = x.size();
588+
if (num_var == 0) return 0.0;
589+
590+
Scalar error = 0.0;
591+
Scalar denom = 0.0;
592+
for (int i = 0; i < num_var; ++i)
593+
{
594+
Scalar diff = x[i] - x0[i];
595+
error += (diff * diff);
596+
denom += (x0[i] * x0[i]);
597+
}
598+
599+
return std::sqrt(error / (num_var * denom));
600+
}
601+
602+
Scalar
603+
root_mean_square_relative_error(const VectorX &x, const VectorX &x0)
604+
{
605+
assert(x.size() == x0.size());
606+
int num_var = x.size();
607+
if (num_var == 0) return 0.0;
608+
609+
Scalar error = 0.0;
610+
for (int i = 0; i < num_var; ++i)
611+
{
612+
Scalar rel_err = (!float_equal(x0[i], 0.0)) ? (x[i] - x0[i]) / x0[i] : 1e10;
613+
error += (rel_err * rel_err);
614+
}
615+
616+
return std::sqrt(error / num_var);
617+
618+
}
619+
566620
// FIXME Rename these variables
567621
// FIXME Ensure all pybind functions for the entire interface are in place
568622
#ifdef PYBIND

src/optimization/energies.hh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ symmetric_dirichlet_energy(
225225
VectorX& f2energy
226226
);
227227

228+
Scalar
229+
root_mean_square_error(const VectorX &x, const VectorX &x0);
230+
231+
Scalar
232+
relative_root_mean_square_error(const VectorX &x, const VectorX &x0);
233+
234+
Scalar
235+
root_mean_square_relative_error(const VectorX &x, const VectorX &x0);
236+
228237
#ifdef PYBIND
229238

230239
VectorX

src/optimization/implicit_optimization.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void initialize_data_log(const std::filesystem::path& data_log_path)
4444
output_file << "step_size,";
4545
output_file << "energy,";
4646
output_file << "max_error,";
47+
output_file << "rmse,";
48+
output_file << "rrmse,";
49+
output_file << "rmsre,";
4750
output_file << "convergence_ratio,";
4851
output_file << "max_change_in_metric_coords,";
4952
output_file << "actual_to_unconstrained_direction_ratio,";
@@ -65,6 +68,19 @@ void update_data_log(
6568
const VectorX& descent_direction,
6669
Scalar convergence_ratio)
6770
{
71+
// Get initial metric coordinates
72+
VectorX metric_init = initial_cone_metric.get_reduced_metric_coordinates();
73+
74+
// Get edge lengths
75+
int num_reduced_edges = metric_init.size();
76+
VectorX l_init(num_reduced_edges);
77+
VectorX l(num_reduced_edges);
78+
for (int E = 0; E < num_reduced_edges; ++E)
79+
{
80+
l_init[E] = exp(metric_init[E] / 2.0);
81+
l[E] = exp(reduced_metric_coords[E] / 2.0);
82+
}
83+
6884
// Copy metric and make discrete
6985
std::unique_ptr<DifferentiableConeMetric> cone_metric =
7086
initial_cone_metric.set_metric_coordinates(reduced_metric_coords);
@@ -84,6 +100,9 @@ void update_data_log(
84100
// Compute numerics
85101
log.energy = opt_energy.energy(initial_cone_metric);
86102
log.error = sup_norm(constraint);
103+
log.rmse = root_mean_square_error(l, l_init);
104+
log.rrmse = relative_root_mean_square_error(l, l_init);
105+
log.rmsre = root_mean_square_relative_error(l, l_init);
87106
log.num_flips = cone_metric->num_flips();
88107
log.convergence_ratio = convergence_ratio;
89108
log.max_change_in_metric_coords = sup_norm(change_in_metric_coords);
@@ -175,6 +194,9 @@ void write_data_log_entry(const OptimizationLog& log, const std::filesystem::pat
175194
output_file << std::fixed << std::setprecision(17) << log.beta << ",";
176195
output_file << std::fixed << std::setprecision(17) << log.energy << ",";
177196
output_file << std::fixed << std::setprecision(17) << log.error << ",";
197+
output_file << std::fixed << std::setprecision(17) << log.rmse << ",";
198+
output_file << std::fixed << std::setprecision(17) << log.rrmse << ",";
199+
output_file << std::fixed << std::setprecision(17) << log.rmsre << ",";
178200
output_file << std::fixed << std::setprecision(17) << log.convergence_ratio << ",";
179201
output_file << std::fixed << std::setprecision(17) << log.max_change_in_metric_coords << ",";
180202
output_file << std::fixed << std::setprecision(17)

src/optimization/implicit_optimization.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ namespace CurvatureMetric
2020
Scalar beta; // Step size
2121
Scalar energy; // Energy
2222
Scalar error; // Max angle constraint error
23+
Scalar rmse; // Root mean squared edge lengths
24+
Scalar rrmse; // Relative root mean squared edge lengths
25+
Scalar rmsre; // Root mean squared relative edge lengths
2326
int num_flips; // Number of flips for MakeDelaunay
2427
Scalar convergence_ratio; // Convergence ratio
2528
Scalar max_change_in_metric_coords; // Maximum change per edge in the metric coordinates

src/tests/test_energies.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,23 @@ TEST_CASE( "The energies of a triangle can be computed", "[energies]" )
7373
REQUIRE( float_equal(J_f2J2.coeff(0, 1), A_sq / A0_sq) );
7474
REQUIRE( float_equal(J_f2J2.coeff(0, 2), 0.0) );
7575
}
76-
}
76+
}
77+
78+
TEST_CASE( "The errors of a triangle can be computed", "[energies]" ) {
79+
SECTION ( "Errors" )
80+
{
81+
VectorX x(3);
82+
VectorX x0(3);
83+
x << 1.0, 2.0, 0.5;
84+
x0 << 2.0, 2.0, 1.0;
85+
// err is 1.0, 0.0, 0.5
86+
// Sq err is 1.0, 0.0, 0.25
87+
// Rel err is 0.5, 0.0, 0.5
88+
// Rel sq err is 0.25, 0.0, 0.25
89+
// total Sq err is 1.25
90+
// rel factor is 9
91+
CHECK( float_equal(root_mean_square_error(x, x0), std::sqrt(1.25 / 3.0)) );
92+
CHECK( float_equal(relative_root_mean_square_error(x, x0), std::sqrt(1.25 / (3.0 * 9.0))) );
93+
CHECK( float_equal(root_mean_square_relative_error(x, x0), std::sqrt(0.5 / 3.0)) );
94+
}
95+
}

src/tests/tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#include "test_optimize.cpp"
88
#include "test_shear.cpp"
99
#include "test_refinement.cpp"
10-
#include "test_regression.cpp"
10+
#include "test_regression.cpp"

0 commit comments

Comments
 (0)