Changeset 10230


Ignore:
Timestamp:
12/16/13 16:11:31 (6 years ago)
Author:
mkommend
Message:

#1997: Updated symbolic island algorithm evaluators and added automatic wiring of evaluators.

Location:
branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/ConsecutiveSamplesEvaluator.cs

    r10178 r10230  
    4747    private const string MaximumIterationsParameterName = "Maximum Iterations";
    4848
    49 
    5049    #region parameter properties
    5150    public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
     
    5958    }
    6059    public ILookupParameter<IntRange> FitnessCalculationPartitionParameter {
    61       get { return (IValueLookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; }
     60      get { return (ILookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; }
    6261    }
    6362    public ILookupParameter<IntRange> FixedSamplesPartitionParameter {
     
    128127      var fixedSamples = FixedSamplesPartitionParameter.ActualValue;
    129128
    130       //create fixed rows enumerable
    131       var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);
    132       //create consecutive rows enumerable
    133       if (ConsecutiveSamples > 0) {
    134         var dataMigrationInterval = DataMigrationIntervalParameter.ActualValue.Value;
    135         var islandIndex = IslandIndexParameter.ActualValue.Value;
    136         var generation = IterationsParameter.ActualValue.Value;
    137         var iteration = islandIndex + (generation / dataMigrationInterval);
    138         var consecutiveRows = GenerateRows(samples, fixedSamples, ConsecutiveSamples, Overlap, iteration);
    139         rows = rows.Concat(consecutiveRows);
     129      var dataMigrationInterval = DataMigrationIntervalParameter.ActualValue.Value;
     130      var generationValue = IterationsParameter.ActualValue;
     131      var generation = generationValue == null ? 0 : generationValue.Value;
     132
     133      //calculat new rows for evaluation
     134      if (generation % dataMigrationInterval == 0) {
     135        //create fixed rows enumerable
     136        var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);
     137        //create consecutive rows enumerable
     138        if (ConsecutiveSamples > 0) {
     139          var islandIndex = IslandIndexParameter.ActualValue.Value;
     140          var iteration = islandIndex + (generation / dataMigrationInterval);
     141          var consecutiveRows = GenerateRows(samples, fixedSamples, ConsecutiveSamples, Overlap, iteration);
     142          rows = rows.Concat(consecutiveRows);
     143        }
     144        //filter out test rows
     145        rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
     146
     147        //TODO change to lookup parameter
     148        ExecutionContext.Scope.Variables.Remove("Rows");
     149        ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
    140150      }
    141       //filter out test rows
    142       rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
    143151
    144       //execution context is created manually to be able to clear the rows parameter easily
    145152      var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope);
    146 
    147       //TODO change to lookup parameter
    148       executionContext.Scope.Variables.Remove("Rows");
    149       executionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
    150153      var successor = evaluator.Execute(executionContext, this.CancellationToken);
    151154      return new OperationCollection(successor, base.Apply());
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/ISymbolicDataAnalysisIslandAlgorithmEvaluator .cs

    r10177 r10230  
    2020#endregion
    2121
     22using HeuristicLab.Core;
     23using HeuristicLab.Data;
    2224using HeuristicLab.Optimization;
    2325
    2426namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic {
    25   public interface ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator : ISingleObjectiveEvaluator {
     27  public interface ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator : ISingleObjectiveEvaluator, IIterationBasedOperator {
     28    IValueLookupParameter<IntValue> DataMigrationIntervalParameter { get; }
    2629  }
    2730}
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/RandomSamplesEvaluator .cs

    r10177 r10230  
    4141    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    4242    private const string FixedSamplesPartitionParameterName = "FixedSamplesPartition";
     43    private const string DataMigrationIntervalParameterName = "DataMigrationInterval";
    4344    private const string RandomSamplesParameterName = "RandomSamples";
     45    private const string IterationsParameterName = "Iterations";
     46    private const string MaximumIterationsParameterName = "Maximum Iterations";
    4447
    4548    #region parameter properties
     
    6265      get { return (ILookupParameter<IntRange>)Parameters[FixedSamplesPartitionParameterName]; }
    6366    }
     67    public IValueLookupParameter<IntValue> DataMigrationIntervalParameter {
     68      get { return (IValueLookupParameter<IntValue>)Parameters[DataMigrationIntervalParameterName]; }
     69    }
    6470    public IFixedValueParameter<IntValue> RandomSamplesParameter {
    6571      get { return (IFixedValueParameter<IntValue>)Parameters[RandomSamplesParameterName]; }
     72    }
     73    public ILookupParameter<IntValue> IterationsParameter {
     74      get { return (ILookupParameter<IntValue>)Parameters[IterationsParameterName]; }
     75    }
     76    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     77      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsParameterName]; }
    6678    }
    6779    #endregion
     
    93105      Parameters.Add(new LookupParameter<IntRange>(FixedSamplesPartitionParameterName, "The data partition which is used to calculate the fitness on the fixed samples."));
    94106      Parameters.Add(new FixedValueParameter<IntValue>(RandomSamplesParameterName, "The number of random samples used for fitness calculation in each island.", new IntValue()));
     107      Parameters.Add(new ValueLookupParameter<IntValue>(DataMigrationIntervalParameterName, "The number of generations that should pass between data migration phases."));
     108      Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The number of performed iterations."));
     109      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true });
    95110    }
    96111
     
    103118      var randomSamples = RandomSamples;
    104119
    105       //create fixed rows enumerable
    106       var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);
    107       //create randomly chosen rows enumerable
    108       if (randomSamples > 0) {
    109         if (randomSamples > samples.Size - fixedSamples.Size) {
    110           var error = string.Format("Could not select {0} random samples, because there are {1} total samples present from which {2} where used in the fixed partition. Please lower the number of random samples in the algorithm configuration.", randomSamples, samples.Size, fixedSamples.Size);
    111           throw new OperatorExecutionException(this, error);
     120      var dataMigrationInterval = DataMigrationIntervalParameter.ActualValue.Value;
     121      var generationValue = IterationsParameter.ActualValue;
     122      var generation = generationValue == null ? 0 : generationValue.Value;
     123
     124      //calculat new rows for evaluation
     125      if (generation % dataMigrationInterval == 0) {
     126        //create fixed rows enumerable
     127        var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);
     128        //create randomly chosen rows enumerable
     129        if (randomSamples > 0) {
     130          if (randomSamples > samples.Size - fixedSamples.Size) {
     131            var error = string.Format("Could not select {0} random samples, because there are {1} total samples present from which {2} where used in the fixed partition. Please lower the number of random samples in the algorithm configuration.", randomSamples, samples.Size, fixedSamples.Size);
     132            throw new OperatorExecutionException(this, error);
     133          }
     134          var randomRows = Enumerable.Range(samples.Start, samples.Size).Where(r => r < fixedSamples.Start || r >= fixedSamples.End);
     135          randomRows = randomRows.SampleRandomWithoutRepetition(RandomParameter.ActualValue, randomSamples, samples.Size - fixedSamples.Size);
     136
     137          rows = rows.Concat(randomRows);
    112138        }
    113         var randomRows = Enumerable.Range(samples.Start, samples.Size).Where(r => r < fixedSamples.Start || r >= fixedSamples.End);
    114         randomRows = randomRows.SampleRandomWithoutRepetition(RandomParameter.ActualValue, randomSamples, samples.Size - fixedSamples.Size);
     139        //filter out test rows
     140        rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
     141        ExecutionContext.Scope.Variables.Remove("Rows");
     142        ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
     143      }
    115144
    116         rows = rows.Concat(randomRows);
    117       }
    118       //filter out test rows
    119       rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
    120 
    121       //execution context is created manually to be able to clear the rows parameter easily
    122145      var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope);
    123 
    124       //TODO change to lookup parameter
    125       executionContext.Scope.Variables.Remove("Rows");
    126       executionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
    127146      var successor = evaluator.Execute(executionContext, this.CancellationToken);
    128147      return new OperationCollection(successor, base.Apply());
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandGeneticAlgorithm.cs

    r10177 r10230  
    132132      FixedSamplesParameter.Value.ValueChanged += (o, e) => {
    133133        RecalculateFixedSamplesPartitions();
    134         ReevaluateImmigrants = FixedSamples >= Problem.FitnessCalculationPartition.Size;
     134        ReevaluateImmigrants = FixedSamples < Problem.FitnessCalculationPartition.Size;
    135135      };
    136136      Analyzer.Operators.PropertyChanged += (o, e) => ParameterizeAnalyzers();
     
    162162    private void ParameterizeEvaluator() {
    163163      var evaluator = EvaluatorParameter.Value;
    164 
    165       var randomEvaluator = evaluator as RandomSamplesEvaluator;
    166       if (randomEvaluator != null) {
    167         ReevaluteElites = randomEvaluator.RandomSamples != 0;
    168       }
    169 
    170       var consecutiveEvaluator = evaluator as ConsecutiveSamplesEvaluator;
    171       if (consecutiveEvaluator != null) {
    172         consecutiveEvaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
    173       }
     164      evaluator.IterationsParameter.ActualName = "Generations";
     165      evaluator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
     166      evaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
     167
     168      ParameterizeStochasticOperatorForIsland(evaluator);
    174169    }
    175170
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/SymbolicDataAnalysisIslandOffspringSelectionGeneticAlgorithm.cs

    r10177 r10230  
    128128      FixedSamplesParameter.Value.ValueChanged += (o, e) => {
    129129        RecalculateFixedSamplesPartitions();
    130         ReevaluateImmigrants = FixedSamples >= Problem.FitnessCalculationPartition.Size;
     130        ReevaluateImmigrants = FixedSamples < Problem.FitnessCalculationPartition.Size;
    131131      };
    132132      Analyzer.Operators.PropertyChanged += (o, e) => ParameterizeAnalyzers();
     
    158158    private void ParameterizeEvaluator() {
    159159      var evaluator = EvaluatorParameter.Value;
    160 
    161       var randomEvaluator = evaluator as RandomSamplesEvaluator;
    162       if (randomEvaluator != null) {
    163         ReevaluteElites = randomEvaluator.RandomSamples != 0;
    164       }
    165 
    166       var consecutiveEvaluator = evaluator as ConsecutiveSamplesEvaluator;
    167       if (consecutiveEvaluator != null) {
    168         consecutiveEvaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
    169       }
     160      evaluator.IterationsParameter.ActualName = "Generations";
     161      evaluator.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
     162      evaluator.DataMigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
     163
     164      ParameterizeStochasticOperator(evaluator);
    170165    }
    171166
Note: See TracChangeset for help on using the changeset viewer.