SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2013 Viktor Gal 00008 * Copyright (C) 2013 Viktor Gal 00009 */ 00010 00011 #include <shogun/ensemble/MeanRule.h> 00012 #include <shogun/lib/SGVector.h> 00013 #include <shogun/lib/SGMatrix.h> 00014 00015 using namespace shogun; 00016 00017 CMeanRule::CMeanRule() 00018 : CCombinationRule() 00019 { 00020 00021 } 00022 00023 CMeanRule::~CMeanRule() 00024 { 00025 00026 } 00027 00028 SGVector<float64_t> CMeanRule::combine(const SGMatrix<float64_t>& ensemble_result) const 00029 { 00030 float64_t* row_sum = 00031 SGMatrix<float64_t>::get_column_sum(ensemble_result.matrix, 00032 ensemble_result.num_rows, 00033 ensemble_result.num_cols); 00034 00035 SGVector<float64_t> mean_labels(row_sum, ensemble_result.num_rows); 00036 00037 float64_t scale = 1/(float64_t)ensemble_result.num_cols; 00038 mean_labels.scale(scale); 00039 00040 return mean_labels; 00041 } 00042 00043 float64_t CMeanRule::combine(const SGVector<float64_t>& ensemble_result) const 00044 { 00045 float64_t combined = SGVector<float64_t>::sum(ensemble_result); 00046 combined /= (float64_t)ensemble_result.vlen; 00047 return combined; 00048 }