summaryrefslogtreecommitdiff
path: root/src/domain_newton.h
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jkentdobias@g.hmc.edu>2014-05-12 18:45:01 -0700
committerJaron Kent-Dobias <jkentdobias@g.hmc.edu>2014-05-12 18:45:01 -0700
commit68a2ac95b473090484fe55895952626a73d14514 (patch)
treede45950c6f1b6885beafb91cf960574dcb2fffa1 /src/domain_newton.h
parentbf1fc1949ec25c1b4290af9d7857f25cb05f693e (diff)
downloadcode-68a2ac95b473090484fe55895952626a73d14514.tar.gz
code-68a2ac95b473090484fe55895952626a73d14514.tar.bz2
code-68a2ac95b473090484fe55895952626a73d14514.zip
added a temporary peice of junk code to save the state of individual domain_newton interations
Diffstat (limited to 'src/domain_newton.h')
-rw-r--r--src/domain_newton.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/domain_newton.h b/src/domain_newton.h
index abb7ea3..3c806c0 100644
--- a/src/domain_newton.h
+++ b/src/domain_newton.h
@@ -2,6 +2,8 @@
#define DOMAIN_NEWTON_H
#include <math.h>
+#include <iostream>
+#include <string>
// GSL includes.
#include <gsl/gsl_math.h>
@@ -24,7 +26,8 @@ template <class energy_func, class grad_func, class hess_func>
int domain_newton(gsl_vector *state, unsigned size, unsigned params,
energy_func get_energy, grad_func get_grad, hess_func get_hess, double
epsilon, unsigned max_iterations, double beta, double s, double sigma,
- double gamma, double eta_0, double delta, double bound, bool verbose) {
+ double gamma, double eta_0, double delta, double bound, bool verbose, bool
+ save_states) {
/* The function domain_newton carries out a modified version of Newton's
* method. On success, 0 is returned. On failure, 1 is returned.
*
@@ -192,8 +195,8 @@ int domain_newton(gsl_vector *state, unsigned size, unsigned params,
if (fabs(norm - old_norm) < gamma * eta) eta *= delta;
// Prints several useful statistics for debugging purposes.
- if (verbose) printf("m was %i, grad_norm was %e, eta was %e, energy was %e\n",
- m, norm, eta, energy);
+ if (verbose) printf("NEWTON STEP %06d: m %i, grad_norm %e, eta %e, energy %e\n",
+ iterations, m, norm, eta, energy);
// Determines if the process has converged to acceptable precision.
if (norm < epsilon) {
@@ -207,6 +210,14 @@ int domain_newton(gsl_vector *state, unsigned size, unsigned params,
// Reset the norm for the next iteration.
old_norm = norm;
+ if (save_states) {
+ char str[40];
+ sprintf(str, "states/state-%06d.dat", iterations);
+ FILE *fout = fopen(str, "w");
+ gsl_vector_fprintf(fout, state, "%.15e");
+ fclose(fout);
+ }
+
// Increment the counter.
iterations++;
}