From 96317f58e836eed63e7aeb9507e9032ded074db5 Mon Sep 17 00:00:00 2001 From: "Joseph D. Gaeddert" Date: Sat, 27 Apr 2024 13:36:08 -0400 Subject: [PATCH] optim: cleaning print() methods for consistency --- src/optim/src/gradsearch.c | 13 +++++++++++-- src/optim/src/qnsearch.c | 10 ++++++++++ src/optim/src/qs1dsearch.c | 2 +- src/optim/src/utilities.c | 6 ++---- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/optim/src/gradsearch.c b/src/optim/src/gradsearch.c index d079f4b9c4..269d7f775f 100644 --- a/src/optim/src/gradsearch.c +++ b/src/optim/src/gradsearch.c @@ -92,13 +92,12 @@ void gradsearch_destroy(gradsearch _q) // print status void gradsearch_print(gradsearch _q) { +#if 0 //printf("gradient search:\n"); printf("u=%12.4e ", _q->u); // utility -#if 0 // enable more verbose output printf("|p|=%7.1e ", _q->pnorm); // norm(p) printf("del=%7.1e ", _q->delta); // delta -#endif printf("step=%7.1e ", _q->alpha); // alpha (step size) unsigned int i; @@ -106,6 +105,16 @@ void gradsearch_print(gradsearch _q) for (i=0; i<_q->num_parameters; i++) printf("%8.4f", _q->v[i]); printf("}\n"); +#else + printf("num_parameters); + printf(", dir=\"%s\"", _q->direction == LIQUID_OPTIM_MAXIMIZE ? "max" : "min"); + printf(", pnorm=%g", _q->pnorm); // norm(p) + printf(", delta=%g", _q->delta); // delta + printf(", u=%g", _q->u); + printf(">\n"); +#endif + // return LIQUID_OK; } float gradsearch_step(gradsearch _q) diff --git a/src/optim/src/qnsearch.c b/src/optim/src/qnsearch.c index 61bef05569..9786f6467e 100644 --- a/src/optim/src/qnsearch.c +++ b/src/optim/src/qnsearch.c @@ -120,11 +120,21 @@ int qnsearch_destroy(qnsearch _q) int qnsearch_print(qnsearch _q) { +#if 0 printf("[%.3f] ", _q->utility); unsigned int i; for (i=0; i<_q->num_parameters; i++) printf("%.3f ", _q->v[i]); printf("\n"); +#else + printf("num_parameters); + printf(", dir=\"%s\"", _q->minimize ? "min" : "max"); + printf(", gamma=%g", _q->gamma); + printf(", delta=%g", _q->delta); // delta + printf(", u=%g", _q->utility); + printf(">\n"); +#endif return LIQUID_OK; } diff --git a/src/optim/src/qs1dsearch.c b/src/optim/src/qs1dsearch.c index 16600b829d..abf8a1f71c 100644 --- a/src/optim/src/qs1dsearch.c +++ b/src/optim/src/qs1dsearch.c @@ -71,7 +71,7 @@ int qs1dsearch_destroy(qs1dsearch _q) int qs1dsearch_print(qs1dsearch _q) { - printf("\n", + printf("\n", _q->vn, _q->v0, _q->vp, _q->un, _q->u0, _q->up); return LIQUID_OK; } diff --git a/src/optim/src/utilities.c b/src/optim/src/utilities.c index a8d1be3511..61c5d835d9 100644 --- a/src/optim/src/utilities.c +++ b/src/optim/src/utilities.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 - 2020 Joseph Gaeddert + * Copyright (c) 2007 - 2024 Joseph Gaeddert * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,9 +20,7 @@ * THE SOFTWARE. */ -// -// utilities.c : n-dimensional utility functions -// +// n-dimensional utility functions #include #include