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) 2012-2013 Heiko Strathmann 00008 */ 00009 00010 #include <shogun/lib/common.h> 00011 #include <shogun/features/streaming/generators/MeanShiftDataGenerator.h> 00012 00013 using namespace shogun; 00014 00015 CMeanShiftDataGenerator::CMeanShiftDataGenerator() : 00016 CStreamingDenseFeatures<float64_t>() 00017 { 00018 init(); 00019 } 00020 00021 CMeanShiftDataGenerator::CMeanShiftDataGenerator(float64_t mean_shift, 00022 index_t dimension, index_t dimension_shift) : 00023 CStreamingDenseFeatures<float64_t>() 00024 { 00025 init(); 00026 set_mean_shift_model(mean_shift, dimension, dimension_shift); 00027 } 00028 00029 CMeanShiftDataGenerator::~CMeanShiftDataGenerator() 00030 { 00031 } 00032 00033 void CMeanShiftDataGenerator::set_mean_shift_model(float64_t mean_shift, 00034 index_t dimension, index_t dimension_shift) 00035 { 00036 REQUIRE(dimension_shift<dimension, "%s::set_mean_shift_model(%f,%d,%d): " 00037 "Dimension of shift is larger than number of dimensions!\n", 00038 mean_shift, dimension, dimension_shift); 00039 00040 m_dimension=dimension; 00041 m_mean_shift=mean_shift; 00042 m_dimension_shift=dimension_shift; 00043 } 00044 00045 void CMeanShiftDataGenerator::init() 00046 { 00047 SG_ADD(&m_dimension, "dimension", "Dimension of data", MS_NOT_AVAILABLE); 00048 SG_ADD(&m_mean_shift, "mean_shift", "Mean shift in one dimension", 00049 MS_NOT_AVAILABLE); 00050 SG_ADD(&m_dimension_shift, "m_dimension_shift", "Dimension of mean shift", 00051 MS_NOT_AVAILABLE); 00052 00053 m_dimension=0; 00054 m_mean_shift=0; 00055 m_dimension_shift=0; 00056 00057 unset_generic(); 00058 } 00059 00060 bool CMeanShiftDataGenerator::get_next_example() 00061 { 00062 SG_SDEBUG("entering CMeanShiftDataGenerator::get_next_example()\n"); 00063 00064 /* allocate space */ 00065 SGVector<float64_t> result=SGVector<float64_t>(m_dimension); 00066 00067 /* fill with std normal data */ 00068 for (index_t i=0; i<m_dimension; ++i) 00069 result[i]=CMath::randn_double(); 00070 00071 /* mean shift in selected dimension */ 00072 result[m_dimension_shift]+=m_mean_shift; 00073 00074 /* save example back to superclass */ 00075 CMeanShiftDataGenerator::current_vector=result; 00076 00077 SG_SDEBUG("leaving CMeanShiftDataGenerator::get_next_example()\n"); 00078 return true; 00079 } 00080 00081 void CMeanShiftDataGenerator::release_example() 00082 { 00083 SGVector<float64_t> temp=SGVector<float64_t>(); 00084 CMeanShiftDataGenerator::current_vector=temp; 00085 }