Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added parameter map example/test
  • Loading branch information
karlnapf committed Dec 28, 2011
1 parent b5aaa46 commit b5ed057
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/undocumented/libshogun/Makefile
Expand Up @@ -19,6 +19,7 @@ TARGETS = basic_minimal classifier_libsvm classifier_minimal_svm \
library_hash parameter_set_from_parameters \
parameter_iterate_float64 parameter_iterate_sgobject \
parameter_modsel_parameters \
parameter_map \
modelselection_parameter_combination_test \
modelselection_model_selection_parameters_test \
modelselection_parameter_tree \
Expand Down
90 changes: 90 additions & 0 deletions examples/undocumented/libshogun/parameter_map.cpp
@@ -0,0 +1,90 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2011 Heiko Strathmann
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
*/

#include <shogun/base/init.h>
#include <shogun/base/Parameter.h>
#include <shogun/base/ParameterMap.h>

using namespace shogun;

void print_message(FILE* target, const char* str)
{
fprintf(target, "%s", str);
}


int main(int argc, char **argv)
{
init_shogun(&print_message, &print_message, &print_message);

ParameterMap* map=new ParameterMap();

map->put(
new SGParamInfo("number", CT_SCALAR, ST_NONE, PT_FLOAT64, 2),
new SGParamInfo("number", CT_SCALAR, ST_NONE, PT_INT32, 1)
);

map->put(
new SGParamInfo("number", CT_SCALAR, ST_NONE, PT_INT32, 1),
new SGParamInfo("number", CT_SCALAR, ST_NONE, PT_FLOAT64, 0)
);

/* finalizing the map is needed before accessing it */
map->finalize_map();

map->print_map();
SG_SPRINT("\n");


/* get some elements from map, one/two ARE in map, three and four are NOT */
DynArray<SGParamInfo*> dummies;
dummies.append_element(new SGParamInfo("number", CT_SCALAR, ST_NONE,
PT_INT32, 1));
dummies.append_element(new SGParamInfo("number", CT_SCALAR, ST_NONE,
PT_FLOAT64, 2));
dummies.append_element(new SGParamInfo("number", CT_SCALAR, ST_NONE,
PT_INT32, 2));
dummies.append_element(new SGParamInfo("number", CT_SCALAR, ST_NONE,
PT_FLOAT64, 0));

for (index_t i=0; i<dummies.get_num_elements(); ++i)
{
SGParamInfo* current=dummies.get_element(i);

char* s=current->to_string();
SG_SPRINT("searching for: %s\n", s);
SG_FREE(s);

if (i==2)
{

}

SGParamInfo* result=map->get(current);
if (result)
{
s=result->to_string();
SG_SPRINT("found: %s\n\n", s);
SG_FREE(s);
}
else
SG_SPRINT("nothing found\n\n");

delete current;
}


delete map;

exit_shogun();

return 0;
}

0 comments on commit b5ed057

Please sign in to comment.