SHOGUN
v2.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
classifier
vw
learners
VwNonAdaptiveLearner.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights
3
* embodied in the content of this file are licensed under the BSD
4
* (revised) open source license.
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* Written (W) 2011 Shashwat Lal Das
12
* Adaptation of Vowpal Wabbit v5.1.
13
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society.
14
*/
15
16
#include <
shogun/classifier/vw/learners/VwNonAdaptiveLearner.h
>
17
18
using namespace
shogun;
19
20
CVwNonAdaptiveLearner::CVwNonAdaptiveLearner
()
21
:
CVwLearner
()
22
{
23
}
24
25
CVwNonAdaptiveLearner::CVwNonAdaptiveLearner
(
CVwRegressor
* regressor,
CVwEnvironment
* vw_env)
26
:
CVwLearner
(regressor, vw_env)
27
{
28
}
29
30
CVwNonAdaptiveLearner::~CVwNonAdaptiveLearner
()
31
{
32
}
33
34
void
CVwNonAdaptiveLearner::train
(
VwExample
* &ex,
float32_t
update
)
35
{
36
if
(fabs(update) == 0.)
37
return
;
38
vw_size_t
thread_mask =
env
->
thread_mask
;
39
40
vw_size_t
thread_num = 0;
41
float32_t
* weights =
reg
->
weight_vectors
[thread_num];
42
43
for
(
vw_size_t
* i = ex->
indices
.
begin
; i != ex->
indices
.
end
; i++)
44
{
45
for
(
VwFeature
* f = ex->
atomics
[*i].
begin
; f != ex->
atomics
[*i].
end
; f++)
46
weights[f->weight_index & thread_mask] += update * f->x;
47
}
48
49
for
(int32_t k = 0; k <
env
->
pairs
.
get_num_elements
(); k++)
50
{
51
char
* i =
env
->
pairs
.
get_element
(k);
52
53
v_array<VwFeature>
temp = ex->
atomics
[(int32_t)(i[0])];
54
temp.
begin
= ex->
atomics
[(int32_t)(i[0])].
begin
;
55
temp.
end
= ex->
atomics
[(int32_t)(i[0])].
end
;
56
for
(; temp.
begin
!= temp.
end
; temp.
begin
++)
57
quad_update(weights, *temp.
begin
, ex->
atomics
[(int32_t)(i[1])], thread_mask, update);
58
}
59
}
60
61
void
CVwNonAdaptiveLearner::quad_update(
float32_t
* weights,
VwFeature
& page_feature,
v_array<VwFeature>
&offer_features,
vw_size_t
mask,
float32_t
update
)
62
{
63
vw_size_t
halfhash =
quadratic_constant
* page_feature.
weight_index
;
64
update *= page_feature.
x
;
65
for
(
VwFeature
* elem = offer_features.
begin
; elem != offer_features.
end
; elem++)
66
weights[(halfhash + elem->weight_index) & mask] += update * elem->x;
67
}
SHOGUN
Machine Learning Toolbox - Documentation