Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10268


Ignore:
Timestamp:
12/22/13 13:12:22 (11 years ago)
Author:
gkronber
Message:

#2109 implemented a grammar especially for GE (the grammar is not configured correctly when used in a classic symbolic regression/classification problem).
To use this grammar in a classical symbolic expression problem, first set the grammar in a GEProblem and load the problem instance (this creates the necessary variable symbols).
After this the configured grammar can be dragged onto the grammar parameter of the classical problem.

Location:
branches/GrammaticalEvolution
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/GrammaticalEvolution

    • Property svn:ignore set to
      _ReSharper.HeuristicLab.Problems.GrammaticalEvolution
      *.suo
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution-3.3.csproj

    r10263 r10268  
    222222      <SubType>Code</SubType>
    223223    </Compile>
     224    <Compile Include="Symbolic\GESymbolicExpressionGrammar.cs" />
    224225    <None Include="HeuristicLab.snk" />
    225226    <Compile Include="ArtificialAnt\GEArtificialAntEvaluator.cs" />
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicDataAnalysisProblem.cs

    r10226 r10268  
    8484      get { return (IValueParameter<T>)Parameters[ProblemDataParameterName]; }
    8585    }
    86     public IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter {
    87       get { return (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
     86    public IValueParameter<GESymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
     87      get { return (IValueParameter<GESymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
    8888    }
    8989    public IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
     
    134134    }
    135135
    136     public ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar {
     136    public GESymbolicExpressionGrammar SymbolicExpressionTreeGrammar {
    137137      get { return SymbolicExpressionTreeGrammarParameter.Value; }
    138138      set { SymbolicExpressionTreeGrammarParameter.Value = value; }
     
    174174    [StorableHook(HookType.AfterDeserialization)]
    175175    private void AfterDeserialization() {
    176       if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
    177         Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
    178         ApplyLinearScalingParameter.Hidden = true;
    179 
    180         //it is assumed that for all symbolic regression algorithms linear scaling was set to true
    181         //there is no possibility to determine the previous value of the parameter as it was stored in the evaluator
    182         if (GetType().Name.Contains("SymbolicRegression"))
    183           ApplyLinearScaling.Value = true;
    184       }
    185 
    186176      RegisterEventHandlers();
    187177    }
     
    194184      : base(evaluator, solutionCreator) {
    195185      Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription, problemData));
    196       Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription));
     186      Parameters.Add(new ValueParameter<GESymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription));
    197187      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, SymoblicExpressionTreeInterpreterParameterDescription));
    198188      //Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, MaximumSymbolicExpressionTreeDepthParameterDescription));
     
    213203      ApplyLinearScalingParameter.Hidden = true;
    214204
    215       SymbolicExpressionTreeGrammar = new TypeCoherentExpressionGrammar();
     205      SymbolicExpressionTreeGrammar = new GESymbolicExpressionGrammar(problemData.AllowedInputVariables, problemData.AllowedInputVariables.Count() * 3);
    216206      SymbolicExpressionTreeInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
    217207
     
    225215    }
    226216
     217    private void DeregisterGrammarHandler() {
     218      SymbolicExpressionTreeGrammarParameter.ValueChanged -= SymbolicExpressionTreeGrammarParameter_ValueChanged;
     219    }
     220    private void RegisterGrammarHandler() {
     221      SymbolicExpressionTreeGrammarParameter.ValueChanged += SymbolicExpressionTreeGrammarParameter_ValueChanged;
     222    }
     223
    227224    protected virtual void UpdateGrammar() {
    228       //SymbolicExpressionTreeGrammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
    229       //SymbolicExpressionTreeGrammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
    230       foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) {
    231         if (!varSymbol.Fixed) {
    232           varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value);
    233           varSymbol.VariableNames = ProblemData.AllowedInputVariables;
    234         }
    235       }
    236       foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {
    237         if (!varSymbol.Fixed) {
    238           varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value);
    239           varSymbol.VariableNames = ProblemData.AllowedInputVariables;
    240         }
    241       }
     225      DeregisterGrammarHandler();
     226      // create a new grammar instance with the correct allowed input variables
     227      SymbolicExpressionTreeGrammarParameter.Value =
     228        new GESymbolicExpressionGrammar(ProblemData.AllowedInputVariables, ProblemData.AllowedInputVariables.Count() * 3);
     229      RegisterGrammarHandler();
    242230    }
    243231
     
    257245      ProblemDataParameter.Value.Changed += (object sender, EventArgs e) => OnProblemDataChanged();
    258246
    259       SymbolicExpressionTreeGrammarParameter.ValueChanged += new EventHandler(SymbolicExpressionTreeGrammarParameter_ValueChanged);
     247      RegisterGrammarHandler();
    260248
    261249      //MaximumFunctionArguments.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
     
    272260
    273261    private void SymbolicExpressionTreeGrammarParameter_ValueChanged(object sender, EventArgs e) {
    274       UpdateGrammar();
    275     }
    276 
    277     private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) {
    278262      UpdateGrammar();
    279263    }
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/GESymbolicRegressionSingleObjectiveProblem.cs

    r10263 r10268  
    7373
    7474      RegisterEventHandlers();
    75       ConfigureGrammarSymbols();
    7675      InitializeOperators();
    7776      UpdateEstimationLimits();
     
    8483
    8584    private void RegisterEventHandlers() {
    86       SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
     85      // nothing to do
    8786    }
    8887
    89     private void ConfigureGrammarSymbols() {
    90       var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar;
    91       if (grammar != null) grammar.ConfigureAsDefaultRegressionGrammar();
    92     }
    9388
    9489    private void InitializeOperators() {
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Symbolic/IGESymbolicDataAnalysisProblem.cs

    r10226 r10268  
    2323using HeuristicLab.Data;
    2424using HeuristicLab.Optimization;
     25using HeuristicLab.Problems.DataAnalysis;
     26using HeuristicLab.Problems.DataAnalysis.Symbolic;
     27using HeuristicLab.Problems.GrammaticalEvolution;
    2528
    26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     29namespace HeuristicLab.Problems.GrammaticalEvolution {
    2730  public interface IGESymbolicDataAnalysisProblem : IDataAnalysisProblem, IHeuristicOptimizationProblem {
    28     IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { get; }
     31    IValueParameter<GESymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter { get; }
    2932    IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; }
    3033    //IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { get; }
     
    3639    IFixedValueParameter<IntRange> ValidationPartitionParameter { get; }
    3740
    38     ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar { get; set; }
     41    GESymbolicExpressionGrammar SymbolicExpressionTreeGrammar { get; set; }
    3942    ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { get; set; }
    4043    //IntValue MaximumSymbolicExpressionTreeDepth { get; }
Note: See TracChangeset for help on using the changeset viewer.