forked from metric-space-ai/metric
-
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.
Merge remote-tracking branch 'origin/master' into issue_35
- Loading branch information
Showing
40 changed files
with
2,873 additions
and
230 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
62 changes: 62 additions & 0 deletions
62
examples/distance_examples/cramervon_mises_distance_example.cpp
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 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
Copyright (c) 2019 Panda Team | ||
*/ | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <chrono> | ||
#include "../../modules/distance.hpp" | ||
#include "assets/test_data.cpp" | ||
|
||
|
||
int main() | ||
{ | ||
/******************** examples for Cramer-von Nises Distance **************************/ | ||
// example for picture | ||
std::cout << "Cramer-von Nises distance example have started" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
/*** here are some data records ***/ | ||
std::vector<double> samples_1 = { 0, 1, 2, 3, 3, 2, 1, 0, 2, 2 }; | ||
std::vector<double> samples_2 = { 0, 0, 2, 3, 3, 2, 1, 0, 2, 2 }; | ||
|
||
metric::CramervonNises<std::vector<double>, double> distance_1; | ||
|
||
auto t1 = std::chrono::steady_clock::now(); | ||
auto result = distance_1(samples_1, samples_2); | ||
auto t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
// | ||
|
||
metric::CramervonNises<std::vector<double>, double> distance_2(0.0001); | ||
|
||
t1 = std::chrono::steady_clock::now(); | ||
result = distance_2(samples_1, samples_2); | ||
t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
// | ||
|
||
metric::CramervonNises<std::vector<double>, double> distance_3(0.1); | ||
|
||
t1 = std::chrono::steady_clock::now(); | ||
result = distance_3(samples_1, samples_2); | ||
t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
return 0; | ||
} |
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
40 changes: 40 additions & 0 deletions
40
examples/distance_examples/kolmogorov_smirnov_distance_example.cpp
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,40 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
Copyright (c) 2019 Panda Team | ||
*/ | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <chrono> | ||
#include "../../modules/distance.hpp" | ||
#include "assets/test_data.cpp" | ||
|
||
|
||
int main() | ||
{ | ||
/******************** examples for Kolmogorov-Smirnov Distance **************************/ | ||
// example for picture | ||
std::cout << "Kolmogorov-Smirnov distance example have started" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
/*** here are some data records ***/ | ||
std::vector<double> samples_1 = { 0, 1, 2, 3, 3, 2, 1, 0, 2, 2 }; | ||
std::vector<double> samples_2 = { 0, 0, 2, 3, 3, 2, 1, 0, 2, 2 }; | ||
//std::vector<double> samples_1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | ||
//std::vector<double> samples_2 = { 1, 2, 3, 4, 5 }; | ||
// | ||
metric::KolmogorovSmirnov<std::vector<double>, double> distance; | ||
|
||
auto t1 = std::chrono::steady_clock::now(); | ||
auto result1 = distance(samples_1, samples_2); | ||
auto t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result1 | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
return 0; | ||
} |
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,76 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
Copyright (c) 2019 Panda Team | ||
*/ | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <chrono> | ||
#include "../../modules/distance.hpp" | ||
#include "assets/test_data.cpp" | ||
|
||
|
||
int main() | ||
{ | ||
/******************** examples for Earth Mover’s Distance **************************/ | ||
// example for picture | ||
std::cout << "Earth Mover's distance example have started" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
/*** here are some data records ***/ | ||
std::vector<double> samples_1 = { 0, 1, 2, 3, 3, 2, 1, 0, 2, 2 }; | ||
std::vector<double> samples_2 = { 0, 0, 2, 3, 3, 2, 1, 0, 2, 2 }; | ||
|
||
metric::RandomEMD<std::vector<double>, double> distance_1; | ||
|
||
|
||
// | ||
// typedef int emd_Type; | ||
|
||
// auto cost_mat = metric::EMD_details::ground_distance_matrix_of_2dgrid<emd_Type>(3, 3); | ||
// auto maxCost = metric::EMD_details::max_in_distance_matrix(cost_mat); | ||
|
||
// metric::EMD<emd_Type> distance_orig(cost_mat, maxCost); | ||
|
||
//print_matrix(cost_mat); | ||
|
||
|
||
|
||
|
||
auto t1 = std::chrono::steady_clock::now(); | ||
auto result = distance_1(samples_1, samples_2); | ||
auto t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
// | ||
|
||
metric::RandomEMD<std::vector<double>, double> distance_2(0.0001); | ||
|
||
t1 = std::chrono::steady_clock::now(); | ||
result = distance_2(samples_1, samples_2); | ||
t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
// | ||
|
||
metric::RandomEMD<std::vector<double>, double> distance_3(0.1); | ||
|
||
t1 = std::chrono::steady_clock::now(); | ||
result = distance_3(samples_1, samples_2); | ||
t2 = std::chrono::steady_clock::now(); | ||
std::cout << "result: " << result | ||
<< " (Time = " << double(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count()) / 1000000 | ||
<< " s)" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
return 0; | ||
} |
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
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,102 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
Copyright (c) 2019 Panda Team | ||
*/ | ||
|
||
#include <iostream> | ||
#include "../../modules/utils/graph.hpp" | ||
#include "../../modules/distance.hpp" | ||
|
||
|
||
int main() | ||
{ | ||
std::cout << "Graph space example have started" << std::endl; | ||
std::cout << "" << std::endl; | ||
|
||
size_t neighbors_num = 3; | ||
|
||
std::vector<std::vector<double>> table = { | ||
{ 0, 1 }, | ||
{ 1, 1 }, | ||
{ 2, 2 }, | ||
{ 3, 3 }, | ||
{ 4, 3 }, | ||
{ 5, 3 }, | ||
{ 4, 6 }, | ||
{ 5, 1 }, | ||
{ 4, 1 }, | ||
{ 3, 2 }, | ||
{ 0, 3 }, | ||
{ 1, 3 }, | ||
{ 2, 3 }, | ||
{ 6, 6 }, | ||
{ 0, 2 }, | ||
{ 0, 9 }, | ||
{ 0, 4 }, | ||
{ 0, 5 }, | ||
{ 0, 6 }, | ||
{ 0, 7 }, | ||
{ 0, 8 }, | ||
}; | ||
|
||
auto g = metric::KNNGraph<std::vector<double>, metric::Euclidian<double>>(table, neighbors_num, 2.5 * neighbors_num); | ||
|
||
std::cout << "graph:" << std::endl; | ||
std::cout << g.get_matrix() << std::endl; | ||
|
||
// | ||
|
||
std::vector<double> query = { 7, 5 }; | ||
|
||
std::cout << std::endl; | ||
std::cout << "gnn search:" << std::endl; | ||
auto found = g.gnnn_search(query, 3); | ||
|
||
for (size_t i = 0; i < found.size(); i++) | ||
{ | ||
std::cout << found[i] << " -> "; | ||
print_vector(g.get_node_data(found[i])); | ||
std::cout << std::endl; | ||
} | ||
std::cout << std::endl; | ||
|
||
// | ||
|
||
auto other_g = metric::KNNGraph(g); | ||
|
||
std::cout << "other graph:" << std::endl; | ||
std::cout << "gnn search:" << std::endl; | ||
found = other_g.gnnn_search(query, 3); | ||
|
||
for (size_t i = 0; i < found.size(); i++) | ||
{ | ||
std::cout << found[i] << " -> "; | ||
print_vector(other_g.get_node_data(found[i])); | ||
std::cout << std::endl; | ||
} | ||
std::cout << std::endl; | ||
|
||
// | ||
|
||
// metric::Tree<std::vector<double>, metric::Euclidian<double>> tree(table); | ||
// | ||
// auto graph_from_tree = metric::KNNGraph(tree, neighbors_num, 2.5 * neighbors_num); | ||
// | ||
// std::cout << "tree graph:" << std::endl; | ||
// std::cout << "gnn search:" << std::endl; | ||
//found = graph_from_tree.gnnn_search(query, 3); | ||
// | ||
//for (size_t i = 0; i < found.size(); i++) | ||
//{ | ||
// std::cout << found[i] << " -> "; | ||
// print_vector(graph_from_tree.get_node_data(found[i])); | ||
// std::cout << std::endl; | ||
//} | ||
// std::cout << std::endl; | ||
|
||
|
||
return 0; | ||
} |
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 |
---|---|---|
|
@@ -42,6 +42,9 @@ int main() | |
|
||
cTree.print(); | ||
|
||
std::cout << std::endl; | ||
std::cout << std::endl; | ||
|
||
// | ||
|
||
/*** batch insert ***/ | ||
|
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
Oops, something went wrong.