コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHaveLowAccidentalChecksumCollision()
        internal virtual void ShouldHaveLowAccidentalChecksumCollision()
        {
            // GIVEN
            int count = 100_000;

            // WHEN
            GSP   gsp        = new GSP();
            int   collisions = 0;
            short reference  = 0;

            for (int i = 0; i < count; i++)
            {
                gsp.Generation = _random.nextLong(GenerationSafePointer.MAX_GENERATION);
                gsp.Pointer    = _random.nextLong(GenerationSafePointer.MAX_POINTER);
                short checksum = ChecksumOf(gsp);
                if (i == 0)
                {
                    reference = checksum;
                }
                else
                {
                    bool unique = checksum != reference;
                    collisions += unique ? 0 : 1;
                }
            }

            // THEN
            assertTrue(( double )collisions / count < 0.0001);
        }
コード例 #2
0
 private bool Read(PageCursor cursor, int offset, GSP into)
 {
     cursor.Offset   = offset;
     into.Generation = GenerationSafePointer.ReadGeneration(cursor);
     into.Pointer    = GenerationSafePointer.ReadPointer(cursor);
     return(GenerationSafePointer.VerifyChecksum(cursor, into.Generation, into.Pointer));
 }
コード例 #3
0
        private async void FinAllGSPBtn_Click(object sender, EventArgs e)
        {
            frequentDgv.Rows.Clear();
            try
            {
                double percent = double.Parse(suppGspTxtb.Text);
                if (percent < 1)
                {
                    MessageBox.Show("Value to low");
                    return;
                }
                double     supp    = ((double)((double)datasetGsp.Count() / (double)100)) * percent;
                int        support = (int)Math.Round(supp);
                GSP        gSP     = new GSP(support, toolStripProgressBar1);
                Sequence[] x       = await gSP.LearnAsync(datasetGsp);

                sequ = x;
                StringBuilder sb = new StringBuilder();

                foreach (var seq in x)
                {
                    frequentDgv.Rows.Add(seq.GetSequence(), (seq.Support / datasetGsp.Count()).ToString("P1"));
                    sb.Append($"{seq.GetSequence()}  -  {seq.Support}/{datasetGsp.Count()} - " +
                              $"{(seq.Support / datasetGsp.Count()).ToString("P1")}\n");
                }
                richTextBox1.Clear();
                richTextBox1.Text             = sb.ToString();
                toolStripProgressBar1.Visible = false;
            }
            catch (Exception ex)
            {
            }
        }
コード例 #4
0
        private GSP Gsp(long generation, long pointer)
        {
            GSP gsp = new GSP();

            gsp.Generation = generation;
            gsp.Pointer    = pointer;
            return(gsp);
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowIfGenerationToSmall()
        internal virtual void ShouldThrowIfGenerationToSmall()
        {
            long generation = GenerationSafePointer.MIN_GENERATION - 1;
            long pointer    = GenerationSafePointer.MinPointer;
            GSP  broken     = Gsp(generation, pointer);

            assertThrows(typeof(System.ArgumentException), () => write(_cursor, 0, broken));
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowIfPointerToLarge()
        internal virtual void ShouldThrowIfPointerToLarge()
        {
            long generation = GenerationSafePointer.MIN_GENERATION;
            long pointer    = GenerationSafePointer.MAX_POINTER + 1;
            GSP  broken     = Gsp(generation, pointer);

            assertThrows(typeof(System.ArgumentException), () => write(_cursor, 0, broken));
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadGspWithZeroValues()
        internal virtual void ShouldReadGspWithZeroValues()
        {
            // GIVEN
            int offset   = 3;
            GSP expected = Gsp(0, 0);

            // THEN
            bool matches = _read(_cursor, offset, _read);

            assertTrue(matches);
            assertEquals(expected, _read);
        }
        //[ValidateAntiForgeryToken]
        public IActionResult FindSpm(float supportPercentage, DateTime startDate, DateTime endDate)
        {
            //  IEnumerable<UkRetailOriginalSales> inputDataset = _dbContext.UkRetailOriginalSales.Select(a => a.CustomerID , a. ).ToList();
            var customerOrders = _dbContext.UkRetailOriginalSales
                                 .Where(a => a.InvoiceDate.Date >= startDate.Date && a.InvoiceDate.Date <= endDate.Date &&
                                        a.CustomerID != null && a.CustomerID < 13000 && a.Quantity > 0 &&
                                        string.Compare(a.StockCode, "a") == -1)
                                 .Select(a => new { a.CustomerID, Year = a.InvoiceDate.Year, Month = a.InvoiceDate.Month, a.StockCode })
                                 //.OrderBy(a => new { a.Year, a.Month })
                                 .GroupBy(a => new { a.CustomerID }).AsQueryable();
            //.GroupBy(a => new { a.CustomerID, a.Year, a.Month });

            List <List <List <string> > > transformedSequences = new List <List <List <string> > >();

            foreach (var groupCustomer in customerOrders)
            {
                var customerMonthlyorder       = groupCustomer.GroupBy(a => new { a.Year, a.Month });
                List <List <string> > sequence = new List <List <string> >();
                foreach (var groupCustomerMontlyOrder in customerMonthlyorder)
                {
                    List <string> itemset = new List <string>();
                    foreach (var order in groupCustomerMontlyOrder)
                    {
                        itemset.Add(order.StockCode);
                    }
                    sequence.Add(itemset);
                }
                transformedSequences.Add(sequence);
            }

            int CountUsers = transformedSequences.Count();
            int support    = Convert.ToInt32(Math.Floor((supportPercentage / 100) * CountUsers));
            GSP gsp        = new GSP();
            List <SequenceSupport> frequentSequences = gsp.FindSequentialPatterns(transformedSequences, support);

            List <SequenceSupportPercentage> frequentSequencesPercentages = new List <SequenceSupportPercentage>();

            foreach (SequenceSupport frequentSequence in frequentSequences)
            {
                SequenceSupportPercentage frequentSequencesPercentage = new SequenceSupportPercentage();
                frequentSequencesPercentage.sequence          = frequentSequence.sequence;
                frequentSequencesPercentage.support           = frequentSequence.support;
                frequentSequencesPercentage.supportPercentage = ((float)frequentSequence.support / transformedSequences.Count()) * 100;
                frequentSequencesPercentages.Add(frequentSequencesPercentage);
            }

            // SavetoDatabase(frequentSequencesPercentages.Where(a => a.sequence.Count()>1).ToList());
            SavetoDatabase(frequentSequencesPercentages.ToList());
            //return View(frequentSequences.Where(a => a.sequence.Count>=1));
            return(View(frequentSequencesPercentages));
        }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldWriteAndReadGsp()
        internal virtual void ShouldWriteAndReadGsp()
        {
            // GIVEN
            int offset   = 3;
            GSP expected = Gsp(10, 110);

            // WHEN
            Write(_cursor, offset, expected);

            // THEN
            bool matches = _read(_cursor, offset, _read);

            assertTrue(matches);
            assertEquals(expected, _read);
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDetectInvalidChecksumOnReadDueToChangedGeneration()
        internal virtual void ShouldDetectInvalidChecksumOnReadDueToChangedGeneration()
        {
            // GIVEN
            int offset  = 0;
            GSP initial = Gsp(123, 456);

            Write(_cursor, offset, initial);

            // WHEN
            _cursor.putInt(offset, ( int )(initial.Generation + 5));

            // THEN
            bool matches = _read(_cursor, offset, _read);

            assertFalse(matches);
        }
コード例 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDetectInvalidChecksumOnReadDueToChangedChecksum()
        internal virtual void ShouldDetectInvalidChecksumOnReadDueToChangedChecksum()
        {
            // GIVEN
            int offset  = 0;
            GSP initial = Gsp(123, 456);

            Write(_cursor, offset, initial);

            // WHEN
            _cursor.putShort(offset + GenerationSafePointer.Size - GenerationSafePointer.CHECKSUM_SIZE, ( short )(ChecksumOf(initial) - 2));

            // THEN
            bool matches = _read(_cursor, offset, _read);

            assertFalse(matches);
        }
コード例 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldWriteAndReadGspCloseToPointerMax()
        internal virtual void ShouldWriteAndReadGspCloseToPointerMax()
        {
            // GIVEN
            long pointer  = GenerationSafePointer.MAX_POINTER;
            GSP  expected = Gsp(12345, pointer);

            Write(_cursor, 0, expected);

            // WHEN
            GSP  read    = new GSP();
            bool matches = read(_cursor, 0, read);

            // THEN
            assertTrue(matches);
            assertEquals(expected, read);
            assertEquals(pointer, read.Pointer);
        }
コード例 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldWriteAndReadGspCloseToGenerationMax()
        internal virtual void ShouldWriteAndReadGspCloseToGenerationMax()
        {
            // GIVEN
            long generation = GenerationSafePointer.MAX_GENERATION;
            GSP  expected   = Gsp(generation, 12345);

            Write(_cursor, 0, expected);

            // WHEN
            GSP  read    = new GSP();
            bool matches = read(_cursor, 0, read);

            // THEN
            assertTrue(matches);
            assertEquals(expected, read);
            assertEquals(generation, read.Generation);
        }
コード例 #14
0
            public override bool Equals(object obj)
            {
                if (this == obj)
                {
                    return(true);
                }
                if (obj == null)
                {
                    return(false);
                }
                if (this.GetType() != obj.GetType())
                {
                    return(false);
                }
                GSP other = ( GSP )obj;

                if (Generation != other.Generation)
                {
                    return(false);
                }
                return(Pointer == other.Pointer);
            }
コード例 #15
0
        public IActionResult FindSpm(string inputData, int support)
        {
            List <List <List <string> > > transformedSequences = new List <List <List <string> > >();
            // List<List<string>> inputSequence = new List<List<string>>();
            // List<string> itemList = new List<List<string>>();

            List <string> sequenceList = new List <string>();

            sequenceList = inputData.Split("\r\n").Where(r => (r != "") && (r != " ")).ToList();
            //sequenceList = inputData.Split('<','>').Where(r => (r != "") && (r != "\r\n")).ToList();
            foreach (string sequence in sequenceList)
            {
                List <string> sequenceItemlists = sequence.Split(' ').ToList();

                List <List <string> > inputSequence = new List <List <string> >();
                foreach (string sequenceItemlist in sequenceItemlists)
                {
                    List <string> itemlist = sequenceItemlist.Split(',').ToList();
                    inputSequence.Add(itemlist);
                }
                transformedSequences.Add(inputSequence);
            }

            GSP gsp = new GSP();
            List <SequenceSupport>           frequentSequences            = gsp.FindSequentialPatterns(transformedSequences, support);
            List <SequenceSupportPercentage> frequentSequencesPercentages = new List <SequenceSupportPercentage>();

            foreach (SequenceSupport frequentSequence in frequentSequences)
            {
                SequenceSupportPercentage frequentSequencesPercentage = new SequenceSupportPercentage();
                frequentSequencesPercentage.sequence          = frequentSequence.sequence;
                frequentSequencesPercentage.support           = frequentSequence.support;
                frequentSequencesPercentage.supportPercentage = ((float)frequentSequence.support / transformedSequences.Count()) * 100;
                frequentSequencesPercentages.Add(frequentSequencesPercentage);
            }

            return(View(frequentSequencesPercentages));
        }
コード例 #16
0
        static void Main(string[] args)
        {
            List <SortedSet <string> >[] dataSet = new List <SortedSet <string> >[]
            {
                new List <SortedSet <string> >()
                {
                    new SortedSet <string>()
                    {
                        "A"
                    },
                    new SortedSet <string>()
                    {
                        "B"
                    },
                    new SortedSet <string>()
                    {
                        "F", "G"
                    },
                    new SortedSet <string>()
                    {
                        "C"
                    },
                    new SortedSet <string>()
                    {
                        "D"
                    }
                },
                new List <SortedSet <string> >()
                {
                    new SortedSet <string>()
                    {
                        "B"
                    },
                    new SortedSet <string>()
                    {
                        "G"
                    },
                    new SortedSet <string>()
                    {
                        "D"
                    }
                },
                new List <SortedSet <string> >()
                {
                    new SortedSet <string>()
                    {
                        "B"
                    },
                    new SortedSet <string>()
                    {
                        "F"
                    },
                    new SortedSet <string>()
                    {
                        "G"
                    },
                    new SortedSet <string>()
                    {
                        "A", "B"
                    }
                },
                new List <SortedSet <string> >()
                {
                    new SortedSet <string>()
                    {
                        "F"
                    },
                    new SortedSet <string>()
                    {
                        "A", "B"
                    },
                    new SortedSet <string>()
                    {
                        "C"
                    },
                    new SortedSet <string>()
                    {
                        "D"
                    }
                },
                new List <SortedSet <string> >()
                {
                    new SortedSet <string>()
                    {
                        "A"
                    },
                    new SortedSet <string>()
                    {
                        "B", "C"
                    },
                    new SortedSet <string>()
                    {
                        "G"
                    },
                    new SortedSet <string>()
                    {
                        "F"
                    },
                    new SortedSet <string>()
                    {
                        "D", "E"
                    }
                }
            };

            //List<SortedSet<string>>[] dataSet = new List<SortedSet<string>>[]
            //{
            //    new List<SortedSet<string>>()
            //    {
            //        new SortedSet<string>(){"30"},
            //        new SortedSet<string>(){"90"}
            //    },
            //    new List<SortedSet<string>>()
            //    {
            //        new SortedSet<string>(){"10", "20"},
            //        new SortedSet<string>(){"30"},
            //        new SortedSet<string>(){"40", "60","70"}
            //    },
            //    new List<SortedSet<string>>()
            //    {
            //        new SortedSet<string>(){"30", "50", "70"}

            //    },
            //    new List<SortedSet<string>>()
            //    {
            //        new SortedSet<string>(){"30"},
            //        new SortedSet<string>(){"40","70"},
            //        new SortedSet<string>(){"90"}
            //    },
            //    new List<SortedSet<string>>()
            //    {
            //        new SortedSet<string>(){"90"}
            //    }
            //};

            SortedSet <string>[] dataset1 =
            {
                new SortedSet <string> {
                    "A", "B", "C", "D"
                },
                new SortedSet <string> {
                    "B", "C", "D", "E"
                },
                new SortedSet <string> {
                    "A", "B", "E"
                }
            };
            GSP al = new GSP(1);

            Sequence[] x = al.Learn(dataSet);
            foreach (var i in x)
            {
                Console.WriteLine(i.ToString());
            }
            Console.WriteLine("\nDone...\nPress any key to exit....");
            Console.ReadKey();
            //Apriori apr = new Apriori(2, 0);
            //var a = apr.Learn(dataset1.ToArray());
            //foreach(var i in a)
            //{
            //    Console.WriteLine(i.ToString());
            //}
            //Console.ReadKey();
        }
コード例 #17
0
 private static short ChecksumOf(GSP gsp)
 {
     return(GenerationSafePointer.ChecksumOf(gsp.Generation, gsp.Pointer));
 }
コード例 #18
0
 private void Write(PageCursor cursor, int offset, GSP gsp)
 {
     cursor.Offset = offset;
     GenerationSafePointer.Write(cursor, gsp.Generation, gsp.Pointer);
 }