/// <summary> /// Generates an initial set of clusters /// </summary> /// <param name="decks">Collection of partial decks from which to generate cluster</param> /// <returns>List of clusters</returns> public List <Cluster> GenerateInitialClusters(List <PartialDeck> decks) { Trace.Log(""); Trace.Log("*** Detecting clusters ***"); var clusters = new List <Cluster>(); var remainingDecks = decks; while (true) { // Generate the next cluster var cluster = this.GenerateCluster(remainingDecks, decks.Count); // If we didn't find a cluster, we're done if (cluster == null) { break; } // Add the cluster to the list clusters.Add(cluster); // Filter out decks that match that cluster remainingDecks = remainingDecks.Where((deck) => MatchRate.Calculate(cluster, deck) < this.options.MinimumMatchRate).ToList(); } return(clusters); }
/// <summary> /// Filter decks to those that match at some minimum rate /// </summary> public List <DeckInfo> FilterByMatchRate(Cluster cluster, List <PartialDeck> decks) { var filteredDecks = new List <DeckInfo>(); foreach (var deck in decks) { double matchRate = MatchRate.Calculate(cluster, deck); if (matchRate >= this.options.MinimumMatchRate) { filteredDecks.Add( new DeckInfo { Deck = deck, MatchRate = matchRate }); } } return(filteredDecks); }
/// <summary> /// Match decks to clusters /// </summary> private Dictionary <Cluster, List <PartialDeck> > MatchDecksToClusters(List <Cluster> clusters, List <PartialDeck> decks) { var clusterGroups = new Dictionary <Cluster, List <PartialDeck> >(); foreach (PartialDeck deck in decks) { // Find the cluster the deck best matches Cluster bestCluster = null; double bestMatchRate = 0.0; foreach (Cluster cluster in clusters) { double matchRate = MatchRate.Calculate(cluster, deck); if (matchRate > bestMatchRate) { bestCluster = cluster; bestMatchRate = matchRate; } } // If it doesn't match any deck well enough, just skip it if (bestMatchRate < this.options.MinimumMatchRate) { continue; } // Associate the deck with the cluster it best matches if (!clusterGroups.ContainsKey(bestCluster)) { clusterGroups.Add(bestCluster, new List <PartialDeck>()); } clusterGroups[bestCluster].Add(deck); } return(clusterGroups); }