Skip to content

Commit

Permalink
added methods to get names of model selection parameters and their de…
Browse files Browse the repository at this point in the history
…scriptions and index (to get type)
  • Loading branch information
karlnapf committed Aug 2, 2011
1 parent 6189797 commit 8c24d9e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/shogun/base/SGObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,51 @@ void CSGObject::init()
m_load_pre_called = false;
m_load_post_called = false;
}

SGVector<char*> CSGObject::get_modelsel_names()
{
SGVector<char*> result=SGVector<char*>(
m_model_selection_parameters->get_num_parameters());

for (index_t i=0; i<result.vlen; ++i)
result.vector[i]=m_model_selection_parameters->get_parameter(i)->m_name;

return result;
}

char* CSGObject::get_modsel_param_descr(const char* param_name)
{
index_t index=get_modsel_param_index(param_name);

if (index<0)
{
SG_ERROR("There is no model selection parameter called \"%s\" for %s",
param_name, get_name());
}

return m_model_selection_parameters->get_parameter(index)->m_description;
}

index_t CSGObject::get_modsel_param_index(const char* param_name)
{
/* use fact that names extracted from below method are in same order than
* in m_model_selection_parameters variable */
SGVector<char*> names=get_modelsel_names();

/* search for parameter with provided name */
index_t index=-1;
for (index_t i=0; i<names.vlen; ++i)
{
TParameter* current=m_model_selection_parameters->get_parameter(i);
if (!strcmp(param_name, current->m_name))
{
index=i;
break;
}
}

/* clean up */
names.destroy_vector();

return index;
}
20 changes: 20 additions & 0 deletions src/shogun/base/SGObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ class CSGObject
*/
Version* get_global_version();

/** @return vector of names of all parameters which are registered for model
* selection */
SGVector<char*> get_modelsel_names();

/** Returns description of a given parameter string, if it exists. SG_ERROR
* otherwise
*
* @param modsel_param name of the parameter
* @return description of the parameter
*/
char* get_modsel_param_descr(const char* param_name);

/** Returns index of model selection parameter with provided index
*
* @param param_name name of model selection parameter
* @return index of model selection parameter with provided name,
* -1 if there is no such
*/
index_t get_modsel_param_index(const char* param_name);

#ifdef TRACE_MEMORY_ALLOCS
static void list_memory_allocs()
{
Expand Down

0 comments on commit 8c24d9e

Please sign in to comment.