void DataTable::UpdateDefaultPartition() { oid_t column_count = GetSchema()->GetColumnCount(); // TODO: Number of clusters and new sample weight oid_t cluster_count = 4; double new_sample_weight = 0.01; brain::Clusterer clusterer(cluster_count, column_count, new_sample_weight); // Process all samples { std::lock_guard<std::mutex> lock(clustering_mutex_); // Check if we have any samples if (samples_.empty()) return; for (auto sample : samples_) { clusterer.ProcessSample(sample); } samples_.clear(); } // TODO: Max number of tiles default_partition_ = clusterer.GetPartitioning(2); }
void KMeansNormalizer::normalize(std::vector<double> *v) { Eigen::Map<Eigen::MatrixXd> mapToData((*v).data(), 1, (*v).size()); std::shared_ptr<ClusterXX::ClustererParameters> kMeansParams = std::make_shared<ClusterXX::KMeansParameters>(K, maxIterations); ClusterXX::Single_KMeans_Clusterer clusterer(mapToData, kMeansParams); clusterer.compute(); std::vector<int> clusters = clusterer.getClusters(); for (unsigned int i = 0; i < v->size(); ++i) { (*v)[i] = (double) clusters[i]; } }
void MultilevelLayouter::drawInternal(Graph& G, count level) { count n = G.numberOfNodes(); if (n <= N_THRSH) { // unrecursive part: call drawing routine METISGraphWriter gWriter; gWriter.write(G, true, "output/test-multi-coarsest.graph"); DEBUG("initial layout by FR, G's size: ", G.numberOfNodes()); FruchtermanReingold initLayouter(bottomLeft, topRight, false); initLayouter.draw(G); PostscriptWriter writer; writer.write(G, "output/test-multi-coarsest-FR.eps"); MaxentStress layouter(bottomLeft, topRight, true); layouter.draw(G); writer.write(G, "output/test-multi-coarsest-ME.eps"); } else { // compute clustering PLP clusterer(G); clusterer.run(); Partition clustering = clusterer.getPartition(); EdgeCut ec; INFO("Clustering: #clusters: ", clustering.numberOfSubsets(), "; cut: ", ec.getQuality(clustering, G)); // coarsen by clustering ParallelPartitionCoarsening contracter(G, clustering); contracter.run(); Graph Gcon = contracter.getCoarseGraph(); std::vector<node> mapping = contracter.getFineToCoarseNodeMapping(); // make recursive call drawInternal(Gcon, level + 1); // apply recursive solution to current graph G.initCoordinates(); G.forNodes([&](node v) { G.setCoordinate(v, Gcon.getCoordinate(mapping[v])); // TRACE("coordinate of ", v, ": ", G.getCoordinate(v, 0), " / ", G.getCoordinate(v, 1)); }); DEBUG("local refinement of graph of size ", n); // run drawing code on current graph FruchtermanReingold layouter(bottomLeft, topRight, true); //, 50 * (level + 1), 0.1); // TODO: externalize layouter.draw(G); } }
void MultiaryPoiMerger::apply(const OsmMapPtr& map, std::vector< std::pair<ElementId, ElementId> >& replaced) { // find the appropriate match creator for calculating scores between clusters std::vector< boost::shared_ptr<MatchCreator> > matchCreators = MatchFactory::getInstance(). getCreators(); foreach (boost::shared_ptr<MatchCreator> mc, matchCreators) { if (mc->isMatchCandidate(map->getElement(_pairs.begin()->first), map)) { if (_matchCreator.get()) { LOG_VARW(_matchCreator->getDescription()); LOG_VARW(mc->getDescription()); throw HootException("Expected only a single match creator to be a candidate for the given " "element. This method may need to be more restrictive, or you may need to reduce your " "list of match creators."); } _matchCreator = mc; } } // find the appropriate merger creator for merging elements in clusters foreach (const CreatorDescription& d, MergerFactory::getInstance().getAllAvailableCreators()) { // ugh. Magic string. To work around this we'll need to link against hoot-js, or find another // way to add that dep. if (d.className == "hoot::ScriptMergerCreator") { _mergerCreator.reset(Factory::getInstance().constructObject<MergerCreator>(d.className)); } } MultiaryScoreCachePtr score(new MultiaryScoreCache(map, _matchCreator)); MultiaryPoiMergeCachePtr merge(new MultiaryPoiMergeCache(map, _matchCreator, _mergerCreator)); MultiaryHierarchicalClusterAlgorithm clusterer(merge, score, _matchCreator->getMatchThreshold()->getMissThreshold()); MultiaryClusterAlgorithm::ClusterList clusters = clusterer.calculateClusters(map, _pairs); QList<MultiaryClusterAlgorithm::ClusterLinkPtr> reviews = clusterer.takeReviews(); _mergeClusters(map, replaced, clusters); _createReviews(map, reviews); }
Int_t IlcTARGETFindClustersV2(Int_t nev=5, Char_t SlowOrFast='s') { cerr<<"Looking for clusters...\n"; if (gIlc) { delete gIlc->GetRunLoader(); delete gIlc; gIlc=0; } IlcRunLoader *rl = IlcRunLoader::Open("gilc.root"); if (rl == 0x0) { cerr<<"IlcTARGETFindClustersV2.C : Can not open session RL=NULL"<< endl; return 1; } IlcTARGETLoader *itsl = (IlcTARGETLoader*)rl->GetLoader("TARGETLoader"); if (itsl == 0x0) { cerr<<"IlcTARGETFindClustersV2.C : can not get TARGET loader"<< endl; return 2; } rl->LoadKinematics(); Int_t retval = rl->LoadgIlc(); if (retval) { cerr<<"IlcTARGETFindClustersV2.C : LoadgIlc returned error"<< endl; delete rl; return 3; } gIlc=rl->GetIlcRun(); IlcTARGET *TARGET = (IlcTARGET*)gIlc->GetModule("TARGET"); if (!TARGET) { cerr<<"Can't find the TARGET !\n"; delete rl; return 3; } IlcTARGETgeom *geom=TARGET->GetTARGETgeom(); itsl->LoadRecPoints("recreate"); if (SlowOrFast=='s') itsl->LoadDigits("read"); else itsl->LoadHits("read"); if(SlowOrFast=='s'){ IlcTARGETclustererV2 clusterer(geom); TStopwatch timer; if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents(); for (Int_t i=0; i<nev; i++) { cerr<<"Processing event number: "<<i<<endl; rl->GetEvent(i); TTree *out=itsl->TreeR(); if (!out) { itsl->MakeTree("R"); out=itsl->TreeR(); } TTree *in=itsl->TreeD(); if (!in) { cerr<<"Can't get digits tree !\n"; return 4; } clusterer.Digits2Clusters(in,out); itsl->WriteRecPoints("OVERWRITE"); timer.Stop(); timer.Print(); } } else{ for(Int_t i=0;i<3;i++){ TARGET->SetSimulationModel(i,new IlcTARGETsimulationFastPoints()); } TStopwatch timer; for (Int_t i=0; i<nev; i++) { rl->GetEvent(i); if(itsl->TreeR()== 0x0) itsl->MakeTree("R"); TTree* in = (TTree*)itsl->TreeH(); TTree* out= (TTree*)itsl->TreeR(); timer.Start(); TARGET->Hits2Clusters(in,out); timer.Stop(); timer.Print(); itsl->WriteRecPoints("OVERWRITE"); } } delete rl; return 0; }