Пример #1
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]");
        }
Пример #2
0
        public EncogNeuralNetworkQuick(LasFile file, int divisionCountX, int divisionCountY)
        {
            var sw = Stopwatch.StartNew();

            _divisionCountX = divisionCountX;
            _divisionCountY = divisionCountY;

            var groupPointList = Utills.GroupPointsList(file, _divisionCountX, _divisionCountY);
            int count          = groupPointList.Count / 5;

            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;
                ClassificationType simpleClass;
                while (true)
                {
                    rndNumber = _rnd.Next(0, groupPointList.Count - 1);
                    if (!Utills.QuickClassess.TryGetValue(groupPointList[rndNumber].classIndex, out simpleClass))
                    {
                        continue;
                    }
                    if (simpleClass == LasPoint.ClassificationType.Water)
                    {
                        waterCount++;
                        if (waterCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (simpleClass == LasPoint.ClassificationType.Ground)
                    {
                        groundCount++;
                        if (groundCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (simpleClass == LasPoint.ClassificationType.Building)
                    {
                        buildingCount++;
                        if (buildingCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (simpleClass == LasPoint.ClassificationType.LowVegetation)
                    {
                        lowCount++;
                        if (lowCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (simpleClass == LasPoint.ClassificationType.MediumVegetation)
                    {
                        mediumCount++;
                        if (mediumCount - 25 < count / 6)
                        {
                            break;
                        }
                    }
                    else if (simpleClass == 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);
                }

                double         avgHeight    = groupPointList[rndNumber].avgHeight;
                double         avgIntensity = groupPointList[rndNumber].avgIntensity;
                double         avgDistance  = groupPointList[rndNumber].avgDistance;
                OpenTK.Vector3 slopeVector  = groupPointList[rndNumber].slopeVector;
                input[i] = new double[] { avgDistance, avgHeight, avgIntensity, slopeVector[0], slopeVector[1], slopeVector[2] };
                ideal[i] = Utills.ClassToVector(simpleClass);
            }

            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]");
        }
Пример #3
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]");
        }