Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabled commandline with number of indices as argument #326

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
6 changes: 5 additions & 1 deletion include/parpeamici/optimizationApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ class OptimizationApplication {
protected:
// command line option parsing
const char *shortOptions = "dhvmt:o:s:";
struct option const longOptions[9] = {
struct option const longOptions[10] = {
{"debug", no_argument, nullptr, 'd'},
{"print-worklist", no_argument, nullptr, 'p'},
{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 'v'},
{"mpi", no_argument, nullptr, 'm'},
{"task", required_argument, nullptr, 't'},
{"gradient-check", required_argument, nullptr, 'g'},
{"outfile-prefix", required_argument, nullptr, 'o'},
{"first-start-idx", required_argument, nullptr, 's'},
{nullptr, 0, nullptr, 0}};
Expand All @@ -165,6 +166,8 @@ class OptimizationApplication {
gradientCheck
};

std::vector<int> para_ind {};

std::string dataFileName;
std::string resultFileName;

Expand All @@ -175,6 +178,7 @@ class OptimizationApplication {
std::unique_ptr<OptimizationProblem> problem;
H5::H5File h5File = 0;
OperationType operationType = OperationType::parameterEstimation;
int num_parameter_checks = 1;
LoadBalancerMaster loadBalancer;
bool withMPI = false;
};
Expand Down
30 changes: 25 additions & 5 deletions src/parpeamici/optimizationApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <random>
#include <csignal>
#include <cstdlib>
#include <sstream>
#include <iostream>

namespace parpe {

Expand Down Expand Up @@ -110,6 +112,21 @@ int OptimizationApplication::parseCliOptionsPostMpiInit(int argc, char **argv) {
if (strcmp(optarg, "gradient_check") == 0)
operationType = OperationType::gradientCheck;
break;
case 'g': {
operationType = OperationType::gradientCheck;
/*
Assuming the next argument is of the type n1,n2,...,nX.
This will be a string of comma separated ints, that need
to be converted to std::vector<int>.
*/
std::stringstream ss(optarg);

for (int i; ss >> i;) {
para_ind.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
} break;
case 'o':
resultFileName = processResultFilenameCommandLineArgument(optarg);
break;
Expand Down Expand Up @@ -230,9 +247,10 @@ int OptimizationApplication::run(int argc, char **argv) {
void OptimizationApplication::runMaster() {
switch (operationType) {
case OperationType::gradientCheck: {
const int numParameterIndicesToCheck = 10000;
optimizationProblemGradientCheckMultiEps(
problem.get(), numParameterIndicesToCheck);
std::vector<double> multi_eps {1e-1, 1e-3, 1e-4, 1e-5, 1e-7};
optimizationProblemGradientCheckMultiEps(problem.get(),
para_ind,
multi_eps);
break;
}
case OperationType::parameterEstimation:
Expand Down Expand Up @@ -266,8 +284,10 @@ void OptimizationApplication::runSingleProcess() {
switch (operationType) {
case OperationType::gradientCheck: {
const int numParameterIndicesToCheck = 10000;
optimizationProblemGradientCheckMultiEps(
problem.get(), numParameterIndicesToCheck);
const double epsilon = 1e-5;
optimizationProblemGradientCheck(problem.get(),
numParameterIndicesToCheck,
epsilon);
break;
}
case OperationType::parameterEstimation:
Expand Down
2 changes: 1 addition & 1 deletion src/parpeoptimization/optimizationProblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void optimizationProblemGradientCheckMultiEps(OptimizationProblem *problem,
int numParameterIndicesToCheck
) {
// set eps
std::vector<double> multi_eps {1e-1, 1e-3, 1e-5, 1e-7, 1e-9};
std::vector<double> multi_eps {1e-1, 1e-3, 1e-4, 1e-5, 1e-7};

// setting the number of parameters to the minimum of
// numParamaterIndicesToCheck and dimension of the problem
Expand Down