SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
modelselection
ModelSelectionParameters.h
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 2011 Heiko Strathmann
8
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9
*/
10
11
#ifndef __MODELSELECTIONPARAMETERS_H_
12
#define __MODELSELECTIONPARAMETERS_H_
13
14
#include <
shogun/base/SGObject.h
>
15
#include <
shogun/lib/DynamicObjectArray.h
>
16
17
namespace
shogun
18
{
19
20
class
CParameterCombination;
21
23
enum
ERangeType
24
{
25
R_LINEAR
,
R_EXP
,
R_LOG
26
};
27
29
enum
EMSParamType
30
{
32
MSPT_NONE
=0,
33
34
/* float64_t */
35
MSPT_FLOAT64
,
36
37
/* int32_t */
38
MSPT_INT32
,
39
};
40
60
class
CModelSelectionParameters
:
public
CSGObject
61
{
62
public
:
64
CModelSelectionParameters
();
65
70
CModelSelectionParameters
(
const
char
* node_name);
71
77
CModelSelectionParameters
(
const
char
* node_name,
CSGObject
* sgobject);
78
80
~CModelSelectionParameters
();
81
86
void
append_child
(
CModelSelectionParameters
* child);
87
94
template
<
class
T>
95
void
set_values
(
SGVector<T>
values);
96
102
void
print_tree
(
int
prefix_num=0);
103
111
CDynamicObjectArray<CParameterCombination>
*
get_combinations
();
112
114
void
build_values
(
float64_t
min,
float64_t
max,
ERangeType
type,
115
float64_t
step=1.0,
float64_t
type_base=2.0);
116
118
void
build_values
(int32_t min, int32_t max,
ERangeType
type, int32_t step=1,
119
int32_t type_base=2);
120
122
inline
virtual
const
char
*
get_name
()
const
123
{
124
return
"ModelSelectionParameters"
;
125
}
126
127
private
:
128
void
init();
129
131
void
delete_values();
132
134
void
build_values
(
EMSParamType
param_type,
void
* min,
void
* max,
135
ERangeType
type,
void
* step,
void
* type_base);
136
137
protected
:
142
bool
has_children
()
const
143
{
144
return
m_child_nodes->
get_num_elements
()>0;
145
}
146
147
private
:
148
CSGObject
* m_sgobject;
149
const
char
* m_node_name;
150
SGVector<char>
m_values;
// dummy void type char
151
CDynamicObjectArray<CModelSelectionParameters>
* m_child_nodes;
152
EMSParamType
m_value_type;
153
};
154
168
template
<
class
T>
SGVector<T>
create_range_array
(T min, T max,
169
ERangeType
type, T step, T type_base)
170
{
171
if
(max<min)
172
SG_SERROR
(
"unable build values: max=%f < min=%f\n"
, max, min);
173
174
/* create value vector */
175
index_t
num_values=
CMath::round
(max-min)/step+1;
176
SGVector<T>
result(num_values);
177
178
/* fill array */
179
for
(
index_t
i=0; i<num_values; ++i)
180
{
181
T current=min+i*step;
182
183
switch
(type)
184
{
185
case
R_LINEAR
:
186
result.
vector
[i]=current;
187
break
;
188
case
R_EXP
:
189
result.
vector
[i]=
CMath::pow
((
float64_t
)type_base, current);
190
break
;
191
case
R_LOG
:
192
if
(current<=0)
193
SG_SERROR
(
"log(x) with x=%f\n"
, current);
194
195
/* custom base b: log_b(i*step)=log_2(i*step)/log_2(b) */
196
result.
vector
[i]=
CMath::log2
(current)/
CMath::log2
(type_base);
197
break
;
198
default
:
199
SG_SERROR
(
"unknown range type!\n"
);
200
break
;
201
}
202
}
203
204
return
result;
205
}
206
207
}
208
#endif
/* __MODELSELECTIONPARAMETERS_H_ */
SHOGUN
Machine Learning Toolbox - Documentation