Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11026 for trunk


Ignore:
Timestamp:
06/18/14 16:55:14 (10 years ago)
Author:
bburlacu
Message:

#2143:

  • Removed ToArray() calls from SymbolicClassificationPruningOperator.cs and SymbolicRegressionPruningOperator.cs.
  • Changed UpdateCounter, UpdateInterval, PruningProbability, PopulationSliceParameter to FixedValueParameters in SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs.
  • Removed empty operator data member
  • Added parameter descriptions
  • Improved source organization
Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs

    r11025 r11026  
    6868      var classificationModel = (IClassificationModel)model;
    6969      var classificationProblemData = (IClassificationProblemData)ProblemData;
    70       var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size).ToArray();
     70      var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
    7171      var estimatedValues = classificationModel.GetEstimatedClassValues(ProblemData.Dataset, trainingIndices);
    7272      var targetValues = ProblemData.Dataset.GetDoubleValues(classificationProblemData.TargetVariable, trainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r11025 r11026  
    5656      var regressionModel = (IRegressionModel)model;
    5757      var regressionProblemData = (IRegressionProblemData)ProblemData;
    58       var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size).ToArray();
     58      var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
    5959      var estimatedValues = regressionModel.GetEstimatedValues(ProblemData.Dataset, trainingIndices); // also bounds the values
    6060      var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs

    r11025 r11026  
    5858    private DataTableValuesCollector valuesCollector;
    5959    private ResultsCollector resultsCollector;
    60     private EmptyOperator emptyOp;
    6160    #endregion
    6261
     
    7473      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
    7574    }
    76     public IValueParameter<IntValue> UpdateIntervalParameter {
    77       get { return (IValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }
    78     }
    79     public IValueParameter<IntValue> UpdateCounterParameter {
    80       get { return (IValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
    81     }
    82     public IValueParameter<DoubleRange> PopulationSliceParameter {
    83       get { return (IValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; }
    84     }
    85     public IValueParameter<DoubleValue> PruningProbabilityParameter {
    86       get { return (IValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; }
     75    public IFixedValueParameter<IntValue> UpdateIntervalParameter {
     76      get { return (IFixedValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }
     77    }
     78    public IFixedValueParameter<IntValue> UpdateCounterParameter {
     79      get { return (IFixedValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
     80    }
     81    public IFixedValueParameter<DoubleRange> PopulationSliceParameter {
     82      get { return (IFixedValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; }
     83    }
     84    public IFixedValueParameter<DoubleValue> PruningProbabilityParameter {
     85      get { return (IFixedValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; }
    8786    }
    8887    public ILookupParameter<IntValue> PopulationSizeParameter {
     
    9392    #region properties
    9493    protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; } }
    95     protected IntValue UpdateInterval { get { return UpdateIntervalParameter.Value; } }
    96     protected IntValue UpdateCounter { get { return UpdateCounterParameter.Value; } }
    97     protected DoubleRange PopulationSlice { get { return PopulationSliceParameter.Value; } }
    98     protected DoubleValue PruningProbability { get { return PruningProbabilityParameter.Value; } }
     94    protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } }
     95
     96    protected int UpdateCounter {
     97      get { return UpdateCounterParameter.Value.Value; }
     98      set { UpdateCounterParameter.Value.Value = value; }
     99    }
     100
     101    protected double PopulationSliceStart {
     102      get { return PopulationSliceParameter.Value.Start; }
     103      set { PopulationSliceParameter.Value.Start = value; }
     104    }
     105
     106    protected double PopulationSliceEnd {
     107      get { return PopulationSliceParameter.Value.End; }
     108      set { PopulationSliceParameter.Value.End = value; }
     109    }
     110
     111    protected double PruningProbability {
     112      get { return PruningProbabilityParameter.Value.Value; }
     113      set { PruningProbabilityParameter.Value.Value = value; }
     114    }
    99115
    100116    protected bool PruneOnlyZeroImpactNodes {
     
    111127    public override void InitializeState() {
    112128      base.InitializeState();
    113       UpdateCounter.Value = 0;
     129      UpdateCounter = 0;
    114130    }
    115131    public override void ClearState() {
    116132      base.ClearState();
    117       UpdateCounter.Value = 0;
     133      UpdateCounter = 0;
    118134    }
    119135    #endregion
     
    143159    protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer() {
    144160      #region add parameters
    145       Parameters.Add(new ValueParameter<DoubleRange>(PopulationSliceParameterName, new DoubleRange(0.75, 1)));
    146       Parameters.Add(new ValueParameter<DoubleValue>(PruningProbabilityParameterName, new DoubleValue(0.5)));
    147       Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    148       Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called", new IntValue(0)));
    149       Parameters.Add(new LookupParameter<IRandom>(RandomParameterName));
    150       Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName));
    151       Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, new DoubleValue(0.0)));
    152       Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, new BoolValue(false)));
     161      Parameters.Add(new FixedValueParameter<DoubleRange>(PopulationSliceParameterName, "The slice of the population where pruning should be applied.", new DoubleRange(0.75, 1)));
     162      Parameters.Add(new FixedValueParameter<DoubleValue>(PruningProbabilityParameterName, "The probability for pruning an individual.", new DoubleValue(0.5)));
     163      Parameters.Add(new FixedValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
     164      Parameters.Add(new FixedValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called", new IntValue(0)));
     165      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator."));
     166      Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data."));
     167      Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "The impact threshold  below which an individual should be pruned.", new DoubleValue(0.0)));
     168      Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Switch to determine of only zero impact individuals should be pruned.", new BoolValue(false)));
    153169      Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals."));
    154170      #endregion
     
    161177    /// <returns>Returns an int range [start, end]</returns>
    162178    private IntRange GetSliceBounds() {
    163       if (PopulationSlice.Start < 0 || PopulationSlice.End < 0) throw new ArgumentOutOfRangeException("The slice bounds cannot be negative.");
    164       if (PopulationSlice.Start > 1 || PopulationSlice.End > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages.");
     179      if (PopulationSliceStart < 0 || PopulationSliceEnd < 0) throw new ArgumentOutOfRangeException("The slice bounds cannot be negative.");
     180      if (PopulationSliceStart > 1 || PopulationSliceEnd > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages.");
    165181      var count = PopulationSizeParameter.ActualValue.Value;
    166       var start = (int)Math.Round(PopulationSlice.Start * count);
    167       var end = (int)Math.Round(PopulationSlice.End * count);
     182      var start = (int)Math.Round(PopulationSliceStart * count);
     183      var end = (int)Math.Round(PopulationSliceEnd * count);
    168184      if (end > count) end = count;
    169185
     
    173189
    174190    private IOperation CreatePruningOperation() {
    175       var oc = new OperationCollection { Parallel = true };
     191      var operations = new OperationCollection { Parallel = true };
    176192      var range = GetSliceBounds();
    177193      var qualities = Quality.Select(x => x.Value).ToArray();
     
    183199      var random = RandomParameter.ActualValue;
    184200
     201      var empty = new EmptyOperator();
     202
    185203      for (int i = 0; i < subscopes.Count; ++i) {
    186         IOperator op;
    187         if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability.Value)
    188           op = PruningOperator;
    189         else op = emptyOp;
     204        IOperator @operator;
     205        if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability)
     206          @operator = PruningOperator;
     207        else @operator = empty;
    190208        var index = indices[i];
    191209        var subscope = subscopes[index];
    192         oc.Add(ExecutionContext.CreateChildOperation(op, subscope));
     210        operations.Add(ExecutionContext.CreateChildOperation(@operator, subscope));
    193211      }
    194       return oc;
     212      return operations;
    195213    }
    196214
    197215    public override IOperation Apply() {
    198       UpdateCounter.Value++;
    199       if (UpdateCounter.Value != UpdateInterval.Value) return base.Apply();
    200       UpdateCounter.Value = 0;
     216      UpdateCounter++;
     217      if (UpdateCounter != UpdateInterval) return base.Apply();
     218      UpdateCounter = 0;
    201219
    202220      if (prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); }
     
    232250      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Population pruning"));
    233251      resultsCollector.ResultsParameter.ActualName = ResultsParameterName;
    234 
    235       emptyOp = new EmptyOperator();
    236252    }
    237253  }
Note: See TracChangeset for help on using the changeset viewer.