Exemplo n.º 1
0
        static void RunProgram()
        {
            //Config
            string codeName                = "Out-Cikade";
            bool   printKMeans             = true;
            bool   printKMeansMembers      = false;
            bool   distanceMatrix          = true;
            bool   multiDimensionalScaling = true;
            bool   localOutlierFactor      = true;

            IConfiguration configuration =
                (ConfigurationSectionHandler)ConfigurationManager.GetSection("csvDataImport");
            var reader         = new StreamReader("UserData.csv");
            var importer       = new CsvDataImporter(reader, configuration);
            var dataCollection = importer.Run();

            //Algo//
            //KMeans
            var k = 5;
            var distanceMetric = new EuclideanMetric();

            var kmeans = new KMeans(dataCollection, k, distanceMetric);

            var start  = DateTime.Now;
            var result = kmeans.Calculate();
            //Other alogs


            //File printing//
            var fileName = string.Format("{0}-{1:MM-dd_HH_mm_ss}.txt", codeName, DateTime.UtcNow);

            FileStream   fs     = new FileStream(fileName, FileMode.CreateNew);
            StreamWriter writer = new StreamWriter(fs);

            writer.Write("Testrun under CodeName {0}. \r\n\r\n", codeName, DateTime.UtcNow);

            if (printKMeans)
            {
                PrintKMeans(writer, result, printKMeansMembers);
            }

            if (distanceMatrix)
            {
                DistanceMatrix(writer, dataCollection, distanceMetric);
            }

            if (multiDimensionalScaling)
            {
                MultiDimensionalScaling(writer, dataCollection, distanceMetric);
            }

            if (localOutlierFactor)
            {
                LocalOutlierFactorD(4, dataCollection, distanceMetric);
            }

            writer.Close();
            fs.Close();
        }
Exemplo n.º 2
0
        public void SetUp()
        {
            var config   = SetupMockConfiguration();
            var reader   = new StringReader(Resources.SampleData);
            var importer = new CsvDataImporter(reader, config);

            dataSet = importer.Run();
        }
Exemplo n.º 3
0
        static void TestImport()
        {
            IConfiguration configuration =
                (ConfigurationSectionHandler)ConfigurationManager.GetSection("csvDataImport");
            var             reader   = new StreamReader("UserData.csv");
            CsvDataImporter importer = new CsvDataImporter(reader, configuration);
            var             dataSet  = importer.Run();

            reader.Close();
        }
Exemplo n.º 4
0
        private IdentifiableDataPointCollection DataImportTask_Run(object input)
        {
            ImportOptions options = input as ImportOptions;

            var reader   = new StreamReader(options.Path);
            var importer = new CsvDataImporter(reader, options.Configuration)
            {
                FieldDelimiter   = options.FieldDelimiter,
                ValueDelimiter   = options.ValueDelimiter,
                RemoveWhiteSpace = options.RemoveWhiteSpace
            };

            return(importer.Run());
        }
        public void ShouldThrowExceptionWhenNumericFieldContainsInvalidValue()
        {
            var config = SetupMockConfiguration();
            var data   =
                @"Gender,BirthYear
Female,1998a
Male,1993";
            var reader   = new StringReader(data);
            var importer = new CsvDataImporter(reader, config);

            var exception = Assert.Throws <InvalidNumericValueException>(() => importer.Run());

            Assert.AreEqual(2, exception.LineNumber);
            Assert.AreEqual(1, exception.Field);
        }
        public void ShouldThrowExceptionWhenScalarValueIsEmpty()
        {
            var config = SetupMockConfiguration();
            var data   =
                @"Gender,BirthYear
,1998
Female,1993";
            var reader   = new StringReader(data);
            var importer = new CsvDataImporter(reader, config);

            var exception = Assert.Throws <InvalidFieldValueException>(() => importer.Run());

            Assert.AreEqual(2, exception.LineNumber);
            Assert.AreEqual(0, exception.Field);
        }