vw_math.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Yahoo! Inc.  All rights reserved.  The copyrights
00003  * embodied in the content of this file are licensed under the BSD
00004  * (revised) open source license.
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * Adaptation of Vowpal Wabbit v5.1.
00012  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society.
00013  */
00014 
00015 #include <shogun/classifier/vw/vw_math.h>
00016 
00017 namespace shogun
00018 {
00019 
00020 float32_t sd_offset_add(float32_t* weights, vw_size_t mask, VwFeature* begin, VwFeature* end, vw_size_t offset)
00021 {
00022     float32_t ret = 0.;
00023     for (VwFeature* f = begin; f!= end; f++)
00024         ret += weights[(f->weight_index + offset) & mask] * f->x;
00025     return ret;
00026 }
00027 
00028 float32_t sd_offset_truncadd(float32_t* weights, vw_size_t mask, VwFeature* begin, VwFeature* end, vw_size_t offset, float32_t gravity)
00029 {
00030     float32_t ret = 0.;
00031     for (VwFeature* f = begin; f!= end; f++)
00032     {
00033         float32_t w = weights[(f->weight_index+offset) & mask];
00034         float32_t wprime = real_weight(w,gravity);
00035         ret += wprime*f->x;
00036     }
00037     return ret;
00038 }
00039 
00040 float32_t one_pf_quad_predict(float32_t* weights, VwFeature& f, v_array<VwFeature> &cross_features, vw_size_t mask)
00041 {
00042     vw_size_t halfhash = quadratic_constant * f.weight_index;
00043 
00044     return f.x *
00045         sd_offset_add(weights, mask, cross_features.begin, cross_features.end, halfhash);
00046 }
00047 
00048 float32_t one_pf_quad_predict_trunc(float32_t* weights, VwFeature& f, v_array<VwFeature> &cross_features, vw_size_t mask, float32_t gravity)
00049 {
00050     vw_size_t halfhash = quadratic_constant * f.weight_index;
00051 
00052     return f.x *
00053         sd_offset_truncadd(weights, mask, cross_features.begin, cross_features.end, halfhash, gravity);
00054 }
00055 
00056 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation