public TrajectoryResponse GetTrajectory(TrajectoryRequest request)
        {
            TrajectoryMapper trajectoryMapper = new TrajectoryMapper(request.Map);
            IReader          reader           = new CSVReader(request.FilePath);

            // Get the data
            trajectoryMapper.GetData(reader);

            // Get the mapped trajectories
            var trajectories = trajectoryMapper.GetTrajectories();

            return(new TrajectoryResponse()
            {
                Trajectories = trajectories.ToArray()
            });
        }
Esempio n. 2
0
        public async Task <HttpResponseMessage> PlotTrajectory()
        {
            try
            {
                HttpRequestMessage requestMessage = this.Request;

                if (!requestMessage.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                TrajectoryRequest request = new TrajectoryRequest();

                string root     = System.Web.HttpContext.Current.Server.MapPath(FILE_UPLOAD_PATH);
                var    provider = new MultipartFormDataStreamProvider(root);

                var result = await Request.Content.ReadAsMultipartAsync(provider);

                var map = result.FormData["map"];

                SOM som = JsonConvert.DeserializeObject <SOM>(map);

                string file = provider.FileData.Last().LocalFileName;

                IReader reader = new CSVReader(file);

                TrajectoryMapper trajectoryMapper = new TrajectoryMapper(som);
                trajectoryMapper.GetData(reader);

                TrajectoryResponse trajectoryResponse = new TrajectoryResponse()
                {
                    Trajectories = trajectoryMapper.GetTrajectories().ToArray()
                };

                File.Delete(result.FileData.First().LocalFileName);

                return(Request.CreateResponse(HttpStatusCode.OK, trajectoryResponse));
            } catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Esempio n. 3
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();
        }