示例#1
0
        public static void OutputLofBounds(double[] lof_maxTable, double[] lof_minTable, List <double[]> coordinateList)
        {
            double[][] output = RectangularArrays.ReturnRectangularDoubleArray(G.NumPoint, 4);
            double     lofmax = lof_maxTable.Max();
            double     xmax   = 0;

            for (int i = 0; i < G.NumPoint; i++)
            {
                xmax = (xmax < coordinateList[i][0]) ? coordinateList[i][0] : xmax;
            }
            for (int i = 0; i < G.NumPoint; i++)
            {
                // 2次元のみ
                // x, y, width, height
                //var x = (CoordinateList[i][0] - G.IntervalList[i][0]) / xmax * lofmax;
                //var y = lof_minTable[i];
                //var width = 0.005;
                //var height = lof_maxTable[i];
                //output[i][0] = x;
                //output[i][1] = y;
                //output[i][2] = width;
                //output[i][3] = height;
                output[i][0] = coordinateList[i][0];
                output[i][1] = coordinateList[i][1];
                output[i][2] = lof_maxTable[i];
                output[i][3] = lof_minTable[i];
            }
            C.OutputRectanglesAsCsv(G.file_lofbounds, output);
        }
示例#2
0
        public void ComputeAllLOF(List <double[]> CoordinateList)
        {
            lof_Table = new double[G.NumPoint];

            d_Table = RectangularArrays.ReturnRectangularDoubleArray(G.NumPoint, G.NumPoint);
            for (int i = 0; i < G.NumPoint; i++)
            {
                for (int j = 0; j < G.NumPoint; j++)
                {
                    d_Table[i][j] = -1;
                }
            }
            knn_Table = new Dictionary <int, List <int> >();
            for (int i = 0; i < G.NumPoint; i++)
            {
                knn_Table.Add(i, new List <int>());
            }

            for (int id = 0; id < G.NumPoint; id++)
            {
                lof_Table[id] = GetLOF(id, CoordinateList);
            }

            /// Output
            var top_n_outliers = lof_Table.OrderByDescending(x => x).Take(G.TOP_N);

            foreach (var outlier in top_n_outliers)
            {
                Console.WriteLine(outlier);
            }
        }
示例#3
0
 public static void OutputRectangles(List <double[]> coordinateList)
 {
     // Rectangles を CSV 出力
     double[][] output = RectangularArrays.ReturnRectangularDoubleArray(G.NumPoint, 4);
     for (int i = 0; i < G.NumPoint; i++)
     {
         // 2次元のみ
         // x, y, width, height
         var x      = coordinateList[i][0] - G.IntervalList[i][0];
         var y      = coordinateList[i][1] - G.IntervalList[i][1];
         var width  = G.IntervalList[i][0] * 2;
         var height = G.IntervalList[i][1] * 2;
         output[i][0] = x;
         output[i][1] = y;
         output[i][2] = width;
         output[i][3] = height;
     }
     C.OutputRectanglesAsCsv(G.file_rectangles, output);
 }
示例#4
0
        public void ComputeRemainingLOF(List <double[]> CoordinateList)
        {
            lof_Table = new double[G.NumPoint];

            d_Table = RectangularArrays.ReturnRectangularDoubleArray(G.NumPoint, G.NumPoint);
            for (int i = 0; i < G.NumPoint; i++)
            {
                for (int j = 0; j < G.NumPoint; j++)
                {
                    d_Table[i][j] = -1;
                }
            }
            knn_Table = new Dictionary <int, List <int> >();
            for (int i = 0; i < G.NumPoint; i++)
            {
                knn_Table.Add(i, new List <int>());
            }

            foreach (int id in remaining_points)
            {
                lof_Table[id] = GetLOF(id, CoordinateList);
            }

            /// Identify NumNeededPoint

            /*if (G.experimentFlug == false)
             * {
             *  List<int> neededkNNPoints = new List<int>();
             *  List<int> neededTotalPoints = new List<int>();
             *  foreach (int id in remaining_points)
             *  {
             *      /// for the point
             *      if (neededkNNPoints.Contains(id) == false) neededkNNPoints.Add(id); //Console.WriteLine("needed kNN:    {0}", id);
             *      if (neededTotalPoints.Contains(id) == false) neededTotalPoints.Add(id);
             *
             *      /// for the kNN of the point
             *      int numkNN = GetNNCount(id, CoordinateList);
             *      for (int i = 0; i < numkNN; i++)
             *      {
             *          var nn = knn_Table[id][i];
             *          if (neededkNNPoints.Contains(nn) == false) neededkNNPoints.Add(nn); //Console.WriteLine("needed kNN:    {0}", nn);
             *          if (neededTotalPoints.Contains(nn) == false) neededTotalPoints.Add(nn);
             *
             *          int numkNNkNN = GetNNCount(nn, CoordinateList);
             *          for (int j = 0; j < numkNNkNN; j++)
             *          {
             *              var nnnn = knn_Table[nn][j];
             *              if (neededTotalPoints.Contains(nnnn) == false) neededTotalPoints.Add(nnnn); //Console.WriteLine("needed kNNkNN: {0}", nnnn);
             *          }
             *      }
             *  }
             *  G.NumNeededkNNPoint = neededkNNPoints.Count();
             *  G.NumNeededTotalPoint = neededTotalPoints.Count();
             *
             *  //neededkNNPoints.Sort();
             *  //neededTotalPoints.Sort();
             * }*/

            /// Output
            var top_n_outliers = lof_Table.OrderByDescending(x => x).Take(G.TOP_N);

            foreach (var outlier in top_n_outliers)
            {
                Console.WriteLine(outlier);
            }
        }
示例#5
0
        public void ComputeLOFBounds(List <double[]> CoordinateList)
        {
            var sw_1 = C.NewStopwatch(); // sw

            d_maxTable   = RectangularArrays.ReturnRectangularDoubleArray(G.NumPoint, G.NumPoint);
            d_minTable   = RectangularArrays.ReturnRectangularDoubleArray(G.NumPoint, G.NumPoint);
            d_maxSorted  = RectangularArrays.ReturnRectangularIntArray(G.NumPoint, G.NumPoint);
            d_minSorted  = RectangularArrays.ReturnRectangularIntArray(G.NumPoint, G.NumPoint);
            lrd_maxTable = new double[G.NumPoint];
            lrd_minTable = new double[G.NumPoint];
            lof_maxTable = new double[G.NumPoint];
            lof_minTable = new double[G.NumPoint];
            G.StopwatchList[sw_1].Stop(); // sw

            /// Compute Distance Bounds
            var sw_2 = C.NewStopwatch(); // sw

            ComputeDistanceBounds(CoordinateList);
            G.StopwatchList[sw_2].Stop(); // sw

            /// Make arrays sorted by distances for making each point's k nearest neighbor
            var sw_3 = C.NewStopwatch(); // sw

            MakeNNsArray();
            G.StopwatchList[sw_3].Stop(); // sw

            /// Compute Lrd Bounds
            var sw_4 = C.NewStopwatch();  // sw

            ComputeLrdBounds();
            G.StopwatchList[sw_4].Stop(); // sw

            /// Compute LOF Bounds
            var sw_5 = C.NewStopwatch(); // sw

            ComputeLOFBounds();
            G.StopwatchList[sw_5].Stop(); // sw

            /// Output
            //if (G.experimentFlug == false) Console.WriteLine("{0} {1} {2} {3} {4}", C.GetTime(sw_1), C.GetTime(sw_2), C.GetTime(sw_3), C.GetTime(sw_4), C.GetTime(sw_5));

            // LOF 上限下限 を出力
            if (G.experimentFlug == false)
            {
                var lofmax = lof_maxTable.OrderBy(x => x);
                var lofmin = lof_minTable.OrderBy(x => x);
                var lrdmax = lrd_maxTable.OrderBy(x => x);
                var lrdmin = lrd_minTable.OrderBy(x => x);

                Console.WriteLine("------------: Max, Avg, Median, Min");
                Console.WriteLine("lof_maxTable: {0}, {1}, {2}, {3}", lof_maxTable.Max(), lof_maxTable.Average(), lofmax.ToArray()[(G.NumPoint / 2)], lof_maxTable.Min());
                Console.WriteLine("lof_minTable: {0}, {1}, {2}, {3}", lof_minTable.Max(), lof_minTable.Average(), lofmin.ToArray()[(G.NumPoint / 2)], lof_minTable.Min());
                Console.WriteLine("lrd_maxTable: {0}, {1}, {2}, {3}", lrd_maxTable.Max(), lrd_maxTable.Average(), lrdmax.ToArray()[(G.NumPoint / 2)], lrd_maxTable.Min());
                Console.WriteLine("lrd_minTable: {0}, {1}, {2}, {3}", lrd_minTable.Max(), lrd_minTable.Average(), lrdmin.ToArray()[(G.NumPoint / 2)], lrd_minTable.Min());

                using (var sw = new System.IO.StreamWriter(G.file_loflrd_bounds_statistics, true)) /// true 上書き, false 新規作成
                {
                    string outputLine = "";
                    outputLine = "LOF_upper, " + lof_maxTable.Max() + ", " + lof_maxTable.Average() + ", " + lofmax.ToArray()[(G.NumPoint / 2)] + ", " + lof_maxTable.Min();
                    sw.WriteLine("{0}", outputLine);
                    outputLine = "LOF_lower, " + lof_minTable.Max() + ", " + lof_minTable.Average() + ", " + lofmin.ToArray()[(G.NumPoint / 2)] + ", " + lof_minTable.Min();
                    sw.WriteLine("{0}", outputLine);
                    outputLine = "lrd_upper, " + lrd_maxTable.Max() + ", " + lrd_maxTable.Average() + ", " + lrdmax.ToArray()[(G.NumPoint / 2)] + ", " + lrd_maxTable.Min();
                    sw.WriteLine("{0}", outputLine);
                    outputLine = "lrd_lower, " + lrd_minTable.Max() + ", " + lrd_minTable.Average() + ", " + lrdmin.ToArray()[(G.NumPoint / 2)] + ", " + lrd_minTable.Min();
                    sw.WriteLine("{0}", outputLine);
                }
            }
        }