Esempio n. 1
0
        public void open_xml()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\",
                Title            = "Browse Text Files",
                CheckFileExists  = true,
                CheckPathExists  = true,
                DefaultExt       = "xml",
                Filter           = "xml files (*.xml)|*.xml",
                FilterIndex      = 2,
                RestoreDirectory = true,
                ReadOnlyChecked  = true,
                ShowReadOnly     = true
            };

            // check if file path is correct
            if (openFileDialog1.ShowDialog() == true)
            {
                file_path = openFileDialog1.FileName; // initial file path field
                //StreamReader sr = new StreamReader(file_path);
                readXML((string)file_path);
                create_dict();
                find_most_corralated();
                TimeSeries            ts1 = new TimeSeries((string)file_path_csv, chunks);
                SimpleAnomalyDetector s   = new SimpleAnomalyDetector();
                TimeSeries            ts  = new TimeSeries((string)file_path2, chunks);
                s.learnNormal(ts);
                List <AnomalyReport> a = s.detect(ts1);
            }
        }
Esempio n. 2
0
        public void updateChoose(string csv_learn, string csv_detect, List <string> features, string chosen_feature)
        {
            Anomaly_detector      anomaly = new Anomaly_detector();
            SimpleAnomalyDetector s       = new SimpleAnomalyDetector();

            this.sd   = s;
            ts_normal = new TimeSeries((string)csv_learn, features);
            s.learnNormal(ts_normal);
            TimeSeries ts_detect = new TimeSeries((string)csv_detect, features);

            anomaly_reports = s.detect(ts_detect);
            CorrelatedFeatures c = s.get_correlated(chosen_feature);

            if (c != null)
            {
                string second_cor;
                if (c.get_feature1() == chosen_feature)
                {
                    second_cor = c.get_feature2();
                }
                else
                {
                    second_cor = c.get_feature1();
                }
                // size vector
                int size = ts_normal.get_dict()[features.IndexOf(chosen_feature)].Count;
                // create circle ****************************************************************
                List <DataPoint> learn_points = circle_to_points(c.Center.x, c.Center.y, c.Threshold);
                Circle_Points = learn_points;
                NotifyPropertyChanged("Circle_Points");
                //List<DataPoint> learn_points = line_to_points(c.get_line_reg(), size, ts_detect.get_dict()[features.IndexOf(chosen_feature)], ts_detect.get_dict()[features.IndexOf(second_cor)]);
                //Line_Reg_Points = learn_points;
                //NotifyPropertyChanged("Line_Reg_Points");
                // the point of the detect
                List <DataPoint> detected_points = new List <DataPoint>();
                for (int i = 0; i < anomaly_reports.Count; i++)
                {
                    if (anomaly_reports[i].get_feature1() == chosen_feature)
                    {
                        float x = ts_detect.get_dict()[features.IndexOf(chosen_feature)][(int)anomaly_reports[i].timeStep];
                        float y = ts_detect.get_dict()[features.IndexOf(second_cor)][(int)anomaly_reports[i].timeStep];
                        detected_points.Add(new DataPoint(x, y));
                    }
                    else
                    {
                        float x = ts_detect.get_dict()[features.IndexOf(second_cor)][(int)anomaly_reports[i].timeStep];
                        float y = ts_detect.get_dict()[features.IndexOf(chosen_feature)][(int)anomaly_reports[i].timeStep];
                        detected_points.Add(new DataPoint(x, y));
                    }
                }
                Anomaly_Points = detected_points;

                NotifyPropertyChanged("Anomaly_Points");
            }

            // anomaly.get_points(ts_normal.get_dict()[features.IndexOf(chosen_feature)], ts_normal.get_dict()[ts_normal.get]
        }
        private void loadAllCorrelatedFeatures()
        {
            string newPath = addHeader(this.trainCSVPath, this.xmlDict);

            this.ts = new Timeseries(newPath);

            this.ad = new SimpleAnomalyDetector((float)0.5);

            this.ad.learnNormal(this.ts);
            this.cf = ad.getNormalModel();
        }
        // starting the application
        public void start()
        {
            this.connect(Constants.HOST_IP, Constants.HOST_PORT);       // connecting to the flight gear server.
            NetworkStream writer = new NetworkStream(fg);               // creating a stream for writing to the server.
            string        line;

            new Thread(delegate()
            {
                if (ts.FeaturesMap.Count == 0)                      // saving the values of the reg flight in timeseries
                {
                    ts.initFeaturesMap(regFlightFile, settingsFile);
                }
                SimpleAnomalyDetector simp = new SimpleAnomalyDetector();
                cf = simp.LearnNormal(ts);
                //dynamic c = loadDLL();
                //TimeSeries anomalyTs = new TimeSeries();
                //anomalyTs.initFeaturesMap(AnomalyFlight, settingsFile);
                //List<AnomalyReport> anomalies = c.Detect(anomalyTs);
                //int anomalyIndex = 0;
                while (timeInDeciSeconds <= ts.getNumOfTimesteps())          // while we are not at the end of the flight
                {
                    if (!Stop)                                               // if the video is not stopped.
                    {
                        UpdateTime();                                        // updating the time of the flight by 1 deciseconds.
                        if (timeInDeciSeconds == ts.getNumOfTimesteps() - 1) // if the time is the end of the flight we will pause the connection.
                        {
                            Stop = true;
                        }
                        if ((DesiredFeature.EndsWith("1") || DesiredFeature.EndsWith("2")) && DesiredFeature != "")      // check if the feature has 2 occurences.
                        {
                            PointsTopRightGraph.Add(new DataPoint(TimeInDeci, getDuplicatedFaetureVal(DesiredFeature))); // adding new point to the graph of the desired feature;
                            getCorrelatedFeature();                                                                      // if the feature has a correlated feature, it will handle the correlated feature's graph here.
                            InvalidateFlag++;                                                                            // indicating we made a chenge in points.
                        }
                        else if (DesiredFeature != "")
                        {
                            PointsTopRightGraph.Add(new DataPoint(TimeInDeci, getFaetureVal(DesiredFeature)));
                            getCorrelatedFeature();
                            InvalidateFlag++;
                        }

                        /*
                         * if((anomalyIndex > anomalies.Count) && anomalies[anomalyIndex++].TimeStep == TimeInDeci)
                         * {
                         *  UpdateAnomaly();
                         * }
                         */
                        line = ts.GetTimestepStr(timeInDeciSeconds);                                    // getting the next time series line.

                        // updating the flight members
                        Elevator    = (ts.getFeatureVal("elevator", timeInDeciSeconds)) * 130 + 125; // update the elevator.
                        Aileron     = (ts.getFeatureVal("aileron", timeInDeciSeconds)) * 130 + 125;  // update the aileron.
                        Throttle    = (getDuplicatedFaetureVal("throttle1")) * 46 + 46;              // update the throttle.
                        Rudder      = (ts.getFeatureVal("rudder", timeInDeciSeconds)) + 46;          // update the rudder.
                        Height      = ts.getFeatureVal("altitude-ft", timeInDeciSeconds);            // update the altitude-ft.
                        FlightSpeed = ts.getFeatureVal("airspeed-kt", timeInDeciSeconds);            // update the airspeed-kt.
                        Direction   = ts.getFeatureVal("heading-deg", timeInDeciSeconds);            // update the heading-deg.
                        Roll        = ts.getFeatureVal("roll-deg", timeInDeciSeconds);               // update the roll-deg.
                        Yaw         = ts.getFeatureVal("side-slip-deg", timeInDeciSeconds);          // update the side-slip-deg.
                        Pitch       = ts.getFeatureVal("pitch-deg", timeInDeciSeconds);              // update the pitch-deg.
                        if (writer.CanWrite)
                        {
                            byte[] writeBuffer = Encoding.ASCII.GetBytes(line + "\r\n"); // start writing the given features.
                            writer.Write(writeBuffer, 0, writeBuffer.Length);
                            writer.Flush();
                            // sending data in 10HZ
                            int converToIntSpeed = Convert.ToInt32(100 / Speed);        // this is how we use the speed of the video
                            Thread.Sleep(converToIntSpeed);                             // the sleep method decides the rate we produce the video.
                        }
                        else
                        {
                            Console.WriteLine("Sorry. You cannot send information to Flight Gear right now.");
                        }
                    }
                    else
                    {
                        while (Stop)
                        {
                        }
                        ;                 // so we wont return to the main loop while we are at pause or stop button.
                    }
                }
                writer.Close();
                fg.Close();
            }).Start();
        }