forked from themisvr/Vector-Clustering-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
Binary file not shown.
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,77 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <algorithm> | ||
#include <random> | ||
#include <cmath> | ||
|
||
#include "../math_utils/math_utils.h" | ||
|
||
|
||
namespace hash { | ||
|
||
template <typename T> | ||
class HashFunction { | ||
|
||
/* | ||
params: | ||
*/ | ||
private: | ||
const uint16_t d; | ||
const uint32_t m; | ||
const uint32_t M; | ||
const double w; | ||
std::vector<double> s_transformations; | ||
std::vector<double> a; | ||
|
||
public: | ||
|
||
HashFunction( const uint16_t &d, const uint32_t &m, const uint32_t &M, | ||
const uint32_t &w) : d(d), m(m), M(M), w(w), s_transformations(d), a(d) { | ||
|
||
std::default_random_engine generator; | ||
std::uniform_real_distribution<double> distribution(0.0, w); | ||
|
||
for (size_t i = 0; i != d; ++i) { | ||
s_transformations[i] = distribution(generator); | ||
} | ||
} | ||
|
||
~HashFunction() = default; | ||
|
||
uint32_t hf_construction(std::vector<double> &pixels) { | ||
uint32_t hash_value = 0; | ||
|
||
for (size_t i = 0; i != d; ++i) { | ||
a[i] = floor((pixels[i] - s[i]) / w) | ||
} | ||
|
||
std::reverse(a.begin(), a.end()); | ||
|
||
for (size_t i = 0; i != d; ++i) { | ||
hash_value += (math_utils::modulo(a[i], i) * math_utils::exp_modulo(m, i, M)) % M; | ||
} | ||
|
||
return hash_value % M; | ||
} | ||
|
||
}; | ||
|
||
|
||
template <typename T> | ||
class AmplifiedFunction { | ||
|
||
private: | ||
|
||
|
||
|
||
|
||
public: | ||
|
||
|
||
|
||
}; | ||
|
||
|
||
} |
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,26 @@ | ||
#pragma once | ||
|
||
|
||
|
||
namespace math_utils { | ||
|
||
inline uint32_t exp_modulo(uint32_t base, uint16_t exp, uint32_t mod) { | ||
uint32_t res = 1; | ||
|
||
base %= mod; | ||
if (base == 0) return 0; | ||
|
||
while (exp > 0) { | ||
if (exp & 1) { res = (res * base) % mod; } | ||
exp >>= 1; | ||
base = (base * base) % mod; | ||
} | ||
return res; | ||
} | ||
|
||
inline uint32_t modulo(int i, uint32_t n) { | ||
return ((i % n) + n) % n; | ||
} | ||
|
||
|
||
} |
Empty file.
Empty file.