Ejemplo n.º 1
0
        // GET: SOM
        public ActionResult Index()
        {
            string filepath = Server.MapPath("~/Dataset/epileptic_dataset.csv");

            _reader = new CSVReader(filepath);

            _model.GetData(_reader);
            _model.Dataset.SetLabel("Patient");
            _model.Dataset.SetLabel("y");

            _model.FeatureLabel = "y";

            _model.InitializeMap();
            _model.Train();
            _model.LabelNodes();

            return(View(_model));
        }
Ejemplo n.º 2
0
        public static void Program1(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();


            string filepath = @"C:\Users\Vilson\Desktop\Datasets\Financial Distress\FD_Training.csv";

            SOM _model = new SOM(10, 10, 0.3, 20);

            _model.Training += _model_Training;
            IReader    _reader = new CSVReader(filepath);
            IClusterer _kmeans = new KMeansClustering();

            _model.GetData(_reader);
            _model.Dataset.SetLabel("Company");
            _model.Dataset.SetLabel("Time");
            _model.Dataset.SetLabel("Financial Distress");
            _model.Dataset.SetLabel("Status");

            _model.FeatureLabel = "Status";

            Console.WriteLine("Start initializing map...");
            stopwatch.Start();
            _model.InitializeMap();
            stopwatch.Stop();
            Console.WriteLine("Completed initialization...");
            Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);

            Console.WriteLine("Start training model...");
            stopwatch.Restart();
            _model.Train();
            stopwatch.Stop();
            Console.WriteLine("Completed training model...");
            Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);

            Console.WriteLine("Start labelling node...");
            stopwatch.Restart();
            _model.LabelNodes();
            stopwatch.Stop();
            Console.WriteLine("Completed labelling node...");
            Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);

            Console.WriteLine("Start clustering nodes...");
            stopwatch.Restart();
            var flattenedMap = ArrayHelper <Node> .FlattenMap(_model.Map);

            var clusteredNodes = _kmeans.Cluster(flattenedMap, 3);

            stopwatch.Stop();
            Console.WriteLine("Completed clustering nodes...");
            Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);

            string trainingPath = @"C:\Users\Vilson\Desktop\Datasets\Financial Distress\Training";

            List <TrajectoryMapper> dbTrajectories = new List <TrajectoryMapper>();

            Console.WriteLine("Start plotting trajectories...");
            stopwatch.Restart();

            foreach (var file in Directory.EnumerateFiles(trainingPath))
            {
                TrajectoryMapper trajectoryMapper = new TrajectoryMapper(_model);
                IReader          trajectoryReader = new CSVReader(file);

                trajectoryMapper.GetData(trajectoryReader);
                trajectoryMapper.GetTrajectories();

                dbTrajectories.Add(trajectoryMapper);
            }

            stopwatch.Stop();
            Console.WriteLine("Completed plotting trajectories...");
            Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);


            string testingPath = @"C:\Users\Vilson\Desktop\Datasets\Financial Distress\Test\fd_297.csv";

            TrajectoryMapper testMapper           = new TrajectoryMapper(_model);
            IReader          trjaectoryDataReader = new CSVReader(testingPath);

            testMapper.GetData(trjaectoryDataReader);
            var unknownTrajectory = testMapper.GetTrajectories();

            IFileHelper        fileHelper        = new FileHelper();
            ISimilarityMeasure similarityMeasure = new CompressionDissimilarityMeasure(fileHelper);

            foreach (var trajectory in dbTrajectories)
            {
                var currentTrajectory = trajectory.GetTrajectories();

                var score = similarityMeasure.MeasureSimilarity(currentTrajectory, unknownTrajectory);
                Console.WriteLine("{0}: {1}", trajectory.FileName, score);
            }

            Console.ReadLine();
        }