Beispiel #1
0
	void run() {
		// Do some validation of the arguments
		if (graph.rows() != graph.cols()) {
			throw std::invalid_argument("Matrix must be square");
		}
		if (graph.any_element_is_inf_or_nan()) {
			throw std::invalid_argument("Matrix includes Inf or NaN values");
		}
		if (graph.any_element_is_negative()) {
			throw std::invalid_argument("Matrix includes negative values");
		}
		if (!is_symmetric(graph)) {
			throw std::invalid_argument("Matrix must be symmetric");
		}
		if (!clustering.empty() && (int)clustering.size() != graph.rows()) {
			throw std::invalid_argument("Initial value must have same size as the matrix");
		}
		
		// initialize Clustering object
		params.lossfun = lossfun.get();
		srand(seed);
		Clustering clus(graph,params);
		if (!clustering.empty()) {
			clus.set_clustering(clustering);
		}
		
		// perform clustering
		if (optimize) {
			clus.optimize();
		}
		
		// outputs
		clustering = clus.get_clustering();
		loss = clus.get_loss();
		num_clusters = clus.num_clusters();
	}