-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#381: CLIQUE integration between C++ and Python.
- Loading branch information
Showing
10 changed files
with
364 additions
and
11 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
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,62 @@ | ||
/** | ||
* | ||
* @authors Andrei Novikov ([email protected]) | ||
* @date 2014-2019 | ||
* @copyright GNU Public License | ||
* | ||
* GNU_PUBLIC_LICENSE | ||
* pyclustering 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. | ||
* | ||
* pyclustering 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/>. | ||
* | ||
*/ | ||
|
||
#include "interface/clique_interface.h" | ||
|
||
#include "cluster/clique.hpp" | ||
|
||
|
||
pyclustering_package * clique_algorithm(const pyclustering_package * const p_sample, const std::size_t p_intervals, const std::size_t p_threshold) { | ||
dataset input_dataset; | ||
p_sample->extract(input_dataset); | ||
|
||
ccore::clst::clique solver(p_intervals, p_threshold); | ||
|
||
ccore::clst::clique_data output_result; | ||
|
||
solver.process(input_dataset, output_result); | ||
|
||
pyclustering_package * package = create_package_container(CLIQUE_PACKAGE_SIZE); | ||
|
||
((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_CLUSTERS] = create_package(&output_result.clusters()); | ||
((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_NOISE] = create_package(&output_result.noise()); | ||
|
||
const auto & blocks = output_result.blocks(); | ||
((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_LOGICAL_LOCATION] = create_package_container(blocks.size()); | ||
((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_MAX_CORNER] = create_package_container(blocks.size()); | ||
((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_MIN_CORNER] = create_package_container(blocks.size()); | ||
((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_BLOCK_POINTS] = create_package_container(blocks.size()); | ||
|
||
pyclustering_package * logical_location = ((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_LOGICAL_LOCATION]; | ||
pyclustering_package * max_corner = ((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_MAX_CORNER]; | ||
pyclustering_package * min_corner = ((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_MIN_CORNER]; | ||
pyclustering_package * block_points = ((pyclustering_package **) package->data)[CLIQUE_PACKAGE_INDEX_BLOCK_POINTS]; | ||
|
||
for (std::size_t i = 0; i < blocks.size(); i++) { | ||
((pyclustering_package **) logical_location->data)[i] = create_package(&(blocks[i].get_logical_location())); | ||
((pyclustering_package **) max_corner->data)[i] = create_package(&(blocks[i].get_spatial_block().get_max_corner())); | ||
((pyclustering_package **) min_corner->data)[i] = create_package(&(blocks[i].get_spatial_block().get_min_corner())); | ||
((pyclustering_package **) block_points->data)[i] = create_package(&(blocks[i].get_points())); | ||
} | ||
|
||
return package; | ||
} |
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 @@ | ||
/** | ||
* | ||
* @authors Andrei Novikov ([email protected]) | ||
* @date 2014-2019 | ||
* @copyright GNU Public License | ||
* | ||
* GNU_PUBLIC_LICENSE | ||
* pyclustering 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. | ||
* | ||
* pyclustering 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/>. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
|
||
#include "interface/pyclustering_package.hpp" | ||
|
||
#include "definitions.hpp" | ||
|
||
|
||
/** | ||
* | ||
* @brief CLIQUE result is returned by pyclustering_package that consist sub-packages and this enumerator provides | ||
* named indexes for sub-packages. | ||
* | ||
*/ | ||
enum clique_package_indexer { | ||
CLIQUE_PACKAGE_INDEX_CLUSTERS = 0, | ||
CLIQUE_PACKAGE_INDEX_NOISE, | ||
CLIQUE_PACKAGE_INDEX_LOGICAL_LOCATION, | ||
CLIQUE_PACKAGE_INDEX_MAX_CORNER, | ||
CLIQUE_PACKAGE_INDEX_MIN_CORNER, | ||
CLIQUE_PACKAGE_INDEX_BLOCK_POINTS, | ||
CLIQUE_PACKAGE_SIZE | ||
}; | ||
|
||
|
||
/** | ||
* | ||
* @brief Clustering algorithm CLIQUE returns allocated clusters. | ||
* @details Caller should destroy returned clustering data using 'cure_data_destroy' when | ||
* it is not required anymore. | ||
* | ||
* @param[in] p_sample: input data for clustering. | ||
* @param[in] p_intervals: amount of intervals in each dimension. | ||
* @param[in] p_threshold: minimum number of objects that should be contained by non-noise block. | ||
* | ||
* @return Returns pointer to cure data - clustering result that can be used for obtaining | ||
* allocated clusters, representative points and means of each cluster. | ||
* | ||
*/ | ||
extern "C" DECLARATION pyclustering_package * clique_algorithm(const pyclustering_package * const p_sample, const std::size_t p_intervals, const std::size_t p_threshold); |
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
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 @@ | ||
/** | ||
* | ||
* @authors Andrei Novikov ([email protected]) | ||
* @date 2014-2019 | ||
* @copyright GNU Public License | ||
* | ||
* GNU_PUBLIC_LICENSE | ||
* pyclustering 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. | ||
* | ||
* pyclustering 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/>. | ||
* | ||
*/ | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include "interface/clique_interface.h" | ||
#include "interface/pyclustering_package.hpp" | ||
|
||
#include "utenv_utils.hpp" | ||
|
||
#include <memory> | ||
|
||
|
||
TEST(utest_interface_clique, clique_algorithm) { | ||
std::shared_ptr<pyclustering_package> sample = pack(dataset({ { 1.0, 1.0 }, { 1.1, 1.0 }, { 1.2, 1.4 }, { 10.0, 10.3 }, { 10.1, 10.2 }, { 10.2, 10.4 } })); | ||
|
||
pyclustering_package * result = clique_algorithm(sample.get(), 2, 0); | ||
ASSERT_EQ((std::size_t) CLIQUE_PACKAGE_SIZE, result->size); | ||
|
||
delete result; | ||
} |
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
Oops, something went wrong.