我是mlpack和使用3.3.1的新手。我想做一些KMeans集群。我可以很好地使用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‘生成kmeans::HamerlyKMeans<度量的模板参数::EuclideanDistance,arma::mat> 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 /usr/include/mlpack/methods/kmeans/hamerly_kmeans.hpp:19:7:(const MatType& dataset,MetricType& HamerlyKMeans );build ^ build /usr/include/mlpack/methods/kmeans/hamerly_kmeans.hpp:19:7:注意:候选函数模板不可行:需要1个参数,但提供了2个build HamerlyKMeans HamerlyKMeans Build^
但是当我查看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);我已经相当混乱了。我一点也不理解类的模板。想法?
发布于 2020-06-09 22:17:56
我已经想通了。我将HamerlyKMeans类的结构更改为
metric::EuclideanDistance euclid_distance;
kmeans::HamerlyKMeans< metric::EuclideanDistance, arma::mat> ek =
kmeans::HamerlyKMeans(in_data,euclid_distance);我最好的理解是编译器告诉我第二个参数告诉我指标::EuclidDistance()不构造l值(我认为它是一个变量,但上面的更改创建了变量euclid_distance,它是一个l值。上面的更改编译和链接都很好。
https://stackoverflow.com/questions/62274801
复制相似问题