SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vw_math.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  * Adaptation of Vowpal Wabbit v5.1.
12  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society.
13  */
14 
16 
17 namespace shogun
18 {
19 
21 {
22  float32_t ret = 0.;
23  for (VwFeature* f = begin; f!= end; f++)
24  ret += weights[(f->weight_index + offset) & mask] * f->x;
25  return ret;
26 }
27 
28 float32_t sd_offset_truncadd(float32_t* weights, vw_size_t mask, VwFeature* begin, VwFeature* end, vw_size_t offset, float32_t gravity)
29 {
30  float32_t ret = 0.;
31  for (VwFeature* f = begin; f!= end; f++)
32  {
33  float32_t w = weights[(f->weight_index+offset) & mask];
34  float32_t wprime = real_weight(w,gravity);
35  ret += wprime*f->x;
36  }
37  return ret;
38 }
39 
41 {
43 
44  return f.x *
45  sd_offset_add(weights, mask, cross_features.begin, cross_features.end, halfhash);
46 }
47 
49 {
51 
52  return f.x *
53  sd_offset_truncadd(weights, mask, cross_features.begin, cross_features.end, halfhash, gravity);
54 }
55 
56 }
uint32_t weight_index
Hashed index in weight vector.
Definition: vw_example.h:41
uint32_t vw_size_t
vw_size_t typedef to work across platforms
Definition: vw_constants.h:26
T * end
Pointer to last set element in the array.
Definition: v_array.h:160
T * begin
Pointer to first element of the array.
Definition: v_array.h:157
float32_t sd_offset_add(float32_t *weights, vw_size_t mask, VwFeature *begin, VwFeature *end, vw_size_t offset)
Definition: vw_math.cpp:20
Class v_array taken directly from JL's implementation.
float32_t one_pf_quad_predict_trunc(float32_t *weights, VwFeature &f, v_array< VwFeature > &cross_features, vw_size_t mask, float32_t gravity)
Definition: vw_math.cpp:48
float32_t sd_offset_truncadd(float32_t *weights, vw_size_t mask, VwFeature *begin, VwFeature *end, vw_size_t offset, float32_t gravity)
Definition: vw_math.cpp:28
const int32_t quadratic_constant
Constant used while hashing/accessing quadratic features.
Definition: vw_constants.h:29
float32_t real_weight(float32_t w, float32_t gravity)
Definition: vw_math.h:35
float float32_t
Definition: common.h:49
One feature in VW.
Definition: vw_example.h:34
float32_t x
Feature value.
Definition: vw_example.h:38
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
float32_t one_pf_quad_predict(float32_t *weights, VwFeature &f, v_array< VwFeature > &cross_features, vw_size_t mask)
Definition: vw_math.cpp:40

SHOGUN Machine Learning Toolbox - Documentation