如何为 mlpack 的 kmeans 构建 HamerlyKmeans 对象
How to constuct the HamerlyKmeans object for mlpack's kmeans
我是 mlpack 的新手,使用的是 3.3.1。我想做一些 KMean 聚类。我可以很好地使用 naiveKMeans 类,但我想使用另一种方法,例如 HamelyKMeans 类。
从手册来看,我似乎需要构造我自己的该类的本地对象来传递它,而不是这行代码中的 NaiveKMeans:
KMeans<mlpack::metric::EuclideanDistance, kmeans::SampleInitialization,
kmeans::MaxVarianceNewCluster, kmeans::NaiveKMeans, arma::mat> km =KMeans(0);
但是当我尝试按如下方式构造它时,我收到一个编译器错误:
// for StackOverflow
#include <mlpack/prereqs.hpp>
#include <mlpack/core.hpp>
#include <mlpack/core/util/cli.hpp>
#include <mlpack/methods/kmeans/kmeans.hpp>
#include <mlpack/methods/kmeans/allow_empty_clusters.hpp>
#include <mlpack/methods/kmeans/kill_empty_clusters.hpp>
#include <mlpack/methods/kmeans/refined_start.hpp>
#include <mlpack/methods/kmeans/elkan_kmeans.hpp>
#include <mlpack/methods/kmeans/hamerly_kmeans.hpp>
#include <mlpack/methods/kmeans/pelleg_moore_kmeans.hpp>
#include <mlpack/methods/kmeans/dual_tree_kmeans.hpp>
using namespace mlpack;
using namespace mlpack::kmeans;
using namespace mlpack::metric;
using namespace mlpack::util;
int main(int argc, char **argv) {
arma::mat in_data(10,10);
for ( int i=0; i < 10; i++ ) {
for ( int j=0; j < 10; j++ ) {
in_data(j,i)=i+j;
}
}
kmeans::HamerlyKMeans< metric::EuclideanDistance, arma::mat>
ek = kmeans::HamerlyKMeans(in_data,EuclideanDistance());
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// HamerlyKMeans to be used instead of NaiveKMeans below
KMeans<mlpack::metric::EuclideanDistance, kmeans::SampleInitialization,
kmeans::MaxVarianceNewCluster, kmeans::NaiveKMeans, arma::mat> km =KMeans(0);
arma::Row<size_t> assignments; // Cluster assignments.
arma::mat centroids; // Cluster centroids.
km.Cluster(in_data,5,assignments, centroids); // 5 clusters.
}
编译器错误消息为:
错误:没有可行的构造函数或推导指南来推导"HamerlyKMeans"的模板参数 [build] kmeans::HamerlyKMeans<metric::EuclideanDistance,> ek = kmeans::HamerlyKMeans(in_data,EuclideanDistance(((; [构建] ^
[build]/usr/include/mlpack/methods/kmeans/hamerly_kmeans.hpp:26:3:注意:候选函数 [使用 MetricType = mlpack::metric::LMetric<2,true>,MatType = arma::Mat] 不可行:期望第二个参数的 l 值
[build] HamerlyKMeans(const MatType&dataset, MetricType&metric(; [构建] ^ [build]/usr/include/mlpack/methods/kmeans/hamerly_kmeans.hpp:19:7:注意:候选函数模板不可行:需要 1 个参数,但提供了 2 个参数 [构建]类哈默利克曼斯 [构建] ^
但是当我查看hamerly_kmeans.hpp时,我看到:
template<typename MetricType, typename MatType>
class HamerlyKMeans
{
public:
/**
* Construct the HamerlyKMeans object, which must store several sets of
* bounds.
*/
HamerlyKMeans(const MatType& dataset, MetricType& metric);
我倒是很不知所措。我根本不了解类的模板。想法?
我已经想通了。我将HamerlyKMeans类的构造更改为此
metric::EuclideanDistance euclid_distance;
kmeans::HamerlyKMeans< metric::EuclideanDistance, arma::mat> ek =
kmeans::HamerlyKMeans(in_data,euclid_distance);
我对此的最好理解是编译器告诉我,第二个参数告诉我 metric::EuclidDistance(( 不构造 l 值(我认为它是一个变量,但上述更改创建了变量euclid_distance这是一个 l 值。上面的更改编译和链接很好。
- C++为构建时间获取QDateTime的可靠方法
- 无法在 CLion 中构建 C++ 项目
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用ndk-build.cmd构建Android.so文件
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 无法使用Qt Creator在Windows中构建yaml-cpp
- 构建一个由C和C++文件组成的库
- llvm构建器向基本块添加终止符
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- 如何跨平台将二进制资源构建到程序中?
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- 如何解决 Ninja c++ 构建和执行问题
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 用CMake构建C++协议
- 如何为 mlpack 的 kmeans 构建 HamerlyKmeans 对象