Simplified misc.h and misc.cc.
[svrt.git] / global.cc
1 /*
2  *  svrt is the ``Synthetic Visual Reasoning Test'', an image
3  *  generator for evaluating classification performance of machine
4  *  learning systems, humans and primates.
5  *
6  *  Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of svrt.
10  *
11  *  svrt is free software: you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  svrt is distributed in the hope that it will be useful, but
16  *  WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with selector.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include <string.h>
26
27 #include "global.h"
28
29 Global global;
30
31 Global::Global() { }
32
33 Global::~Global() { }
34
35 void Global::init_parser(ParamParser *parser) {
36   // The nice level of the process
37   parser->add_association("niceness", "15", false);
38   // Seed to initialize the random generator
39   parser->add_association("random_seed", "0", false);
40
41   // Where to put the generated files
42   parser->add_association("result_path", "/tmp/", false);
43   // The classifier filename
44   parser->add_association("classifier_name", "default.clf", false);
45
46   // Should we display a progress bar for lengthy operations
47   parser->add_association("progress_bar", "yes", false);
48
49   // The problem number
50   parser->add_association("problem_number", "0", false);
51
52   // The number of samples for training and testing
53   parser->add_association("nb_train_samples", "1000", false);
54   parser->add_association("nb_test_samples", "1000", false);
55   parser->add_association("nb_weak_learners", "1000", false);
56   parser->add_association("nb_optimization_weak_learners", "100", false);
57   parser->add_association("nb_sampled_samples", "-1", false);
58 }
59
60 void Global::read_parser(ParamParser *parser) {
61   niceness = parser->get_association_int("niceness");
62   random_seed = parser->get_association_int("random_seed");
63
64   strncpy(result_path, parser->get_association("result_path"), buffer_size);
65   strncpy(classifier_name, parser->get_association("classifier_name"), buffer_size);
66   if(!classifier_name[0]) {
67     sprintf(classifier_name, "%s/default.clf", result_path);
68   }
69
70   bar.set_visible(parser->get_association_bool("progress_bar"));
71
72   problem_number = parser->get_association_int("problem_number");
73
74   nb_train_samples = parser->get_association_int("nb_train_samples");
75   nb_test_samples = parser->get_association_int("nb_test_samples");
76   nb_weak_learners = parser->get_association_int("nb_weak_learners");
77   nb_optimization_weak_learners = parser->get_association_int("nb_optimization_weak_learners");
78   nb_sampled_samples = parser->get_association_int("nb_sampled_samples");
79 }