Пример #1
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);
        }
        public static Tuple <double[], int> GetInputOutputFromClassificationType(LasPoint point, LasFile file)
        {
            var            abc = LinearRegression.ComputeRegressionPoint(file, point, regressionCount, regressionRange);
            double         distanceFromPlane = Utills.DistanceFromPlane(point, abc);
            LasPoint3Short pointShort        = (LasPoint3Short)point;
            double         green             = pointShort.Green - (pointShort.Red + pointShort.Blue) / 2;
            var            input             = new double[] { green, file.LasHeader.ScaleZ(point.Z), point.Intensity, abc.X, abc.Y, abc.Z, distanceFromPlane };
            int            output;

            switch (point.Classification)
            {
            case LasPoint.ClassificationType.Ground:
                output = 0;
                break;

            case LasPoint.ClassificationType.HighVegetation:
                output = 1;
                break;

            case LasPoint.ClassificationType.Building:
                output = 2;
                break;

            case LasPoint.ClassificationType.MediumVegetation:
                output = 3;
                break;

            case LasPoint.ClassificationType.LowVegetation:
                output = 4;
                break;

            case LasPoint.ClassificationType.Water:
                output = 5;
                break;

            default:
                input  = new double[] { -1, -1, -1, -1, -1, -1, -1 };
                output = 6;
                break;
            }
            return(Tuple.Create(input, 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]");
        }