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);
        }
示例#2
0
        public IEnumerable <OutputModel> Get()
        {
            var predictor             = ClusteringService.KMeans();
            List <OutputModel> output = new List <OutputModel>();

            StreamReader file = new StreamReader("./iris.data");
            string       line;

            while ((line = file.ReadLine()) != null)
            {
                string[]   splitLine = line.Split(',');
                InputModel irisData  = new InputModel
                {
                    SepalLength = float.Parse(splitLine[0]),
                    SepalWidth  = float.Parse(splitLine[1]),
                    PetalLength = float.Parse(splitLine[2]),
                    PetalWidth  = float.Parse(splitLine[3])
                };

                var prediction = predictor.Predict(irisData);
                output.Add(new OutputModel(irisData, prediction.PredictedClusterId));
            }
            file.Close();
            return(output);
        }
        public void Clustering_TwoFrames()
        {
            var clustering = new ClusteringService();
            var frame1     = new Order().Random(10);
            var frame2     = new Order().Random(11);
            var frame3     = new Order().Random(12);
            var frame4     = new Order().Random(13);
            var frame5     = new Order().Random(18);
            var frame6     = new Order().Random(19);
            var frame7     = new Order().Random(20);
            var frame8     = new Order().Random(21);
            var frame9     = new Order().Random(22);

            frame1.OrderDirection = OrderDirections.SELL;
            frame3.OrderDirection = OrderDirections.SELL;
            frame5.OrderDirection = OrderDirections.SELL;
            frame7.OrderDirection = OrderDirections.SELL;
            frame9.OrderDirection = OrderDirections.SELL;

            var frames = new[] { frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9 };

            var results = clustering.Cluster(frames);

            var hm = results;
        }
        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 Clustering_ReturnsEmpty_ForNullArgs()
        {
            var clustering = new ClusteringService();

            var cluster = clustering.Cluster(null);

            Assert.IsNotNull(cluster);
            Assert.AreEqual(cluster.Count, 0);
        }
 public PointsGroupService(DatabaseContext context,
                           ItemService itemService,
                           ItemFilterer itemFilterer,
                           FileHandlerService fileHandlerService,
                           ClusteringService clusteringService)
 {
     this._context            = context;
     this._itemService        = itemService;
     this._itemFilterer       = itemFilterer;
     this._fileHandlerService = fileHandlerService;
     this._clusteringService  = clusteringService;
 }
        public void ClusteringNullObjectsTest()
        {
            //Arrange
            ClusteringService clusteringService = new ClusteringService();
            var objRepo = new DetectedObjectRepository(GetContext());
            IEnumerable <DataLayer.Models.DetectedObject> objs = new List <DataLayer.Models.DetectedObject>();
            float         score     = 0;
            List <PointF> centroids = new List <PointF>();
            //Act
            var res = clusteringService.GetClusters(4, objs, out score, out centroids);

            //Assert
            Assert.Null(res);
        }
        public void ClusteringNullClustersTest()
        {
            //Arrange
            ClusteringService clusteringService = new ClusteringService();
            var           objRepo   = new DetectedObjectRepository(GetContext());
            var           objs      = objRepo.GetVacantObjects(4);
            float         score     = 0;
            List <PointF> centroids = new List <PointF>();
            //Act
            var res = clusteringService.GetClusters(0, objs, out score, out centroids);

            //Assert
            Assert.Null(res);
        }
示例#9
0
        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();
        }
示例#10
0
        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);
                }
            }
        }
示例#11
0
 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();
 }