Skip to content
Snippets Groups Projects
calcul.cpp 28.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • ///Calculates first cell included in the warping window.
    ///@param[in] row row
    ///@param[in] win warping window width
    ///@param[in] coefficient input time series length ratio
    ///@return index of first cell in warping window
    
    int calcul::dtw_wpassStart(size_t row, int win, double coefficient)
    
    	return std::max(1, (int)(ceil((row - 1) * coefficient + 0.0000000001) - win));
    
    ///Calculates last cell included in the warping window.
    ///@param[in] row row
    ///@param[in] win warping window width
    ///@param[in] coefficient input time series length ratio
    ///@param[in] lenB length of the time series B
    ///@return index of last cell in warping window
    
    int calcul::dtw_wpassEnd(size_t row, int win, double coefficient, int lenB)
    
    	return std::min(lenB + 1, (int)(ceil(row * coefficient) + 1) + win);
    
    	//const size_t end = min(lenB + 1, (int)(ceil(i * lenB / (double)lenA) + 1) + w);
    
    ///Calculates if cell is included in the flexible warping pass.
    ///@param[in] row row
    ///@param[in] col column
    ///@param[in] past last cell which was included
    ///@param[in] w flexible warping pass width
    ///@return TRUE if cell is in the flexible pass
    ///@return FALSE if cell is not in the flexible pass
    
    bool calcul::dtw_isFlexiblePass(int row, int col, coord const &past, int w)
    
    	return std::abs((past.row - row) - (past.col - col)) < w;
    
    ///Calculates mean value of the input vector.
    ///@param[in] v vector of doubles
    ///@return mean
    
    double calcul::vtr_mean(vtr<double> const &v)
    {
    	double sum = 0;
    
    ///Calculates vector of means of the 2d input vector.
    ///@param[in] series two dimensional vector
    ///@return vector of means
    
    vtr<double> calcul::vtr_mean(vtr2<double> const &series)
    {
    	vtr<double> average(series.size());
    
    	for (size_t i = 0; i < series.size(); i++)
    
    		average[i] = vtr_mean(series[i]);
    
    ///Calculates standard deviation of the input vector.
    ///@param[in] v vector
    ///@return standard deviation
    
    double calcul::vtr_std(vtr<double> const &v)
    {
    	double mean = vtr_mean(v);
    
    	double sum = 0;
    	for (auto &i : v)
    
    		sum += pow(i - mean, 2);
    
    
    	return sqrt(sum / v.size());
    
    ///Finds maximal value contained in the input vector.
    ///@tparam data type of searched vector
    ///@param[in] input vector
    
    ///@return maximal value
    
    template <typename T>
    T calcul::vtr_max(vtr<T> const &input)
    {
    
    	T max = (T)constant::MIN_double;
    
    template int calcul::vtr_max(vtr<int> const &input);
    
    template double calcul::vtr_max<double>(vtr<double> const &input);
    
    
    ///Finds maximal value contained in the 2d input vector.
    ///@tparam data type of searched vector
    ///@param[in] input vector
    ///@return maximal value
    
    template <typename T>
    T calcul::vtr_max(vtr2<T> const &input)
    {
    	double max = constant::MIN_double;
    
    	for (auto &&i : input)
    
    
    	return max;
    }
    template double calcul::vtr_max<double>(vtr2<double> const &input);
    
    
    ///Finds maximal value contained in the 3d input vector.
    ///@param[in] input vector
    ///@return maximal value
    
    template <typename T>
    T calcul::vtr_max(vtr3<T> const &input)
    {
    	double max = constant::MIN_double;
    
    
    	for (auto const &i : input) 
    	{
    
    		auto tmp = vtr_findMax(i);
    
    		if (tmp > max)
    			max = tmp;
    	}
    
    	return max;
    }
    
    
    ///Finds minimal value contained in the input vector.
    ///@param[in] input vector
    ///@return minimal value
    
    template <typename T>
    T calcul::vtr_min(vtr<T> const &input)
    {
    	T min = (T)constant::MAX_double;
    
    	for (auto &i : input)
    
    
    	return min;
    }
    template double calcul::vtr_min<double>(vtr<double> const &input);
    
    
    ///Finds minimal value contained in the input vector.
    ///@param[in] input vector
    ///@return minimal value
    
    template <typename T>
    T calcul::vtr_min(vtr2<T> const &input)
    {
    	double min = constant::MAX_double;
    
    
    	for (auto const &i : input) 
    	{
    
    template double calcul::vtr_min<double>(vtr2<double> const &input);