SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
features
streaming
generators
MeanShiftDataGenerator.cpp
浏览该文件的文档.
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) 2012-2013 Heiko Strathmann
8
*/
9
10
#include <
shogun/lib/common.h
>
11
#include <
shogun/features/streaming/generators/MeanShiftDataGenerator.h
>
12
13
using namespace
shogun;
14
15
CMeanShiftDataGenerator::CMeanShiftDataGenerator
() :
16
CStreamingDenseFeatures
<
float64_t
>()
17
{
18
init();
19
}
20
21
CMeanShiftDataGenerator::CMeanShiftDataGenerator
(
float64_t
mean_shift,
22
index_t
dimension,
index_t
dimension_shift) :
23
CStreamingDenseFeatures
<
float64_t
>()
24
{
25
init();
26
set_mean_shift_model
(mean_shift, dimension, dimension_shift);
27
}
28
29
CMeanShiftDataGenerator::~CMeanShiftDataGenerator
()
30
{
31
}
32
33
void
CMeanShiftDataGenerator::set_mean_shift_model
(
float64_t
mean_shift,
34
index_t
dimension,
index_t
dimension_shift)
35
{
36
REQUIRE
(dimension_shift<dimension,
"%s::set_mean_shift_model(%f,%d,%d): "
37
"Dimension of shift is larger than number of dimensions!\n"
,
38
mean_shift, dimension, dimension_shift);
39
40
m_dimension
=dimension;
41
m_mean_shift
=mean_shift;
42
m_dimension_shift
=dimension_shift;
43
}
44
45
void
CMeanShiftDataGenerator::init()
46
{
47
SG_ADD
(&
m_dimension
,
"dimension"
,
"Dimension of data"
,
MS_NOT_AVAILABLE
);
48
SG_ADD
(&
m_mean_shift
,
"mean_shift"
,
"Mean shift in one dimension"
,
49
MS_NOT_AVAILABLE
);
50
SG_ADD
(&
m_dimension_shift
,
"m_dimension_shift"
,
"Dimension of mean shift"
,
51
MS_NOT_AVAILABLE
);
52
53
m_dimension
=0;
54
m_mean_shift
=0;
55
m_dimension_shift
=0;
56
57
unset_generic
();
58
}
59
60
bool
CMeanShiftDataGenerator::get_next_example
()
61
{
62
SG_SDEBUG
(
"entering CMeanShiftDataGenerator::get_next_example()\n"
);
63
64
/* allocate space */
65
SGVector<float64_t>
result=
SGVector<float64_t>
(
m_dimension
);
66
67
/* fill with std normal data */
68
for
(
index_t
i=0; i<
m_dimension
; ++i)
69
result[i]=
CMath::randn_double
();
70
71
/* mean shift in selected dimension */
72
result[
m_dimension_shift
]+=
m_mean_shift
;
73
74
/* save example back to superclass */
75
CMeanShiftDataGenerator::current_vector
=result;
76
77
SG_SDEBUG
(
"leaving CMeanShiftDataGenerator::get_next_example()\n"
);
78
return
true
;
79
}
80
81
void
CMeanShiftDataGenerator::release_example
()
82
{
83
SGVector<float64_t>
temp=
SGVector<float64_t>
();
84
CMeanShiftDataGenerator::current_vector
=temp;
85
}
SHOGUN
机器学习工具包 - 项目文档