Add only parameter to gridsearch

This commit is contained in:
Ricardo Montañana Gómez 2023-11-28 10:08:40 +01:00
parent d06bf187b2
commit 8dbbb65a2f
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
4 changed files with 36 additions and 9 deletions

25
.vscode/launch.json vendored
View File

@ -14,7 +14,7 @@
"-s", "-s",
"271", "271",
"-p", "-p",
"/home/rmontanana/Code/discretizbench/datasets/", "/Users/rmontanana/Code/discretizbench/datasets/",
], ],
//"cwd": "${workspaceFolder}/build/sample/", //"cwd": "${workspaceFolder}/build/sample/",
}, },
@ -33,7 +33,22 @@
// "--hyperparameters", // "--hyperparameters",
// "{\"repeatSparent\": true, \"maxModels\": 12}" // "{\"repeatSparent\": true, \"maxModels\": 12}"
], ],
"cwd": "/home/rmontanana/Code/discretizbench", "cwd": "${workspaceFolder}/../discretizbench",
},
{
"type": "lldb",
"request": "launch",
"name": "gridsearch",
"program": "${workspaceFolder}/build_debug/src/Platform/b_grid",
"args": [
"-m",
"KDB",
"--discretize",
"--continue",
"glass",
"--only"
],
"cwd": "${workspaceFolder}/../discretizbench",
}, },
{ {
"type": "lldb", "type": "lldb",
@ -64,7 +79,7 @@
"accuracy", "accuracy",
"--build", "--build",
], ],
"cwd": "/home/rmontanana/Code/discretizbench", "cwd": "${workspaceFolder}/../discretizbench",
}, },
{ {
"type": "lldb", "type": "lldb",
@ -75,7 +90,7 @@
"-n", "-n",
"20" "20"
], ],
"cwd": "/home/rmontanana/Code/discretizbench", "cwd": "${workspaceFolder}/../discretizbench",
}, },
{ {
"type": "lldb", "type": "lldb",
@ -84,7 +99,7 @@
"program": "${workspaceFolder}/build_debug/src/Platform/b_list", "program": "${workspaceFolder}/build_debug/src/Platform/b_list",
"args": [], "args": [],
//"cwd": "/Users/rmontanana/Code/discretizbench", //"cwd": "/Users/rmontanana/Code/discretizbench",
"cwd": "/home/rmontanana/Code/covbench", "cwd": "${workspaceFolder}/../discretizbench",
}, },
{ {
"type": "lldb", "type": "lldb",

View File

@ -123,17 +123,23 @@ namespace platform {
} }
} }
catch (const std::exception& e) { catch (const std::exception& e) {
std::cerr << "Error loading previous results: " << e.what() << std::endl; std::cerr << "* There were no previous results" << std::endl;
std::cerr << "* Initizalizing new results" << std::endl;
results = json();
} }
// Remove datasets already processed // Remove datasets already processed
vector< string >::iterator it = datasets_names.begin(); vector< string >::iterator it = datasets_names.begin();
while (it != datasets_names.end()) { while (it != datasets_names.end()) {
if (*it != config.continue_from) { if (*it != config.continue_from) {
it = datasets_names.erase(it); it = datasets_names.erase(it);
} else } else {
if (config.only)
++it;
else
break; break;
} }
} }
}
// Create model // Create model
std::cout << "***************** Starting Gridsearch *****************" << std::endl; std::cout << "***************** Starting Gridsearch *****************" << std::endl;
std::cout << "input file=" << config.input_file << std::endl; std::cout << "input file=" << config.input_file << std::endl;

View File

@ -17,6 +17,7 @@ namespace platform {
std::string output_file; std::string output_file;
std::string continue_from; std::string continue_from;
bool quiet; bool quiet;
bool only; // used with continue_from to only compute that dataset
bool discretize; bool discretize;
bool stratified; bool stratified;
int n_folds; int n_folds;

View File

@ -23,9 +23,10 @@ argparse::ArgumentParser manageArguments(std::string program_name)
} }
); );
program.add_argument("--discretize").help("Discretize input datasets").default_value((bool)stoi(env.get("discretize"))).implicit_value(true); program.add_argument("--discretize").help("Discretize input datasets").default_value((bool)stoi(env.get("discretize"))).implicit_value(true);
program.add_argument("--stratified").help("If Stratified KFold is to be done").default_value((bool)stoi(env.get("stratified"))).implicit_value(true);
program.add_argument("--quiet").help("Don't display detailed progress").default_value(false).implicit_value(true); program.add_argument("--quiet").help("Don't display detailed progress").default_value(false).implicit_value(true);
program.add_argument("--continue").help("Continue computing from that dataset").default_value("No"); program.add_argument("--continue").help("Continue computing from that dataset").default_value("No");
program.add_argument("--stratified").help("If Stratified KFold is to be done").default_value((bool)stoi(env.get("stratified"))).implicit_value(true); program.add_argument("--only").help("Used with continue to compute that dataset only").default_value(false).implicit_value(true);
program.add_argument("--score").help("Score used in gridsearch").default_value("accuracy"); program.add_argument("--score").help("Score used in gridsearch").default_value("accuracy");
program.add_argument("-f", "--folds").help("Number of folds").default_value(stoi(env.get("n_folds"))).scan<'i', int>().action([](const std::string& value) { program.add_argument("-f", "--folds").help("Number of folds").default_value(stoi(env.get("n_folds"))).scan<'i', int>().action([](const std::string& value) {
try { try {
@ -58,8 +59,12 @@ int main(int argc, char** argv)
config.stratified = program.get<bool>("stratified"); config.stratified = program.get<bool>("stratified");
config.n_folds = program.get<int>("folds"); config.n_folds = program.get<int>("folds");
config.quiet = program.get<bool>("quiet"); config.quiet = program.get<bool>("quiet");
config.only = program.get<bool>("only");
config.seeds = program.get<std::vector<int>>("seeds"); config.seeds = program.get<std::vector<int>>("seeds");
config.continue_from = program.get<std::string>("continue"); config.continue_from = program.get<std::string>("continue");
if (config.continue_from == "No" && config.only) {
throw std::runtime_error("Cannot use --only without --continue");
}
} }
catch (const exception& err) { catch (const exception& err) {
cerr << err.what() << std::endl; cerr << err.what() << std::endl;