Exemple #1
0
        /// <summary>
        /// Makes a collection of empty timestamped workflow trace shells, one for each unique "Case ID" in loaded data from an event log.
        /// </summary>
        /// <param name="ids">A "Case ID" column from the data frame, representation of a loaded event log.</param>
        /// <returns>A list of empty timestamped workflow traces, one for each unique "Case ID" in given data.</returns>
        private List <TimestampedWorkflowTrace> MakeEmptyTimestampedWfts(Deedle.Series <int, string> ids)
        {
            List <TimestampedWorkflowTrace> traces = new List <TimestampedWorkflowTrace>();
            HashSet <string> uniqueIds             = new HashSet <string>(ids.Values);

            foreach (var id in uniqueIds)
            {
                traces.Add(new TimestampedWorkflowTrace("" + id));
            }
            return(traces);
        }
        public void MaxDrawdown()
        {
            var series = new Deedle.Series <DateTime, double>(new []
            {
                new KeyValuePair <DateTime, double>(new DateTime(2020, 1, 1), 100000),
                new KeyValuePair <DateTime, double>(new DateTime(2020, 1, 2), 90000),
                new KeyValuePair <DateTime, double>(new DateTime(2020, 1, 3), 100000),
                new KeyValuePair <DateTime, double>(new DateTime(2020, 1, 4), 100000),
                new KeyValuePair <DateTime, double>(new DateTime(2020, 1, 5), 80000)
            });

            var collection = DrawdownCollection.GetDrawdownPeriods(series, 1).ToList();

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(0.2, collection.First().Drawdown, 0.0001);
        }
Exemple #3
0
        public void Stat2StDevBenchmark()
        {
            var comparer = KeyComparer <int> .Default;
            var count    = 1_000_000;
            var width    = 20;
            var sm       = new SortedMap <int, double>(count, comparer);

            sm.Add(0, 0);
            for (int i = 2; i <= count; i++)
            {
                sm.Add(i, i);
            }

            var ds1 = new Deedle.Series <int, double>(sm.Keys.ToArray(), sm.Values.ToArray());

            var sum = 0.0;

            for (int r = 0; r < 10; r++)
            {
                var sum1 = 0.0;
                using (Benchmark.Run("Stat2 Online N", count * width))
                {
                    foreach (var stat2 in sm.Stat2(width).Values)
                    {
                        sum1 += stat2.StDev;
                    }
                }
                Assert.True(sum1 != 0);

                var sum2 = 0.0;
                using (Benchmark.Run("Stat2 Online Width GE", count * width))
                {
                    foreach (var stat2 in sm.Stat2(width - 1, Lookup.GE).Values)
                    {
                        sum2 += stat2.StDev;
                    }
                }
                Assert.True(sum2 != 0);

                var sum3 = 0.0;
                using (Benchmark.Run("Stat2 Window N", count * width))
                {
                    foreach (var stat2 in sm.Window(width).Map(x => x.Stat2()).Values)
                    {
                        sum3 += stat2.StDev;
                    }
                }
                Assert.True(sum3 != 0);

                var sum4 = 0.0;
                using (Benchmark.Run("Stat2 Window Width GE", count * width))
                {
                    foreach (var stat2 in sm.Window(width - 1, Lookup.GE).Map(x => x.Stat2()).Values)
                    {
                        sum4 += stat2.StDev;
                    }
                }
                Assert.True(sum4 != 0);

                var sum5 = 0.0;
                using (Benchmark.Run("Deedle (online)", count * width))
                {
                    var deedleStDev = Deedle.Stats.movingStdDev(width, ds1);
                    foreach (var keyValuePair in deedleStDev.Values)
                    {
                        sum5 += keyValuePair;
                    }
                }
                Assert.True(sum5 != 0);

                Assert.True(Math.Abs(sum1 / sum2 - 1) < 0.000001);
                Assert.True(Math.Abs(sum1 / sum3 - 1) < 0.000001);
                Assert.True(Math.Abs(sum1 / sum4 - 1) < 0.000001);
                Assert.True(Math.Abs(sum1 / sum5 - 1) < 0.000001);

                sum = 0.0;
                using (Benchmark.Run("SortedMap enumeration", count))
                {
                    var cursor = sm.GetEnumerator();
                    while (cursor.MoveNext())
                    {
                        sum += cursor.currentValue;
                    }
                }
                Assert.True(sum != 0);
            }

            Benchmark.Dump($"The window width is {width}. Stat2 MOPS are calculated as a number of calculated values multiplied by width, " +
                           $"which is equivalent to the total number of cursor moves for Window case. SortedMap line is for reference - it is the " +
                           $"speed of raw iteration over SM without Stat2/Windows overheads (and not multiplied by width).");
        }