5 #include <unordered_map>
25 return static_cast<bool>(std::ifstream(fileName));
33 int value = n * (n - 1) / 2;
34 return value > 0 ? value : 0;
52 return std::accumulate(v.begin(), v.end(), 0.0);
61 std::cout << x <<
", ";
62 std::cout << std::endl;
73 for (
const std::vector<double> &v : mat)
85 std::map<int, int> frequencyMap;
87 for(
const int &val : vec)
99 for (
auto it = frequencyMap.begin(); it != frequencyMap.end();) {
100 if (it->second < threshold)
101 it = frequencyMap.erase(it);
107 std::map<int, int>(frequencyMap).swap(frequencyMap);
112 template <
typename T>
116 std::cerr <<
"\n\nWARNING: Empty Vector! Size is Zero (0).\n\n";
117 return std::adjacent_find(vec.begin(), vec.end(), [](
const T& a,
const T& b) { return a != b; }) == vec.end();
124 std::unordered_map<int, int> freq;
127 for (
int num : vec) {
132 int majorityElement = vec[0];
134 for (
const auto& pair : freq) {
135 if (pair.second > maxCount) {
136 maxCount = pair.second;
137 majorityElement = pair.first;
141 return majorityElement;
153 for (
int num : vec) {
154 if (num != majorityElement) {
166 std::vector<double> stdVec(vec.GetNrows());
167 for (
int i = 0; i < vec.GetNrows(); ++i) {
176 const std::vector<double>& vec2,
179 if (vec1.size() != vec2.size())
182 for (
size_t i = 0; i < vec1.size(); ++i)
184 if (std::abs(vec1[i] - vec2[i]) > tol)
Definition: Utilities.h:18
int CalculatePairs(int n)
Definition: Utilities.h:30
bool does_file_exist(const char *fileName)
Definition: Utilities.h:20
Definition: Utilities.h:42
bool AreVectorsEqual(const std::vector< double > &vec1, const std::vector< double > &vec2, double tol=1e-4)
Definition: Utilities.h:175
bool areAllElementsEqual(const std::vector< T > &vec)
Definition: Utilities.h:113
std::vector< double > TVectorDToStdVector(const TVectorD &vec)
Definition: Utilities.h:164
void filterAndShrinkMap(std::map< int, int > &frequencyMap, int threshold=2)
Definition: Utilities.h:97
int getMajorityElement(const std::vector< int > &vec)
Definition: Utilities.h:122
std::map< int, int > GetUniqueElementsAndFrequency(const std::vector< int > &vec)
Definition: Utilities.h:83
void printVectorOfVectors(std::vector< std::vector< double >> const &mat)
Definition: Utilities.h:67
void printVector(const std::vector< T > &v)
Definition: Utilities.h:58
int countDifferentFromMajority(const std::vector< int > &vec)
Definition: Utilities.h:146
double sumVector(const std::vector< double > &v)
Definition: Utilities.h:44