/usr/include/shogun/modelselection/ParameterCombination.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | /*
* 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-2012 Heiko Strathmann
* Written (W) 2013 Roman Votyakov
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
*/
#ifndef __PARAMETERCOMBINATION_H__
#define __PARAMETERCOMBINATION_H__
#include <shogun/lib/DynamicObjectArray.h>
#include <shogun/lib/Map.h>
namespace shogun
{
class CModelSelectionParameters;
class CMachine;
class Parameter;
/** @brief Class that holds ONE combination of parameters for a learning
* machine. The structure is organized as a tree. Every node may hold a name or
* an instance of a Parameter class. Nodes may have children. The nodes are
* organized in such way, that every parameter of a model for model selection
* has one node and sub-parameters are stored in sub-nodes. Using a tree of this
* class, parameters of models may easily be set. There are these types of
* nodes:
*
* -root node: no name and no Parameter instance, every tree has such a node as
* root. Has children.
*
* -Parameter node: a node with no name and an instance of Parameter, filled
* with one or more values. There may be different elements in these Parameter
* instances. Parameter nodes may have children with sub-parameters.
*
* Again: Leafs of the tree may only be Parameter nodes.
*/
class CParameterCombination : public CSGObject
{
friend class CModelSelectionParameters;
public:
/** constructor for a root node */
CParameterCombination();
/** constructor for a parameter node
*
* @param param parameter node
*/
CParameterCombination(Parameter* param);
/** constructor for an object. Builds parameter combination of the gradient
* parameters.
*
* It adds parameters recursively starting from given object (given object
* becomes the root node).
*
* @param obj object to build parameter combination
*/
CParameterCombination(CSGObject* obj);
/** destructor also recursively destroys complete tree (SG_UNREF of child
* nodes)
*/
virtual ~CParameterCombination();
/** Prints a representation of the current node
*
* @param prefix_num number of tabs that will be prefixed for every output.
* At each recursion level, one is added.
*/
void print_tree(int prefix_num=0) const;
/** applies this parameter tree to a parameter instance
*
* Recursively iterates over all children of the tree and sets model
* selection parameters of children to sub-parameters
*
* @param parameter Parameter instance to apply parameter tree to
*/
void apply_to_modsel_parameter(Parameter* parameter) const;
/** applies this parameter tree to a learning machine (wrapper for
* apply_to_modesel_parameter() method)
*
* @param machine learning machine to apply parameter tree to
*/
void apply_to_machine(CMachine* machine) const;
/** appends a child to this node
*
* @param child child to append
*/
void append_child(CParameterCombination* child);
/** Adds (copies of) all children of given node
*
* @param node (copies of) children of given node are added to this one
*/
void merge_with(CParameterCombination* node);
/** Copies the complete tree of this node. Note that nodes are actually
* copied. If this is a parameter node, a NEW Parameter instance to the same
* data is created in the copy
*
* @return copy of the tree with this node as root as described above
*/
CParameterCombination* copy_tree() const;
/** Takes a set of sets of leafs nodes (!) and produces a set of instances
* of this class that contain every combination of the parameters in the leaf
* nodes in their Parameter variables. All combinations are put into a newly
* created tree. The root of this tree will be a copy of a specified node
*
* created Parameter instances are added to the result set.
*
* @param sets Set of sets of leafs to combine
* @param new_root root node that is copied and put as root into all result
* trees
* @result result set of tree combinations
*/
static CDynamicObjectArray* leaf_sets_multiplication(
const CDynamicObjectArray& sets,
const CParameterCombination* new_root);
/** Sets specific parameter to specified value.
*
* @param name Name of parameter
* @param value value to be set
* @param parent The CSObject that directly holds this parameter
* @param index index if the parameter is a vector
*
* @return bool true if value successfully set.
*/
template <typename T>
bool set_parameter(const char* name,
T value, CSGObject* parent, index_t index = -1)
{
bool match = false;
if (m_param)
{
for (index_t i = 0; i < m_param->get_num_parameters(); ++i)
{
void* param = m_param->get_parameter(i)->m_parameter;
if (m_param->get_parameter(i)->m_datatype.m_ptype
==PT_SGOBJECT)
{
if (parent == (*((CSGObject**)param)))
match = true;
}
}
}
bool result = false;
for (index_t i = 0; i < m_child_nodes->get_num_elements(); ++i)
{
CParameterCombination* child = (CParameterCombination*)
m_child_nodes->get_element(i);
if (!match)
result |= child->set_parameter(name, value, parent, index);
else
result |= child->set_parameter_helper(name, value, index);
SG_UNREF(child);
}
return result;
}
/** Gets specific parameter by name.
*
* @param name Name of parameter
* @param parent The CSObject that directly holds this parameter
*
* return specified parameter. NULL if not found.
*/
TParameter* get_parameter(const char* name, CSGObject* parent);
/** checks whether this node has children
*
* @return true if node has children
*/
bool has_children() const
{
return m_child_nodes->get_num_elements()>0;
}
/** Returns a newly created array with pointers to newly created Parameter
* instances, which contain all combinations of the provided Parameters.
*
* @param set_1 array of Parameter instances
* @param set_2 array of Parameter instances
* @return result array with all combinations
*/
static DynArray<Parameter*>* parameter_set_multiplication(
const DynArray<Parameter*>& set_1,
const DynArray<Parameter*>& set_2);
/** @return name of the SGSerializable */
virtual const char* get_name() const
{
return "ParameterCombination";
}
/** returns total length of the parameters in combination
*
* @return total length of the parameters in combination
*/
virtual uint32_t get_parameters_length() { return m_parameters_length; }
/** builds map, which contains parameters and its values.
*
* This method adds to map only parameters of floating point type.
*
* @param values_map map, which contains parameters and its values
*/
virtual void build_parameter_values_map(
CMap<TParameter*, SGVector<float64_t> >* values_map);
/** builds map, which contains parameters and its parents
*
* @param parent_map map, which contains parameters and its parents
*/
virtual void build_parameter_parent_map(
CMap<TParameter*, CSGObject*>* parent_map);
protected:
/** Takes a set of sets of (non-value) trees and returns a set with all
* combinations of the elements, where only combinations of trees with
* different names are built.
*
* @param sets set of sets of CParameterCombination instances which
* represent the trees to be multiplied
* @param new_root this new root is put in front of all products
* @return set of trees with the given root as root and all combinations
* of the trees in the sets as children
*/
static CDynamicObjectArray* non_value_tree_multiplication(
const CDynamicObjectArray* sets,
const CParameterCombination* new_root);
/** Takes a set of sets of trees and extracts all trees with a given name.
* Assumes that in a (inner) set, all trees have the same name on their
* single parameter. Used by get_combinations
*
* @param sets set of sets of CParameterCombination instances to search in
* @param desired_name tree with this name is searched
* @return set of trees with the desired name
*/
static CDynamicObjectArray* extract_trees_with_name(
const CDynamicObjectArray* sets, const char* desired_name);
/** Gets parameter by name in current node.
*
* @param name name of parameter
* @return parameter. Null if not found.
*/
TParameter* get_parameter_helper(const char* name);
/** Sets parameter by name in current node.
*
* @param name name of parameter
* @param value of parameter
* @param index index if parameter is a vector
*
* @return true if found.
*/
bool set_parameter_helper(const char* name, bool value, index_t index);
/** Sets parameter by name in current node.
*
* @param name name of parameter
* @param value of parameter
* @param index index if parameter is a vector
*
* @return true if found.
*/
bool set_parameter_helper(const char* name, int32_t value, index_t index);
/** Sets parameter by name in current node.
*
* @param name name of parameter
* @param value of parameter
* @param index index if parameter is a vector
*
* @return true if found.
*/
bool set_parameter_helper(const char* name, float64_t value, index_t index);
private:
void init();
protected:
/** parameter of combination */
Parameter* m_param;
/** child parameters */
CDynamicObjectArray* m_child_nodes;
/** total length of the parameters in combination */
uint32_t m_parameters_length;
};
}
#endif /* __PARAMETERCOMBINATION_H__ */
|