Skip to content

Commit

Permalink
LM objfun tests slightly better diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisThielemans committed May 13, 2024
1 parent e72447a commit 81f57f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
31 changes: 18 additions & 13 deletions src/include/stir/recon_buildblock/test/ObjectiveFunctionTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ ObjectiveFunctionTests<ObjectiveFunctionT, TargetT>::test_gradient(const std::st
if (!testOK)
{
std::cerr << "Numerical gradient test failed with for " + test_name + "\n";
std::cerr << "Writing diagnostic files target.hv, gradient.hv, numerical_gradient.hv\n";
write_to_file("target.hv", target);
write_to_file("gradient.hv", *gradient_sptr);
write_to_file("numerical_gradient.hv", *gradient_2_sptr);
std::cerr << "Writing diagnostic files " << test_name << "_target.hv, *gradient.hv, *numerical_gradient.hv\n";
write_to_file(test_name + "_target.hv", target);
write_to_file(test_name + "_gradient.hv", *gradient_sptr);
write_to_file(test_name + "_numerical_gradient.hv", *gradient_2_sptr);
return Succeeded::no;
}
else
Expand Down Expand Up @@ -156,12 +156,13 @@ ObjectiveFunctionTests<ObjectiveFunctionT, TargetT>::test_Hessian(const std::str
if (!testOK)
{
std::cerr << "Numerical Hessian test failed with for " + test_name + "\n";
std::cerr << "Writing diagnostic files target.hv, gradient.hv, increment, numerical_gradient.hv, Hessian_times_increment\n";
write_to_file("target.hv", target);
write_to_file("gradient.hv", *gradient_sptr);
write_to_file("increment.hv", *increment_sptr);
write_to_file("gradient_at_increment.hv", *gradient_2_sptr);
write_to_file("Hessian_times_increment.hv", *output);
std::cerr << "Writing diagnostic files " << test_name
<< "_target.hv, *gradient.hv, *increment, *numerical_gradient.hv, *Hessian_times_increment\n";
write_to_file(test_name + "_target.hv", target);
write_to_file(test_name + "_gradient.hv", *gradient_sptr);
write_to_file(test_name + "_increment.hv", *increment_sptr);
write_to_file(test_name + "_gradient_at_increment.hv", *gradient_2_sptr);
write_to_file(test_name + "_Hessian_times_increment.hv", *output);
return Succeeded::no;
}
else
Expand Down Expand Up @@ -195,9 +196,13 @@ ObjectiveFunctionTests<ObjectiveFunctionT, TargetT>::test_Hessian_concavity(cons
else
{
// print to console the FAILED configuration
info("FAIL: " + test_name + ": Computation of x^T H x = " + std::to_string(my_sum)
+ " > 0 (Hessian) and is therefore NOT concave" + "\n >target image max=" + std::to_string(target.find_max())
+ "\n >target image min=" + std::to_string(target.find_min()));
std::cerr << "FAIL: " + test_name + ": Computation of x^T H x = " + std::to_string(my_sum)
<< " > 0 (Hessian) and is therefore NOT concave"
<< "\n >target image max=" << target.find_max() << "\n >target image min=" << target.find_min()
<< "\n >output image max=" << output->find_max() << "\n >output image min=" << output->find_min();
std::cerr << "Writing diagnostic files to " << test_name + "_concavity_out.hv etc\n.";
write_to_file(test_name + "_concavity_out.hv", *output);
write_to_file(test_name + "_target.hv", target);
return Succeeded::no;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ PoissonLogLikelihoodWithLinearModelForMeanAndProjDataTests::run_tests_for_object
objective_function_type& objective_function, target_type& target)
{
std::cerr << "----- testing Gradient\n";
test_gradient("PoissonLLProjData", objective_function, target, 0.01F);
test_gradient("PoissonLLListModeData", objective_function, target, 0.01F);

std::cerr << "----- testing concavity via Hessian-vector product (accumulate_Hessian_times_input)\n";
test_Hessian_concavity("PoissonLLProjData", objective_function, target);
test_Hessian_concavity("PoissonLLListModeData", objective_function, target);

std::cerr << "----- testing approximate-Hessian-vector product (accumulate_Hessian_times_input)\n";
test_approximate_Hessian_concavity(objective_function, target);

std::cerr << "----- testing Hessian-vector product (accumulate_Hessian_times_input)\n";
test_Hessian("PoissonLLProjData", objective_function, target, 0.5F);
test_Hessian("PoissonLLListModeData", objective_function, target, 0.5F);

if (!this->is_everything_ok())
{
Expand Down

0 comments on commit 81f57f9

Please sign in to comment.