Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/02/13 13:18:57 (11 years ago)
Author:
bburlacu
Message:

#1772: Refactoring of directed graph components, added code for correctly serializing vertices and edges. Added specific building blocks analyzers and new population diversity analyzer which correctly integrates with the parallel engine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Analyzers/SymbolicExpressionTreePopulationDiversityAnalyzer.cs

    r9296 r9419  
    4444  public sealed class SymbolicExpressionTreePopulationDiversityAnalyzer : SingleSuccessorOperator, IAnalyzer {
    4545    #region Parameter names
     46    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    4647    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4748    private const string UpdateIntervalParameterName = "UpdateInterval";
     
    5657    private const string SortSubtreesParameterName = "SortSubtrees";
    5758    private const string SimilarityValuesParmeterName = "Similarity";
    58     // population graph
    59     private const string PopulationGraphParameterName = "PopulationGraph";
    6059    // clone map
    6160    private const string GlobalCloneMapParameterName = "GlobalCloneMap";
     
    6463
    6564    #region Parameters
     65    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
     66      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
     67    }
    6668
    6769    public ValueParameter<IntValue> UpdateIntervalParameter {
     
    116118
    117119    #region Parameter properties
     120    public IntValue MaximumSymbolicExpressionTreeDepth {
     121      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     122    }
    118123
    119124    public IntValue UpdateInterval {
     
    164169      Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    165170      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations so far."));
    166       Parameters.Add(new ValueParameter<BoolValue>(MatchVariablesParameterName, "Specify if the symbolic expression tree comparer should match variable names."));
    167       Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specify if the symbolic expression tree comparer should match variable weights."));
    168       Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specify if the symbolic expression tree comparer should match constant values."));
     171      Parameters.Add(new ValueParameter<BoolValue>(MatchVariablesParameterName, "Specify if the symbolic expression tree comparer should match variable names.", new BoolValue(true)));
     172      Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specify if the symbolic expression tree comparer should match variable weights.", new BoolValue(true)));
     173      Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specify if the symbolic expression tree comparer should match constant values.", new BoolValue(true)));
    169174      Parameters.Add(new ValueParameter<BoolValue>(SortSubtreesParameterName, "Specifies whether the subtrees of a tree should be sorted before comparison."));
    170175      Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection)."));
    171176      Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false)));
    172177      Parameters.Add(new LookupParameter<DoubleValue>(SimilarityValuesParmeterName, ""));
     178      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    173179      UpdateCounterParameter.Hidden = true;
    174180      UpdateIntervalParameter.Hidden = true;
     
    177183    [StorableHook(HookType.AfterDeserialization)]
    178184    private void AfterDeserialization() {
     185      if (!Parameters.ContainsKey(MaximumSymbolicExpressionTreeDepthParameterName)) {
     186        Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
     187      }
    179188    }
    180189
    181190    #region IStatefulItem members
    182191    public override void InitializeState() {
     192      UpdateCounter.Value = 0;
    183193      base.InitializeState();
    184       UpdateCounter.Value = 0;
    185     }
    186 
    187     public override void ClearState() {
    188       base.ClearState();
    189       UpdateCounter.Value = 0;
    190194    }
    191195    #endregion
     
    199203        UpdateCounter.Value++;
    200204        if (UpdateCounter.Value != UpdateInterval.Value) return base.Apply();
    201 
    202205        UpdateCounter.Value = 0;
    203206        var trees = SymbolicExpressionTreeParameter.ActualValue.ToList();
     
    208211
    209212        SimilarityParameter.ActualValue = new DoubleValue();
     213        // needed only with the old (and inefficient) geneticitem-based similarity measure
     214        //        var geneticItems = trees.ToDictionary(tree => tree, tree => tree.GetGeneticItems(1, MaximumSymbolicExpressionTreeDepth.Value - 2).ToArray());
    210215
    211216        var comp = new SymbolicExpressionTreeNodeSimilarityComparer {
     
    217222        var operations = new OperationCollection { Parallel = true };
    218223        foreach (var tree in trees) {
    219           var op = new SymbolicDataAnalysisExpressionTreeSimilarityCalculator { CurrentSymbolicExpressionTree = tree, SimilarityComparer = comp };
     224          var op = new SymbolicDataAnalysisExpressionTreeSimilarityCalculator { CurrentSymbolicExpressionTree = tree, SimilarityComparer = comp, MaximumTreeDepth = MaximumSymbolicExpressionTreeDepth.Value };
    220225          var operation = ExecutionContext.CreateChildOperation(op, ExecutionContext.Scope);
    221226          operations.Add(operation);
     
    256261      relativeSelectionCountsTable.Rows["SelectedIndividuals"].Values.Add(relativeSelectionCount);
    257262
    258       // build a selection frequencies histogram
    259       var graph = (SymbolicExpressionTreeGenealogyGraph)results[PopulationGraphParameterName].Value;
    260       // get graph nodes corresponding to individuals of the previous generation
    261       var prevGen = graph.Nodes.Where(node => node.Rank.IsAlmost(Generations.Value - 1)).OrderByDescending(n => n.Quality).ToList();
    262       var frequencies = new double[SymbolicExpressionTreeParameter.ActualValue.Length];
    263       for (int i = 0; i != prevGen.Count; ++i) {
    264         int selFreq = GlobalCloneMap.Values.Count(t => t == prevGen[i].SymbolicExpressionTree);
    265         frequencies[i] = selFreq;
    266       }
    267       DataTable selectionFrequenciesTable;
    268       if (!results.ContainsKey("SelectionFrequencies")) {
    269         selectionFrequenciesTable = new DataTable("Selection Frequencies") { VisualProperties = { YAxisTitle = "Selection Count" } };
    270         results.Add(new Result("SelectionFrequencies", selectionFrequenciesTable));
    271       }
    272       selectionFrequenciesTable = (DataTable)results["SelectionFrequencies"].Value;
    273       DataRow histoRow;
    274       if (!selectionFrequenciesTable.Rows.ContainsKey("SelectionFrequencies")) {
    275         histoRow = new DataRow("SelectionFrequencies") { VisualProperties = { StartIndexZero = true } };
    276         selectionFrequenciesTable.Rows.Add(histoRow);
    277       }
    278       histoRow = selectionFrequenciesTable.Rows["SelectionFrequencies"];
    279       histoRow.Values.Replace(frequencies);
    280 
    281       bool storeHistory = StoreHistory.Value;
    282       if (storeHistory) {
    283         DataTableHistory selectionFrequenciesHistory;
    284         if (!results.ContainsKey("SelectionFrequenciesHistory")) {
    285           selectionFrequenciesHistory = new DataTableHistory();
    286           results.Add(new Result("SelectionFrequenciesHistory", selectionFrequenciesHistory));
    287         }
    288         selectionFrequenciesHistory = (DataTableHistory)results["SelectionFrequenciesHistory"].Value;
    289         selectionFrequenciesHistory.Add((DataTable)selectionFrequenciesTable.Clone());
    290       }
    291263      return base.Apply();
    292264    }
Note: See TracChangeset for help on using the changeset viewer.