Skip to content

Commit

Permalink
optim: cleaning print() methods for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Apr 27, 2024
1 parent b4460c4 commit 96317f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/optim/src/gradsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,29 @@ 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;
printf("{");
for (i=0; i<_q->num_parameters; i++)
printf("%8.4f", _q->v[i]);
printf("}\n");
#else
printf("<liquid.gradsearch");
printf(", n=%u", _q->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)
Expand Down
10 changes: 10 additions & 0 deletions src/optim/src/qnsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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("<liquid.gradsearch");
printf(", n=%u", _q->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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/optim/src/qs1dsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int qs1dsearch_destroy(qs1dsearch _q)

int qs1dsearch_print(qs1dsearch _q)
{
printf("<liquid.qs1dsearch{%12g,%12g,%12g}{%12g,%12g,%12g}>\n",
printf("<liquid.qs1dsearch, v=[%12g,%12g,%12g], u=[%12g,%12g,%12g]>\n",
_q->vn, _q->v0, _q->vp, _q->un, _q->u0, _q->up);
return LIQUID_OK;
}
Expand Down
6 changes: 2 additions & 4 deletions src/optim/src/utilities.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,9 +20,7 @@
* THE SOFTWARE.
*/

//
// utilities.c : n-dimensional utility functions
//
// n-dimensional utility functions

#include <stdio.h>
#include <stdlib.h>
Expand Down

0 comments on commit 96317f5

Please sign in to comment.