Example #1
0
 public void SetUp()
 {
     _currentTime          = 0;
     _pZero                = new EuclideanPoint(0, 0, _currentTime);
     _p500                 = new EuclideanPoint(500, 500, _currentTime);
     _singletonClusterZero = new [] { _pZero };
     _singletonCluster500  = new [] { _p500 };
     _fullCluster          = new[] { _pZero, _p500 };
     _simFunc              = (x, y) =>
                             (float)Math.Sqrt(Math.Pow(x.X - y.X, 2) + Math.Pow(x.Y - y.Y, 2));
 }
Example #2
0
        public void ElementWiseSum_SimplePointList_SinglePoint()
        {
            var arr = new[]
            {
                new EuclideanPoint(1, 2, 0),
                new EuclideanPoint(3, 4, 0)
            };

            var expected = new EuclideanPoint(4, 6, 0);
            var actual   = arr.ElementWiseSum();

            Assert.That(actual.X, Is.EqualTo(expected.X));
            Assert.That(actual.Y, Is.EqualTo(expected.Y));
        }
Example #3
0
        private static void DenStreamSyntheticTest()
        {
            var filePath   = $"{Environment.CurrentDirectory}/Data/Synthesis/DataSteamGenerator/data.synthetic.json";
            var dataStream = ContinuousDataReader.ReadSyntheticEuclidean(filePath);

            Func <EuclideanPoint, EuclideanPoint, float> simFunc = (x, y) =>
                                                                   (float)Math.Sqrt(Math.Pow(x.X - y.X, 2) + Math.Pow(x.Y - y.Y, 2));

            Func <CoreMicroCluster <EuclideanPoint>, CoreMicroCluster <EuclideanPoint>, int, float> cmcSimFunc = (u, v, t) =>
                                                                                                                 (float)Math.Sqrt(Math.Pow(u.Center(t).X - v.Center(t).X, 2) +
                                                                                                                                  Math.Pow(u.Center(t).Y - v.Center(t).Y, 2));

            var denStream = new DenStream <EuclideanPoint>(simFunc, cmcSimFunc);

            denStream.AddToDataStream(dataStream);
            denStream.MaintainClusterMap();

            var pcmcs      = new List <EuclideanPoint>();
            var ocmcs      = new List <EuclideanPoint>();
            var pcmcPoints = new List <EuclideanPoint>();
            var ocmcPoints = new List <EuclideanPoint>();

            foreach (var pcmc in denStream.PotentialCoreMicroClusters)
            {
                var _pcmc = pcmc as CoreMicroCluster <EuclideanPoint>;
                var p     = new EuclideanPoint(_pcmc.Center(denStream.CurrentTime).X, _pcmc.Center(denStream.CurrentTime).Y,
                                               (int)_pcmc.Radius(denStream.CurrentTime));
                p.SetRadius(_pcmc.Radius(denStream.CurrentTime));
                pcmcs.Add(p);
            }

            foreach (var ocmc in denStream.OutlierCoreMicroClusters)
            {
                var _ocmc = ocmc as CoreMicroCluster <EuclideanPoint>;
                var p     = new EuclideanPoint(_ocmc.Center(denStream.CurrentTime).X, _ocmc.Center(denStream.CurrentTime).Y,
                                               (int)_ocmc.Radius(denStream.CurrentTime));
                p.SetRadius(_ocmc.Radius(denStream.CurrentTime));
                ocmcs.Add(p);
            }

            foreach (var pcmc in denStream.PotentialCoreMicroClusters)
            {
                pcmc.Points.ForEach(p =>
                {
                    var ep = new EuclideanPoint(p.X, p.Y, 2);
                    ep.SetRadius(2);
                    pcmcPoints.Add(ep);
                });
            }

            foreach (var ocmc in denStream.OutlierCoreMicroClusters)
            {
                ocmc.Points.ForEach(p =>
                {
                    var ep = new EuclideanPoint(p.X, p.Y, 2);
                    ep.SetRadius(2);
                    ocmcPoints.Add(ep);
                });
            }

            File.WriteAllText($"{Environment.CurrentDirectory}/Data/Synthesis/ClusterVisualization/pcmcs.json", JsonConvert.SerializeObject(pcmcs));
            File.WriteAllText($"{Environment.CurrentDirectory}/Data/Synthesis/ClusterVisualization/ocmcs.json", JsonConvert.SerializeObject(ocmcs));
            File.WriteAllText($"{Environment.CurrentDirectory}/Data/Synthesis/ClusterVisualization/pcmcPoints.json", JsonConvert.SerializeObject(pcmcPoints));
            File.WriteAllText($"{Environment.CurrentDirectory}/Data/Synthesis/ClusterVisualization/ocmcPoints.json", JsonConvert.SerializeObject(ocmcPoints));

            Console.WriteLine($"Wrote {pcmcs.Count} PCMCs and {ocmcs.Count} OCMCs to disk.");
        }