Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/14 15:23:47 (10 years ago)
Author:
mkommend
Message:

#1997: Merged trunk changes into data analysis island algorithms branch and fixed bugs in the evaluators.

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

Legend:

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

    r10421 r10579  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    131132      var generation = generationValue == null ? 0 : generationValue.Value;
    132133
    133       //calculat new rows for evaluation
    134       if (dataMigrationInterval != 0 && 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 consecutiveSamples = (int)(ConsecutiveSamples * samples.Size);
    142           var overlap = (int)Overlap * consecutiveSamples;
    143           var consecutiveRows = GenerateRows(samples, fixedSamples, consecutiveSamples, overlap, iteration);
    144           rows = rows.Concat(consecutiveRows);
    145         }
    146         //filter out test rows
    147         rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
     134      if (ConsecutiveSamples > 0 && dataMigrationInterval == 0)
     135        throw new ArgumentException("The data migration interval must not be 0 if consecutive samples are used.");
    148136
    149         //TODO change to lookup parameter
    150         ExecutionContext.Scope.Variables.Remove("Rows");
    151         ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
     137      //create fixed rows enumerable
     138      var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);
     139      //create consecutive rows enumerable
     140      if (ConsecutiveSamples > 0) {
     141        var islandIndex = IslandIndexParameter.ActualValue.Value;
     142        var iteration = islandIndex + (generation / dataMigrationInterval);
     143        var consecutiveSamples = (int)(ConsecutiveSamples * samples.Size);
     144        var overlap = (int)Overlap * consecutiveSamples;
     145        var consecutiveRows = GenerateRows(samples, fixedSamples, consecutiveSamples, overlap, iteration);
     146        rows = rows.Concat(consecutiveRows);
    152147      }
     148      //filter out test rows
     149      rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
     150
     151      //TODO change to lookup parameter
     152      ExecutionContext.Scope.Variables.Remove("Rows");
     153      ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
    153154
    154155      var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope);
  • branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Algorithms.DataAnalysis.Symbolic/3.3/RandomSamplesEvaluator .cs

    r10421 r10579  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Operators;
    27 using HeuristicLab.Optimization;
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3434namespace HeuristicLab.Algorithms.DataAnalysis.Symbolic {
    3535  [StorableClass]
    36   public sealed class RandomSamplesEvaluator : SingleSuccessorOperator, IStochasticOperator, ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator {
    37     private const string RandomParameterName = "Random";
     36  public sealed class RandomSamplesEvaluator : SingleSuccessorOperator, ISymbolicDataAnalysisIslandGeneticAlgorithmEvaluator {
    3837    private const string ProblemDataParameterName = "ProblemData";
    3938    private const string EvaluatorParameterName = "ProblemEvaluator";
     
    4342    private const string DataMigrationIntervalParameterName = "DataMigrationInterval";
    4443    private const string RandomSamplesParameterName = "RandomSamples";
     44    private const string IslandIndexParameterName = "IslandIndex";
    4545    private const string IterationsParameterName = "Iterations";
    4646    private const string MaximumIterationsParameterName = "Maximum Iterations";
    4747
    4848    #region parameter properties
    49     public ILookupParameter<IRandom> RandomParameter {
    50       get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
    51     }
    5249    public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
    5350      get { return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
     
    7067    public IFixedValueParameter<PercentValue> RandomSamplesParameter {
    7168      get { return (IFixedValueParameter<PercentValue>)Parameters[RandomSamplesParameterName]; }
     69    }
     70    public ILookupParameter<IntValue> IslandIndexParameter {
     71      get { return (ILookupParameter<IntValue>)Parameters[IslandIndexParameterName]; }
    7272    }
    7373    public ILookupParameter<IntValue> IterationsParameter {
     
    9898    public RandomSamplesEvaluator()
    9999      : base() {
    100       Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
    101100      Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
    102101      Parameters.Add(new LookupParameter<IOperator>(EvaluatorParameterName, "The evaluator provided by the symbolic data analysis  problem."));
     
    106105      Parameters.Add(new FixedValueParameter<PercentValue>(RandomSamplesParameterName, "The number of random samples used for fitness calculation in each island.", new PercentValue()));
    107106      Parameters.Add(new ValueLookupParameter<IntValue>(DataMigrationIntervalParameterName, "The number of generations that should pass between data migration phases."));
     107      Parameters.Add(new LookupParameter<IntValue>(IslandIndexParameterName, "The index of the current island."));
    108108      Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The number of performed iterations."));
    109109      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true });
     
    122122      var generation = generationValue == null ? 0 : generationValue.Value;
    123123
    124       //calculat new rows for evaluation
    125       if (dataMigrationInterval != 0 && 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);
    136124
    137           rows = rows.Concat(randomRows);
     125      if (randomSamples > 0 && dataMigrationInterval == 0)
     126        throw new ArgumentException("The data migration interval must not be 0 if random samples are used.");
     127
     128      //create fixed rows enumerable
     129      var rows = Enumerable.Range(fixedSamples.Start, fixedSamples.Size);
     130      //create randomly chosen rows enumerable
     131      if (randomSamples > 0) {
     132        var islandIndex = IslandIndexParameter.ActualValue.Value;
     133        var random = new FastRandom(islandIndex + (generation / dataMigrationInterval));
     134
     135        if (randomSamples > samples.Size - fixedSamples.Size) {
     136          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);
     137          throw new OperatorExecutionException(this, error);
    138138        }
    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)));
     139        var randomRows = Enumerable.Range(samples.Start, samples.Size).Where(r => r < fixedSamples.Start || r >= fixedSamples.End);
     140        randomRows = randomRows.SampleRandomWithoutRepetition(random, randomSamples, samples.Size - fixedSamples.Size);
     141        rows = rows.Concat(randomRows);
    143142      }
     143
     144      //filter out test rows       
     145      rows = rows.Where(r => r < problemData.TestPartition.Start || r > problemData.TestPartition.End);
     146      //TODO change to lookup parameter
     147      ExecutionContext.Scope.Variables.Remove("Rows");
     148      ExecutionContext.Scope.Variables.Add(new HeuristicLab.Core.Variable("Rows", new EnumerableItem<int>(rows)));
    144149
    145150      var executionContext = new ExecutionContext(ExecutionContext, evaluator, ExecutionContext.Scope);
Note: See TracChangeset for help on using the changeset viewer.