Exemple #1
0
        public ClassificationType[,] Classify(LasFile file)
        {
            var sw = Stopwatch.StartNew();

            ClassificationType[,] output = new ClassificationType[_divisionCountX, _divisionCountY];
            SubgroupOfPoints[,] values   = Utills.GroupPoints(file, _divisionCountX, _divisionCountY);
            Statistics stats = new Statistics();

            stats.Count = _divisionCountX * _divisionCountY;
            for (int i = 0; i < _divisionCountX; i++)
            {
                for (int j = 0; j < _divisionCountY; j++)
                {
                    double         avgHeight    = values[i, j].avgHeight;
                    double         avgIntensity = values[i, j].avgIntensity;
                    double         avgDistance  = values[i, j].avgDistance;
                    OpenTK.Vector3 slopeVector  = values[i, j].slopeVector;
                    IMLData        classed      = Network.Compute(new BasicMLData(
                                                                      new double[] { avgDistance, avgHeight, avgIntensity, slopeVector[0], slopeVector[1], slopeVector[2] }));
                    output[i, j] = Utills.QuickClassess[classed.IndexOfMax()];
                    ClassificationType ct;
                    if (!Utills.QuickClassess.TryGetValue(values[i, j].classIndex, out ct))
                    {
                        continue;
                    }
                    if (output[i, j] != ct)
                    {
                        stats.ClassErrors[(int)ct]++;
                    }
                    stats.PredictionMatrix[(int)output[i, j], (int)ct]++;
                    stats.PredictionMatrix[(int)ct, (int)output[i, j]]++;
                    stats.ClassCount[(int)output[i, j]]++;
                    stats.ClassRealCount[(int)ct]++;
                }
                Console.WriteLine(i);
            }
            Console.Write(stats.ToString());
            sw.Stop();
            Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
            stats.SaveMatrixAsCSV();
            return(output);
        }
        public ClassificationType[,] Classify(LasFile file, int divCountX, int divCountY)
        {
            Stopwatch swTotal = Stopwatch.StartNew();
            Stopwatch sw      = Stopwatch.StartNew();

            Console.WriteLine("Preparing testing dataset...");
            LasPointDataRecords points = file.LasPointDataRecords;

            ClassificationType[,] output = new ClassificationType[divCountX, divCountY];
            SubgroupOfPoints[,] values   = Utills.GroupPoints(file, divCountX, divCountY);
            Statistics stats = new Statistics();

            stats.Count = divCountX * divCountY;
            sw.Stop();
            Console.WriteLine("Preparing testing dataset completed [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
            Stopwatch sw2 = Stopwatch.StartNew();

            Console.WriteLine("Classification in progress...");

            int noiseCount = 0;

            for (int i = 0; i < divCountX; i++)
            {
                for (int j = 0; j < divCountY; j++)
                {
                    if (values[i, j].classIndex == 7)
                    {
                        output[i, j] = ClassificationType.Noise;
                        noiseCount++;
                    }
                    else
                    {
                        double         avgHeight    = values[i, j].avgHeight;
                        double         avgIntensity = values[i, j].avgIntensity;
                        double         avgDistance  = values[i, j].avgDistance;
                        OpenTK.Vector3 slopeVector  = values[i, j].slopeVector;

                        output[i, j] = Utills.ClassificationClasses[knn.Compute(new double[] {
                            avgDistance, avgHeight, avgIntensity, slopeVector[0],
                            slopeVector[1], slopeVector[2]
                        })];

                        ClassificationType ct;
                        if (!Utills.QuickClassess.TryGetValue(values[i, j].classIndex, out ct))
                        {
                            continue;
                        }
                        if (output[i, j] != ct)
                        {
                            stats.ClassErrors[(int)ct]++;
                        }
                        stats.PredictionMatrix[(int)output[i, j], (int)ct]++;
                        stats.PredictionMatrix[(int)ct, (int)output[i, j]]++;
                        stats.ClassCount[(int)output[i, j]]++;
                        stats.ClassRealCount[(int)ct]++;
                    }
                }
                //Console.WriteLine(i);
            }
            Console.Write(stats.ToString());
            sw2.Stop();
            Console.WriteLine("Classification completed [" + sw2.Elapsed.TotalSeconds.ToString() + "s]");
            swTotal.Stop();
            Console.WriteLine("Total time: [" + swTotal.Elapsed.TotalSeconds.ToString() + "s]");
            Console.WriteLine("Noise count: " + noiseCount.ToString());
            stats.SaveMatrixAsCSV();
            return(output);
        }