Пример #1
0
        public LasPoint.ClassificationType[] Classify(LasFile file)
        {
            Stopwatch           sw     = Stopwatch.StartNew();
            LasPointDataRecords points = file.LasPointDataRecords;

            LasPoint.ClassificationType[] output = new LasPoint.ClassificationType[points.Count];
            Statistics stats = new Statistics();

            stats.Count = points.Count;
            for (int i = 0; i < points.Count; i++)
            {
                LasPoint3Short point   = (LasPoint3Short)points[i];
                double         green   = point.Green - (point.Red + point.Blue) / 2;
                IMLData        classed = Network.Compute(
                    new BasicMLData(new double[] { file.LasHeader.ScaleZ(point.Z), point.Intensity, green }));
                output[i] = Utills.QuickClassess[classed.IndexOfMax()];
                if (output[i] != points[i].Classification)
                {
                    stats.ClassErrors[(int)points[i].Classification]++;
                }
                stats.PredictionMatrix[(int)points[i].Classification, (int)output[i]]++;
                stats.ClassCount[(int)output[i]]++;
                stats.ClassRealCount[(int)points[i].Classification]++;
                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }
            }
            Console.Write(stats.ToString());
            sw.Stop();
            Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
            stats.SaveMatrixAsCSV();
            return(output);
        }
Пример #2
0
        public LasPoint.ClassificationType[] Classify(LasFile file, int count = 0)
        {
            var sw = Stopwatch.StartNew();
            LasPointDataRecords points = file.LasPointDataRecords;

            if (count == 0 || count > points.Count)
            {
                count = points.Count;
            }
            LasPoint.ClassificationType[] output = new LasPoint.ClassificationType[count];
            Statistics stats = new Statistics();

            stats.Count = count;
            OpenTK.Vector3[] abc = new OpenTK.Vector3[count];
            Parallel.For(0, count, (i) =>
            {
                abc[i] = LinearRegression.ComputeRegressionPoint(file, points[i], regressionCount, regressionRange);
                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }
            });
            for (int i = 0; i < count; i++)
            {
                //double[] regression = LinearRegression.ComputeRegressionNumerics(file, points[i], regressionCount, regressionRange);
                LasPoint3Short point = (LasPoint3Short)points[i];
                //OpenTK.Vector3 abc = LinearRegression.ComputeRegressionPoint(file, points[i], regressionCount, regressionRange);
                double  distanceFromPlane = Utills.DistanceFromPlane(point, abc[i]);
                double  green             = point.Green - (point.Red + point.Blue) / 2;
                IMLData classed           = Network.Compute(new BasicMLData(new double[] { green, file.LasHeader.ScaleZ(point.Z), point.Intensity,
                                                                                           abc[i].X, abc[i].Y, abc[i].Z, distanceFromPlane }));
                output[i] = Utills.QuickClassess[classed.IndexOfMax()];
                if (output[i] != points[i].Classification)
                {
                    stats.ClassErrors[(int)points[i].Classification]++;
                }
                stats.ClassCount[(int)output[i]]++;
                stats.ClassRealCount[(int)points[i].Classification]++;
                stats.PredictionMatrix[(int)points[i].Classification, (int)output[i]]++;
                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }
            }
            Console.Write(stats.ToString());
            sw.Stop();
            Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
            stats.SaveMatrixAsCSV();
            return(output);
        }
        public LasPoint.ClassificationType[] Classify(LasFile file)
        {
            var sw = Stopwatch.StartNew();
            LasPointDataRecords points = file.LasPointDataRecords;
            int pointsCount            = points.Count();

            LasPoint.ClassificationType[] output = new LasPoint.ClassificationType[pointsCount];
            Statistics stats = new Statistics();

            stats.Count = pointsCount;
            OpenTK.Vector3[] slopeVector = new OpenTK.Vector3[pointsCount];

            Parallel.For(0, pointsCount, (i) =>
            {
                slopeVector[i] = LinearRegression.ComputeRegressionPoint(file, points[i], regressionCount, regressionRange);
                if (i % 1000 == 0)
                {
                    Console.WriteLine("ComputeRegression " + i);
                }
            });

            for (int i = 0; i < pointsCount; i++)
            {
                LasPoint3Short point             = (LasPoint3Short)points[i];
                double         distanceFromPlane = Utills.DistanceFromPlane(point, slopeVector[i]);
                double         green             = point.Green - (point.Red + point.Blue) / 2;

                output[i] = Utills.ClassificationClasses[knn.Compute(new double[] { green,
                                                                                    file.LasHeader.ScaleZ(point.Z), point.Intensity, slopeVector[i].X,
                                                                                    slopeVector[i].Y, slopeVector[i].Z, distanceFromPlane })];

                if (output[i] != points[i].Classification)
                {
                    stats.ClassErrors[(int)points[i].Classification]++;
                }
                stats.ClassCount[(int)output[i]]++;
                stats.ClassRealCount[(int)points[i].Classification]++;
                stats.PredictionMatrix[(int)points[i].Classification, (int)output[i]]++;
                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }
            }
            Console.Write(stats.ToString());
            sw.Stop();
            Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
            stats.SaveMatrixAsCSV();
            return(output);
        }
Пример #4
0
        public EncogNeuralNetworkSlow(LasFile file)
        {
            var sw    = Stopwatch.StartNew();
            int count = 300000;
            LasPointDataRecords points = file.LasPointDataRecords;

            double[][] input         = new double[count][];
            double[][] ideal         = new double[count][];
            int        waterCount    = 0;
            int        groundCount   = 0;
            int        lowCount      = 0;
            int        mediumCount   = 0;
            int        highCount     = 0;
            int        buildingCount = 0;

            for (int i = 0; i < count; i++)
            {
                int rndNumber;
                while (true)
                {
                    rndNumber = _rnd.Next(0, points.Count - 1);
                    if (points[rndNumber].Classification == LasPoint.ClassificationType.Water)
                    {
                        waterCount++;
                        if (waterCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.Ground)
                    {
                        groundCount++;
                        if (groundCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.Building)
                    {
                        buildingCount++;
                        if (buildingCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.LowVegetation)
                    {
                        lowCount++;
                        if (lowCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.MediumVegetation)
                    {
                        mediumCount++;
                        if (mediumCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.HighVegetation)
                    {
                        highCount++;
                        if (highCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    if (highCount > 5 * count)
                    {
                        highCount = 0;
                    }
                    if (buildingCount > 5 * count)
                    {
                        buildingCount = 0;
                    }
                    if (lowCount > 5 * count)
                    {
                        lowCount = 0;
                    }
                    if (mediumCount > 5 * count)
                    {
                        mediumCount = 0;
                    }
                    if (waterCount > 5 * count)
                    {
                        waterCount = 0;
                    }
                    if (groundCount > 5 * count)
                    {
                        groundCount = 0;
                    }
                }
                if (i % 1000 == 0)
                {
                    Console.WriteLine("Selected point: " + i + "/" + count);
                }
                //double[] regression = LinearRegression.ComputeRegressionNumerics(file, points[rndNumber], regressionCount, regressionRange);
                OpenTK.Vector3 abc               = LinearRegression.ComputeRegressionPoint(file, points[rndNumber], regressionCount, regressionRange);
                LasPoint3Short point             = (LasPoint3Short)points[rndNumber];
                double         distanceFromPlane = Utills.DistanceFromPlane(point, abc);
                double         green             = point.Green - (point.Red + point.Blue) / 2;
                input[i] = new double[] { green, file.LasHeader.ScaleZ(point.Z), point.Intensity, abc.X, abc.Y, abc.Z, distanceFromPlane };
                ideal[i] = Utills.ClassToVector(point.Classification);
            }
            inputNumber = input[0].Length;
            init();

            IMLDataSet trainingSet = new BasicMLDataSet(input, ideal);
            IMLTrain   train       = new ResilientPropagation(Network, trainingSet);
            int        epoch       = 1;

            do
            {
                train.Iteration();
                Console.WriteLine("Train error: " + train.Error + ", iteration: " + epoch);
                epoch++;
            } while (epoch < 1000);
            LearningError = train.Error;
            train.FinishTraining();
            sw.Stop();
            Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
        }
Пример #5
0
        public EncogNeuralNetwork(LasFile file)
        {
            Stopwatch           sw     = Stopwatch.StartNew();
            int                 count  = 300000;
            LasPointDataRecords points = file.LasPointDataRecords;

            double[][] input         = new double[count][];
            double[][] ideal         = new double[count][];
            int        waterCount    = 0;
            int        groundCount   = 0;
            int        lowCount      = 0;
            int        mediumCount   = 0;
            int        highCount     = 0;
            int        buildingCount = 0;

            for (int i = 0; i < count; i++)
            {
                int rndNumber;
                while (true)
                {
                    rndNumber = _rnd.Next(0, points.Count - 1);
                    if (points[rndNumber].Classification == LasPoint.ClassificationType.Water)
                    {
                        waterCount++;
                        if (waterCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.Ground)
                    {
                        groundCount++;
                        if (groundCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.Building)
                    {
                        buildingCount++;
                        if (buildingCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.LowVegetation)
                    {
                        lowCount++;
                        if (lowCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.MediumVegetation)
                    {
                        mediumCount++;
                        if (mediumCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (points[rndNumber].Classification == LasPoint.ClassificationType.HighVegetation)
                    {
                        highCount++;
                        if (highCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    if (highCount > 5 * count)
                    {
                        highCount = 0;
                    }
                    if (buildingCount > 5 * count)
                    {
                        buildingCount = 0;
                    }
                    if (lowCount > 5 * count)
                    {
                        lowCount = 0;
                    }
                    if (mediumCount > 5 * count)
                    {
                        mediumCount = 0;
                    }
                    if (waterCount > 5 * count)
                    {
                        waterCount = 0;
                    }
                    if (groundCount > 5 * count)
                    {
                        groundCount = 0;
                    }
                }
                if (i % 100 == 0)
                {
                    Console.WriteLine(i);
                }
                LasPoint3Short point = (LasPoint3Short)points[rndNumber];
                double         green = point.Green - (point.Red + point.Blue) / 2;
                input[i] = new double[] { file.LasHeader.ScaleZ(point.Z), point.Intensity, green };
                ideal[i] = Utills.ClassToVector(point.Classification);
            }
            inputNumber = input[0].Length;
            init();

            IMLDataSet trainingSet = new BasicMLDataSet(input, ideal);
            IMLTrain   train       = new ResilientPropagation(Network, trainingSet);
            int        epoch       = 1;

            do
            {
                train.Iteration();
                Console.WriteLine(train.Error + " | " + epoch);
                epoch++;
            } while (epoch < 1000);
            LearningError = train.Error;
            train.FinishTraining();
            sw.Stop();
            Console.WriteLine("Czas trwania [" + sw.Elapsed.TotalSeconds.ToString() + "s]");
        }
        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);
        }
Пример #7
0
        public static List <LasPoint> GenerateClassArray(LasPointDataRecords points, double percentToTrain)
        {
            Console.WriteLine("Generationg Class Arrays in progress");

            return(points.GetRandomPointsByClass(ClassificationClasses, percentToTrain));
        }