public Dictionary <CustomSocketDomain.SocketDomain, List <FuzzyFact> > GetFuzzyFacts(List <FuzzyDomain> domains, List <CustomSocket> sockets) { var socketType = typeof(CustomSocket); var fuzzyFacts = new Dictionary <CustomSocketDomain.SocketDomain, List <FuzzyFact> >(); foreach (var domain in domains) { var type = CustomSocketDomain.SocketDomainType[domain.Domain]; var domainValues = sockets .Select(p => socketType.GetProperty(domain.Domain.ToString()).GetValue(p)) .Where(p => !CustomSocketDomain.SocketDefaultValue[type].Equals(p)) .Distinct() .Select(p => Convert.ToDouble(p)) .ToList(); var factList = new List <FuzzyFact>(); foreach (var value in ClusteringService.CMeans(domain.Clusters.Count(), domainValues)) { factList.Add(new FuzzyFact(domain, value.Value, value.ClusterDegree)); } fuzzyFacts.Add(domain.Domain, SortClusters(factList)); } return(fuzzyFacts); }
public List <FuzzyFact> GetAmperageCircuitFact(List <FuzzyFuncStatement> statements, CustomSocket socket) { var values = new List <double>(); foreach (var statement in statements) { values.Add(statement.Result(socket)); } var domain = new FuzzyDomain(CustomSocketDomain.SocketDomain.AmperageCircuit, new FuzzyDomainOption { ClusterCount = FuzzyCustomSocket.GetFuzzySocketDomains()[CustomSocketDomain.SocketDomain.AmperageCircuit], Min = values.Min(), Max = values.Max() }); var facts = new List <FuzzyFact>(); foreach (var value in ClusteringService.CMeans(domain.Clusters.Count, values)) { facts.Add(new FuzzyFact(domain, value.Value, value.ClusterDegree)); } return(facts); }
public void CMeans_isSeedCapable() { var values = new List <double> { 1, 1, 2, 3, 3, 4, 5, 5 }; var fuzzyValues = ClusteringService.CMeans(3, values, randSeed: 0).ToList(); }
public void CMeans_isPlainCorrect() { var plainClusters = new List <double> { 1, 1, 1, 5, 5, 5, 9, 9, 9 }; const int plainClustersExpectedCount = 3; const int elements = 3; var result = ClusteringService.CMeans(plainClustersExpectedCount, plainClusters).ToList(); for (var k = 0; k < plainClustersExpectedCount; k++) { var clusterDegree = result[k * elements].GetMostProbableCluster(); for (var j = k * elements; j < elements; j++) { Assert.Equal(clusterDegree.Key, result[j].GetMostProbableCluster().Key); } } }
public void CMeans_isComplexCorrect() { var complexClusters = new List <double> { 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10, 12, 12, 12, 14, 15, 15, 16, 16, 19, 19, 19, 19, 20, 22, 22, 26, 28, 28, 29, 30, 37, 37, 38, 41, 55, 55, 55, 55, 63, 64, 70, 120, 120, 120, 120, 120, 120, 184 }; const int complexClustersExpectedCount = 3; var result = ClusteringService.CMeans(complexClustersExpectedCount, complexClusters).ToList(); }