Пример #1
0
        private double?AdjustedRmsZ(Grid2DPhenotype other)
        {
            RegularGrid2D adjusted_grid = AdjustedGrid(other);
            double?       adjustedRmsZ  = grid.RmsDifference(adjusted_grid);

            return(adjustedRmsZ);
        }
Пример #2
0
        public override double[] Compare(Phenotype other)
        {
            Debug.Assert(other is Grid2DPhenotype);
            Grid2DPhenotype otherPhenotype = (Grid2DPhenotype)other;

            return(CompareAdjustedHeight(otherPhenotype));
        }
Пример #3
0
        /// <summary>
        /// Divide the Grids into tiles, and compute the adjusted height fitness
        /// for each tile.
        /// </summary>
        /// <param name="other">The grid to be compared against this.</param>
        /// <returns>An array of tile fitnesses</returns>
        private double[] CompareTiledAdjustedHeight(Grid2DPhenotype other)
        {
            List <double> result        = new List <double>();
            const int     numTilesI     = 2;
            const int     numTilesJ     = 2;
            RegularGrid2D adjusted_grid = AdjustedGrid(other);
            int           tileSizeI     = this.grid.SizeI / numTilesI;
            int           tileSizeJ     = this.grid.SizeJ / numTilesJ;

            for (int tileI = 0; tileI < numTilesI; ++tileI)
            {
                int beginI = tileI * tileSizeI;
                int endI   = (tileI + 1) * tileSizeI;
                for (int tileJ = 0; tileJ < numTilesJ; ++tileJ)
                {
                    int    beginJ       = tileJ * tileSizeJ;
                    int    endJ         = (tileJ + 1) * tileSizeJ;
                    double?adjustedRmsZ = grid.RmsDifference(adjusted_grid, beginI, endI, beginJ, endJ);
                    if (adjustedRmsZ.HasValue)
                    {
                        result.Add(adjustedRmsZ.Value);
                    }
                }
            }
            return(result.ToArray());
        }
Пример #4
0
        private double[] CompareAdjustedHeight(Grid2DPhenotype other)
        {
            double?adjustedRmsZ = AdjustedRmsZ(other);

            Debug.Assert(adjustedRmsZ.HasValue);
            return(new double[] { adjustedRmsZ.Value });
        }
Пример #5
0
        private double[] CompareHeight(Grid2DPhenotype other)
        {
            // Partial derivative comparisons
            double?rmsZ = grid.RmsDifference(other.Grid);

            Debug.Assert(rmsZ.HasValue);
            return(new double[] { rmsZ.Value });
        }
Пример #6
0
        private double[] CompareHeightAndGradients(Grid2DPhenotype other)
        {
            // Partial derivative comparisons
            double?rmsZ    = grid.RmsDifference(other.Grid);
            double?rmsDzDx = RmsGradientI(other);
            double?rmsDzDy = RmsGradientJ(other);

            return(new double[] { rmsZ.Value, rmsDzDx.Value, rmsDzDy.Value });
        }
Пример #7
0
        private double[] CompareAdjustedHeightAndGradients(Grid2DPhenotype other)
        {
            double?adjustedRmsZ = AdjustedRmsZ(other);
            double?rmsGradientI = RmsGradientI(other);
            double?rmsGradientJ = RmsGradientJ(other);

            Debug.Assert(adjustedRmsZ.HasValue);
            Debug.Assert(rmsGradientI.HasValue);
            Debug.Assert(rmsGradientJ.HasValue);
            return(new double[] { adjustedRmsZ.Value, rmsGradientI.Value, rmsGradientJ.Value });
        }
Пример #8
0
        public double RandomHistogramDipAzimuth()
        {
            if (dipAzimuthHistogramGenerator == null)
            {
                Grid2DPhenotype p = (Grid2DPhenotype)Target;
                IRegularGrid2D  g = p.Grid;
                Histogram       dipAzimuthHistogram = g.CreateDipAzimuthHistogram(24);
                dipAzimuthHistogramGenerator = new ContinuousHistogramGenerator(dipAzimuthHistogram);
            }
            double value = dipAzimuthHistogramGenerator.NextDouble();

            //Console.WriteLine("randomAzimuth = {0}", Angle.RadiansToDegrees(value));
            return(value);
        }
Пример #9
0
        private RegularGrid2D AdjustedGrid(Grid2DPhenotype other)
        {
            double        mean          = grid.Mean();
            double        other_mean    = other.Grid.Mean();
            double        difference    = other_mean - mean;
            RegularGrid2D adjusted_grid = (RegularGrid2D)other.Grid.Clone();

            for (int i = 0; i < adjusted_grid.SizeI; ++i)
            {
                for (int j = 0; j < adjusted_grid.SizeJ; ++j)
                {
                    adjusted_grid[i, j] -= difference;
                }
            }
            return(adjusted_grid);
        }
Пример #10
0
        private static void RecordBest(IRegularGrid2D targetGrid, Population population, int generation, RectangularDomain domain)
        {
            List <Individual> best = population.Best;

            for (int j = 0; j < best.Count; ++j)
            {
                Console.Write("best[{0}] = [", j);
                foreach (double f in best[j].Fitness)
                {
                    Console.Write(f);
                    Console.Write(" ");
                }
                Console.WriteLine("] with {0} genes", best[j].Genome.Count);

                // Express the genome to create a grid
                Individual      bestIndividual = (Individual)best[j].Clone();
                Grid2DPhenotype bestPhenotype  = (Grid2DPhenotype)bestIndividual.Phenome;
                bestPhenotype.Grid.MaskFrom(targetGrid);
                StringBuilder gridFileName = new StringBuilder();
                gridFileName.AppendFormat("evolved_{0}_{1}.grd", generation + 1, j);
                bestPhenotype.Grid.WriteSurfer6BinaryFile(gridFileName.ToString());
                ReportLogger.Instance.Writer.WriteStartElement("Grid");
                ReportLogger.Instance.Writer.WriteStartAttribute("file");
                ReportLogger.Instance.Writer.WriteValue(gridFileName.ToString());
                ReportLogger.Instance.Writer.WriteEndAttribute();
                ReportLogger.Instance.Writer.WriteEndElement();

                // Express the genome to create a fault polygon map
                OutlineMapDomain    mapDomain       = new OutlineMapDomain(domain);
                OutlineMapPhenotype mapPhenotype    = (OutlineMapPhenotype)bestIndividual.Genome.Express(mapDomain);
                StringBuilder       polygonFileName = new StringBuilder();
                polygonFileName.AppendFormat("evolved_{0}_{1}.poly", generation + 1, j);
                using (StreamWriter writer = File.CreateText(polygonFileName.ToString()))
                {
                    writer.Write(mapPhenotype.ToString());
                }
                ReportLogger.Instance.Writer.WriteStartElement("Polygons");
                ReportLogger.Instance.Writer.WriteStartAttribute("file");
                ReportLogger.Instance.Writer.WriteValue(polygonFileName.ToString());
                ReportLogger.Instance.Writer.WriteEndAttribute();
                ReportLogger.Instance.Writer.WriteEndElement();
            }
        }
Пример #11
0
        private double?RmsGradientI(Grid2DPhenotype other)
        {
            double?rmsDzDx = PartialDerivativeIGrid.RmsDifference(other.PartialDerivativeIGrid);

            return(rmsDzDx);
        }