-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a bunch of new functionalities.
- Loading branch information
Showing
24 changed files
with
879 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: arithmetic_mean.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 2018-06-13 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_MEAN_H | ||
#define EASYDSP_STATISTICAL_MEAN_H | ||
|
||
#include <boost/accumulators/accumulators.hpp> | ||
#include <boost/accumulators/statistics.hpp> | ||
#include <numeric> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type mean(InputIterator first, InputIterator last) { | ||
using namespace boost::accumulators; | ||
accumulator_set<value_type, features<tag::mean>> acc; | ||
acc = std::for_each(first, last, acc); | ||
return boost::accumulators::mean(acc); | ||
} | ||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_MEAN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: centroid.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 17/6/2018 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_CENTROID_HPP | ||
#define EASYDSP_STATISTICAL_CENTROID_HPP | ||
|
||
#include <iterator> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type centroid(InputIterator first, InputIterator last) { | ||
value_type weighted_sum = static_cast<value_type>(0); | ||
value_type unweighted_sum = static_cast<value_type>(0); | ||
for (value_type i = 0; first != last; ++first, ++i) { | ||
weighted_sum += i * (*first); | ||
unweighted_sum += *first; | ||
} | ||
return weighted_sum / unweighted_sum; | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_CENTROID_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: crest.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 14/6/2018 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_CREST_HPP | ||
#define EASYDSP_STATISTICAL_CREST_HPP | ||
|
||
#include "arithmetic_mean.hpp" | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
|
||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type crest(InputIterator first, InputIterator last) { | ||
const value_type computed_mean = mean(first, last); | ||
const value_type computed_max = *std::max_element(first, last); | ||
return computed_max / computed_mean; | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_CREST_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: decrease.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 17/6/2018 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_DECREASE_HPP | ||
#define EASYDSP_STATISTICAL_DECREASE_HPP | ||
|
||
#include <iterator> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type decrease(InputIterator first, InputIterator last) { | ||
const auto size = std::distance(first, last); | ||
value_type weighted_sum = static_cast<value_type>(0); | ||
value_type unweighted_sum = static_cast<value_type>(0); | ||
for (value_type i = 0, initial = *first; first != last; ++first, ++i) { | ||
weighted_sum += (1 / i) * ((*first) - initial); | ||
unweighted_sum += *first; | ||
} | ||
return weighted_sum / unweighted_sum; | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_DECREASE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: entropy.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 17/6/2018 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_ENTROPY_HPP | ||
#define EASYDSP_STATISTICAL_ENTROPY_HPP | ||
|
||
#include <cmath> | ||
#include <numeric> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type entropy(InputIterator first, InputIterator last) { | ||
const auto sum = std::accumulate(first, last, static_cast<value_type>(0)); | ||
const auto predicate = [sum](const value_type accumulated, const value_type current) { | ||
const auto normalized = current / sum; | ||
return (accumulated + std::log2(normalized) * normalized); | ||
}; | ||
return std::accumulate(first, last, static_cast<value_type>(0), predicate); | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_ENTROPY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: flatness.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 14/6/2018 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_FLATNESS_H | ||
#define EASYDSP_STATISTICAL_FLATNESS_H | ||
|
||
#include "arithmetic_mean.hpp" | ||
#include "geometric_mean.hpp" | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
|
||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type flatness(InputIterator first, InputIterator last) { | ||
const value_type computed_gmean = geometric_mean(first, last); | ||
const value_type computed_mean = mean(first, last); | ||
return geometric_mean / computed_mean; | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_FLATNESS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: flux.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 17/6/2018 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_FLUX_HPP | ||
#define EASYDSP_STATISTICAL_FLUX_HPP | ||
|
||
#include <type_traits> | ||
#include <iterator> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
|
||
enum FluxType { ManhattanDistance, EuclideanDistance, Logarithmic }; | ||
|
||
template <FluxType Type> | ||
struct Flux { | ||
template <typename InputIterator, | ||
typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type operator()(InputIterator first, InputIterator last, InputIterator first_other) const { | ||
const auto size = std::distance(first, last); | ||
if constexpr (std::is_same_v<Type, FluxType::ManhattanDistance>) { | ||
value_type accumulated = static_cast<value_type>(0); | ||
for (; first != last; ++first, ++first_other) { | ||
accumulated += meta::manhattan_distance(*first, *first_other); | ||
} | ||
return std::sqrt(accumulated) / static_cast<value_type>(size); | ||
|
||
} else if constexpr (std::is_same_v<Type, FluxType::EuclideanDistance>) { | ||
value_type accumulated = static_cast<value_type>(0); | ||
for (; first != last; ++first, ++first_other) { | ||
accumulated += meta::euclidean_distance(*first, *first_other); | ||
} | ||
return accumulated / static_cast<value_type>(size); | ||
} else if constexpr (std::is_same_v<Type, FluxType::Logarithmic>) { | ||
value_type accumulated = static_cast<value_type>(0); | ||
for (; first != last; ++first, ++first_other) { | ||
accumulated += std::log(std::abs(*first) / std::abs(*first_other)); | ||
} | ||
return accumulated / static_cast<value_type>(size); | ||
} | ||
} | ||
}; | ||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_FLUX_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: generalized_mean.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 2018-06-13 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_GENERALIZED_MEAN_H | ||
#define EASYDSP_STATISTICAL_GENERALIZED_MEAN_H | ||
|
||
#include <numeric> | ||
#include <cmath> | ||
#include <iterator> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
|
||
template <typename InputIterator, typename Integer, | ||
typename value_type = typename std::iterator_traits<InputIterator>::value_type, | ||
typename = typename std::enable_if<std::is_integral<Integer>::value>::type> | ||
inline value_type generalized_mean(InputIterator first, InputIterator last, Integer beta) { | ||
const auto predicate = [beta](const value_type prev, const value_type current) { | ||
return static_cast<value_type>(prev + std::pow(current, beta)); | ||
}; | ||
const value_type accumulated = std::accumulate(first, last, value_type(), predicate); | ||
const value_type temp = accumulated / static_cast<value_type>(std::distance(first, last)); | ||
return static_cast<value_type>(std::pow(temp, 1 / static_cast<value_type>(beta))); | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_GENERALIZED_MEAN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: geometric_mean.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 2018-06-13 | ||
*/ | ||
#ifndef EASYDSP_STATISTICAL_GEOMETRIC_MEAN_H | ||
#define EASYDSP_STATISTICAL_GEOMETRIC_MEAN_H | ||
|
||
#include <numeric> | ||
#include <cmath> | ||
#include <iterator> | ||
|
||
namespace easy { namespace dsp { namespace statistics { | ||
|
||
template <typename InputIterator, typename value_type = typename std::iterator_traits<InputIterator>::value_type> | ||
inline value_type geometric_mean(InputIterator first, InputIterator last) { | ||
const value_type accumulated = std::accumulate(first, last, value_type(), std::multiplies<value_type>()); | ||
return static_cast<value_type>(std::pow(accumulated, 1 / static_cast<value_type>(std::distance(first, last)))); | ||
} | ||
|
||
}}} // namespace easy::feature::statistical | ||
|
||
#endif // EASYDSP_STATISTICAL_GEOMETRIC_MEAN_H |
Oops, something went wrong.