[7128] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization.Operators;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
|
---|
| 33 |
|
---|
| 34 | [StorableClass]
|
---|
| 35 | public class RuggednessAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
|
---|
[7176] | 36 | public bool EnabledByDefault {
|
---|
| 37 | get { return false; }
|
---|
| 38 | }
|
---|
[7128] | 39 |
|
---|
| 40 | #region Parameters
|
---|
| 41 | public LookupParameter<DataTable> QualityTrailParameter {
|
---|
| 42 | get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
|
---|
| 43 | }
|
---|
| 44 | public LookupParameter<DataTable> CorrelationLengthTableParameter {
|
---|
| 45 | get { return (LookupParameter<DataTable>)Parameters["CorrelationLengthTable"]; }
|
---|
| 46 | }
|
---|
| 47 | public LookupParameter<AutoCorrelationTable> AutocorrelationParameter {
|
---|
| 48 | get { return (LookupParameter<AutoCorrelationTable>)Parameters["Autocorrelation"]; }
|
---|
| 49 | }
|
---|
| 50 | public LookupParameter<VariableCollection> ResultsParameter {
|
---|
| 51 | get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
| 52 | }
|
---|
| 53 | public LookupParameter<DoubleValue> AutoCorrelation1Parameter {
|
---|
| 54 | get { return (LookupParameter<DoubleValue>)Parameters["AutoCorrelation1"]; }
|
---|
| 55 | }
|
---|
| 56 | public LookupParameter<IntValue> CorrelationLengthParameter {
|
---|
| 57 | get { return (LookupParameter<IntValue>)Parameters["CorrelationLength"]; }
|
---|
| 58 | }
|
---|
| 59 | #endregion
|
---|
| 60 |
|
---|
| 61 | [StorableConstructor]
|
---|
| 62 | protected RuggednessAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 63 | protected RuggednessAnalyzer(RuggednessAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 64 |
|
---|
| 65 | public RuggednessAnalyzer() {
|
---|
| 66 | Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution"));
|
---|
| 67 | Parameters.Add(new LookupParameter<DataTable>("CorrelationLengthTable", "Maximum nr of steps between statistically significantly correlated quality values"));
|
---|
| 68 | Parameters.Add(new LookupParameter<AutoCorrelationTable>("Autocorrelation", "Autocorrelation function of successive quality values"));
|
---|
| 69 | Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
|
---|
| 70 | Parameters.Add(new LookupParameter<DoubleValue>("AutoCorrelation1", "Autocorrelation for one mutation step."));
|
---|
| 71 | Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "The correlation length."));
|
---|
| 72 |
|
---|
| 73 | var resultsCollector = new ResultsCollector();
|
---|
| 74 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(CorrelationLengthTableParameter.Name));
|
---|
| 75 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(AutocorrelationParameter.Name));
|
---|
| 76 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(AutoCorrelation1Parameter.Name));
|
---|
| 77 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(CorrelationLengthParameter.Name));
|
---|
| 78 |
|
---|
| 79 | OperatorGraph.InitialOperator = resultsCollector;
|
---|
| 80 | resultsCollector.Successor = null;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 84 | return new RuggednessAnalyzer(this, cloner);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public override IOperation Apply() {
|
---|
| 88 | DataTable correlationLengthTable = GetOrCreateCorrelationLengthTable();
|
---|
| 89 | AutoCorrelationTable autocorrelationTable = GetOrCreateAutoCorrelationTable();
|
---|
| 90 | DataTable qualityTrail = QualityTrailParameter.ActualValue;
|
---|
| 91 | if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
|
---|
| 92 | double[] autocorrelationValues;
|
---|
| 93 | int correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues);
|
---|
| 94 | correlationLengthTable.Rows["Correlation Length"].Values.Add(correlationLength);
|
---|
| 95 | autocorrelationTable.Rows["Auto Correlation"].Values.Clear();
|
---|
| 96 | autocorrelationTable.Rows["Auto Correlation"].Values.AddRange(autocorrelationValues);
|
---|
| 97 | CorrelationLengthParameter.ActualValue = new IntValue(correlationLength);
|
---|
| 98 | AutoCorrelation1Parameter.ActualValue = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0);
|
---|
| 99 | }
|
---|
| 100 | return base.Apply();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | private AutoCorrelationTable GetOrCreateAutoCorrelationTable() {
|
---|
| 104 | AutoCorrelationTable autocorrelationTable = AutocorrelationParameter.ActualValue;
|
---|
| 105 | if (autocorrelationTable == null) {
|
---|
| 106 | autocorrelationTable = new AutoCorrelationTable("Auto Correlation");
|
---|
| 107 | AutocorrelationParameter.ActualValue = autocorrelationTable;
|
---|
| 108 | var row = new DataRow("Auto Correlation");
|
---|
| 109 | row.VisualProperties.StartIndexZero = true;
|
---|
| 110 | autocorrelationTable.Rows.Add(row);
|
---|
| 111 | }
|
---|
| 112 | return autocorrelationTable;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | private DataTable GetOrCreateCorrelationLengthTable() {
|
---|
| 116 | DataTable correlationLengthTable = CorrelationLengthTableParameter.ActualValue;
|
---|
| 117 | if (correlationLengthTable == null) {
|
---|
| 118 | correlationLengthTable = new DataTable("Correlation Length");
|
---|
| 119 | CorrelationLengthTableParameter.ActualValue = correlationLengthTable;
|
---|
| 120 | correlationLengthTable.Rows.Add(new DataRow("Correlation Length"));
|
---|
| 121 | }
|
---|
| 122 | return correlationLengthTable;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|