void BFFindMotif::FindMotifSub(std::deque<Point> &window) { size_t i = 0; for(i = 0; i < window.size() - m_MotifLength; ++i) { double distance = 0.0; bool newMotif = true; TimeSeries ts; ts.reserve(m_MotifLength); if(m_SlideWindow.size() >= m_MotifLength) // Only process slide window larger than motif length { // Get time series for(size_t j = i; j < i + m_MotifLength; ++j) { ts.push_back(window[j].second); } // Compare with candidate motif for(size_t j = 0; j < m_CandidateMotif.size(); ++j) { distance = EuclideanDistance(m_CandidateMotif[j].second, ts); if((2 * m_Radius > distance) && (m_Radius < distance)) // Neither new motif nor similar motif { newMotif = false; } else if(m_Radius > distance) // Similar motif { m_CandidateMotif[j].first++; i += m_Step; newMotif = false; break; // Impossible to be similar with other candidates } } if(true == newMotif) // New motif { m_CandidateMotif.push_back(make_pair<long long, TimeSeries>(1, ts)); i += m_Step; } } else { cerr << "Window size:" << m_SlideWindow.size() << endl; } } for(size_t k = 0; k < i; ++k) { window.pop_front(); } }
void SIMMA:: FindMotifSub(long &bufferCount) { long lLastSize = m_K; // last size of candidate motif buffer long step = 32; size_t i = 0; for(i = 0; i < m_SlideWindow.size() - m_MotifLength; ++i) { double distance = 0.0; bool newMotif = true; TimeSeries ts; ts.reserve(m_MotifLength); ++bufferCount; // Check buffer when size big enough if(true == m_bBufferCheck) { if((2 * m_K < bufferCount) && (5 * m_K < (int)m_CandidateMotif.size())) { this->BufferCheck(); lLastSize = m_SlideWindow.size(); bufferCount = 0; } } if(m_SlideWindow.size() >= m_MotifLength) // Only process slide window larger than motif length { // Get time series for(size_t j = i; j < i + m_MotifLength; ++j) { ts.push_back(m_SlideWindow[j].second); } // Compare with candidate motif for(size_t j = 0; j < m_CandidateMotif.size(); ++j) { distance = EuclideanDistance(m_CandidateMotif[j].second, ts); if((2 * m_Radius > distance) && (m_Radius < distance)) // Neither new motif nor similar motif { newMotif = false; } else if(m_Radius > distance) // Similar motif { m_CandidateMotif[j].first++; long jump = this->NonTrivialStep(i); if(0 != jump) i += jump; else i = m_SlideWindow.size() - m_MotifLength; newMotif = false; break; // Impossible to be similar with other candidates } } // Check whether current time series is new motif if(true == newMotif) { m_CandidateMotif.push_back(make_pair<long long, TimeSeries>(1, ts)); long jump = this->NonTrivialStep(i); if(0 != jump) i += jump; else i = m_SlideWindow.size() - m_MotifLength; } } } // Remove used elements for(size_t k = 0; k < i; ++k) { m_SlideWindow.pop_front(); } }