📄 windowslide.cpp
字号:
/* Context : Fuzzy Clustering Algorithms Author : Frank Hoeppner, see also AUTHORS file Description : implementation of class module WindowSlide History : Comment : This file was generated automatically. DO NOT EDIT. Copyright : Copyright (C) 1999-2000 Frank Hoeppner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*//* The University of Applied Sciences Oldenburg/Ostfriesland/Wilhelmshaven hereby disclaims all copyright interests in the program package `fc' (tool package for fuzzy cluster analysis) written by Frank Hoeppner. Prof. Haass, President of Vice, 2000-Mar-10*/#ifndef WindowSlide_SOURCE#define WindowSlide_SOURCE/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif// necessary includes#include "WindowSlide.hpp"// data// implementationtemplate < class ANALYSIS >WindowSlide< ANALYSIS >::WindowSlide ( OnePassAlgorithm<ANALYSIS> *ap_alg ) : mp_succ_alg(ap_alg) , m_elem_funcs_called(false) , m_emulated_elem_wise(false) { }template < class ANALYSIS >WindowSlide< ANALYSIS >::~WindowSlide ( ) { FUNCLOG("~WindowSlide"); delete mp_succ_alg; }template < class ANALYSIS >voidWindowSlide< ANALYSIS >::operator() ( ANALYSIS& a_analysis ) { FUNCLOG("WindowSlide"); if (!m_elem_funcs_called) { m_emulated_elem_wise = true; operator()(a_analysis,a_analysis.option()); for ( typename ANALYSIS::data_iter i_data(a_analysis.data().begin()); i_data != a_analysis.data().end(); ++i_data ) { operator()(a_analysis,*i_data); } for ( typename ANALYSIS::prot_iter i_prot(a_analysis.prototypes().begin()); i_prot != a_analysis.prototypes().end(); ++i_prot ) { operator()(a_analysis,*i_prot); } for ( typename ANALYSIS::link_iter i_link(a_analysis.links().begin()); i_link != a_analysis.links().end(); ++i_link ) { operator()(a_analysis,*i_link); } } call_successor(mp_succ_alg,a_analysis,"wins"); m_elem_funcs_called=false; m_emulated_elem_wise=false; }template < class ANALYSIS >voidWindowSlide< ANALYSIS >::operator() ( ANALYSIS& a_analysis, WindowSlide< ANALYSIS >::opt_type& a_option ) { FUNCLOG("WindowSlide::operator(opt)"); if (!m_elem_funcs_called) reset(a_analysis); m_buffer_size=10; // read from options m_window_width=3; // read m_ring_index=0; m_sample_size=0; m_full=false; m_border=NEG_IMPOSSIBLE_RANGE; m_ring_buffer.adjust(m_buffer_size); m_weight_buffer.adjust(m_buffer_size); m_feature.datum().adjust(m_buffer_size); a_option.number_prototypes() = DEFAULT_OPTION_PROTCOUNT; // will be deleted a_option.number_features() = DEFAULT_OPTION_DATACOUNT; // will change a_option.data_dimension() = m_buffer_size; // new size (*mp_succ_alg)(a_analysis,a_option); }template < class ANALYSIS >voidWindowSlide< ANALYSIS >::operator() ( ANALYSIS& a_analysis, WindowSlide< ANALYSIS >::data_type& a_datum ) { FUNCLOG("WindowSlide::operator(data)"); if (!m_elem_funcs_called) reset(a_analysis); trace("buffer=",m_ring_buffer); real_type x(a_datum.select(a_analysis.option().m_selector[AXIS_X])); real_type y(a_datum.select(a_analysis.option().m_selector[AXIS_Y])); if (m_border==NEG_IMPOSSIBLE_RANGE) // this is first data object { m_border = x + m_window_width/m_buffer_size; } if (x<m_border) { m_ring_buffer[m_ring_index] += y; m_weight_buffer[m_ring_index] += a_datum.weight(); ++m_sample_size; } else // ring buffer element finished { // calc mean value if (m_sample_size>0) m_ring_buffer[m_ring_index] /= m_sample_size; // reset values m_sample_size=0; // increase border m_border += m_window_width/m_buffer_size; if (m_full) // ring buffer completely filled { // calc new datum real_type mean(0),var(0); // for (int i=0;i<m_buffer_size;++i) { mean += m_ring_buffer(i); var += SQR(m_ring_buffer(i)); } mean /= m_buffer_size; var = sqrt(1.0/(m_buffer_size-1) * (var - SQR(mean)*m_buffer_size)); // m_feature.weight()=0; for (int i=0;i<m_buffer_size;++i) { int index((i+m_ring_index+1)%m_buffer_size); // m_feature.datum()(i) = m_ring_buffer(index); // m_feature.datum()(i) = m_ring_buffer(index)-mean; m_feature.datum()(i) = (m_ring_buffer(index)-mean)/var; m_feature.weight() += m_weight_buffer(index); } m_feature.weight()=DEFAULT_FEATURE_WEIGHT; ++m_ring_index; if (m_ring_index==m_buffer_size) m_ring_index=0; // push new datum (*mp_succ_alg)(a_analysis,m_feature); } else { ++m_ring_index; m_full = (m_ring_index==m_buffer_size-1); } // reset new buffer element { m_ring_buffer(m_ring_index) = 0; m_weight_buffer(m_ring_index) = 0; } } }template < class ANALYSIS >voidWindowSlide< ANALYSIS >::operator() ( ANALYSIS& a_analysis, WindowSlide< ANALYSIS >::prot_type& a_prototype ) { FUNCLOG("WindowSlide::operator(prot)"); if (!m_elem_funcs_called) reset(a_analysis); }template < class ANALYSIS >voidWindowSlide< ANALYSIS >::operator() ( ANALYSIS& a_analysis, WindowSlide< ANALYSIS >::link_type& a_link ) { FUNCLOG("WindowSlide::operator(link)"); if (!m_elem_funcs_called) reset(a_analysis); }template < class ANALYSIS >voidWindowSlide< ANALYSIS >::reset ( ANALYSIS& a_analysis ) { FUNCLOG("WindowSlide::reset"); m_elem_funcs_called=true; }// template instantiation#endif // WindowSlide_SOURCE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -