Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6284


Ignore:
Timestamp:
05/25/11 10:50:21 (14 years ago)
Author:
mkommend
Message:

#1479: Created branch for grammar editing.

Location:
branches/GP.Grammar.Editor
Files:
13 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj

    r5809 r6284  
    9393  </PropertyGroup>
    9494  <ItemGroup>
     95    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     96    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     97    <Reference Include="HeuristicLab.Data.Views-3.3">
     98      <HintPath>..\..\HeuristicLab.Data.Views\3.3\bin\Debug\HeuristicLab.Data.Views-3.3.dll</HintPath>
     99    </Reference>
     100    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     101    <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3">
     102      <HintPath>..\..\HeuristicLab.Visualization.ChartControlsExtensions\3.3\bin\Debug\HeuristicLab.Visualization.ChartControlsExtensions-3.3.dll</HintPath>
     103    </Reference>
    95104    <Reference Include="System" />
    96105    <Reference Include="System.Core">
     
    99108    <Reference Include="System.Drawing" />
    100109    <Reference Include="System.Windows.Forms" />
     110    <Reference Include="System.Windows.Forms.DataVisualization" />
    101111    <Reference Include="System.Xml.Linq">
    102112      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    109119  </ItemGroup>
    110120  <ItemGroup>
     121    <Compile Include="SymbolicExpressionGrammarEditorView.cs">
     122      <SubType>UserControl</SubType>
     123    </Compile>
     124    <Compile Include="SymbolicExpressionGrammarEditorView.Designer.cs">
     125      <DependentUpon>SymbolicExpressionGrammarEditorView.cs</DependentUpon>
     126    </Compile>
    111127    <Compile Include="SymbolicExpressionGrammarView.cs">
    112128      <SubType>UserControl</SubType>
     
    171187      <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>
    172188      <Name>HeuristicLab.MainForm-3.3</Name>
     189    </ProjectReference>
     190    <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">
     191      <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>
     192      <Name>HeuristicLab.Optimization.Views-3.3</Name>
    173193    </ProjectReference>
    174194    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
     
    198218      <Install>true</Install>
    199219    </BootstrapperPackage>
     220  </ItemGroup>
     221  <ItemGroup>
     222    <EmbeddedResource Include="SymbolicExpressionGrammarEditorView.resx">
     223      <DependentUpon>SymbolicExpressionGrammarEditorView.cs</DependentUpon>
     224    </EmbeddedResource>
    200225  </ItemGroup>
    201226  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r6233 r6284  
    179179          ReplaceWithMinimalTree(random, root, parent, argumentIndex);
    180180        } else {
    181           var allowedSymbols = (from s in parent.Grammar.Symbols
     181          var allowedSymbols = (from s in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, argumentIndex)
    182182                                where s.InitialFrequency > 0.0
    183                                 where parent.Grammar.IsAllowedChildSymbol(parent.Symbol, s, argumentIndex)
    184                                 where parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1
    185                                 where parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
     183                                where s.Fixed || parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1
     184                                where s.Fixed || parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
    186185                                select s)
    187186                               .ToList();
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r5916 r6284  
    9696      int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0.Parent);
    9797
    98 
    9998      List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>();
    10099      parent1.Root.ForEachNodePostfix((n) => {
    101         if (n.GetLength() <= maxInsertedBranchLength &&
    102           n.GetDepth() <= maxInsertedBranchDepth &&
    103           IsMatchingPointType(crossoverPoint0, n))
     100        if (!n.Symbol.Fixed &&
     101            n.GetLength() <= maxInsertedBranchLength &&
     102            n.GetDepth() <= maxInsertedBranchDepth &&
     103            IsMatchingPointType(crossoverPoint0, n))
    104104          allowedBranches.Add(n);
    105105      });
     
    158158      List<CutPoint> leafCrossoverPoints = new List<CutPoint>();
    159159      parent0.Root.ForEachNodePostfix((n) => {
    160         if (n.Subtrees.Any() && n != parent0.Root) {
     160        if (!n.Symbol.Fixed && n.Subtrees.Any() && n != parent0.Root) {
    161161          foreach (var child in n.Subtrees) {
    162162            if (child.GetLength() <= maxBranchLength &&
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r5809 r6284  
    167167    <Compile Include="Symbols\Argument.cs" />
    168168    <Compile Include="Symbols\ArgumentTreeNode.cs" />
     169    <Compile Include="Symbols\GroupSymbol.cs" />
    169170    <Compile Include="Symbols\StartSymbol.cs" />
    170171    <Compile Include="Symbols\InvokeFunction.cs" />
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbol.cs

    r5809 r6284  
    2727    ISymbolicExpressionTreeNode CreateTreeNode();
    2828    double InitialFrequency { get; set; }
     29    bool Fixed { get; set; }
    2930
    3031    event EventHandler Changed;
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r6233 r6284  
    3535    bool ReadOnly { get; set; }
    3636    event EventHandler ReadOnlyChanged;
     37
     38    void AddSymbol(ISymbol symbol);
     39    void RemoveSymbol(ISymbol symbol);
     40
     41    void AddAllowedChildSymbol(ISymbol parent, ISymbol child);
     42    void AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
     43    void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child);
     44    void RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex);
     45
     46    void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount);
    3747  }
    3848}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammarBase.cs

    r5809 r6284  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Core;
     
    4142    int GetMaximumExpressionLength(ISymbol start);
    4243    int GetMinimumExpressionDepth(ISymbol start);
     44
     45    event EventHandler Changed;
    4346  }
    4447}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs

    r6233 r6284  
    160160    }
    161161
    162     #region IStatefulItem
     162    #region IStatefulItem methods
    163163    void IStatefulItem.InitializeState() { }
    164164    void IStatefulItem.ClearState() {
     
    166166    }
    167167    #endregion
     168
     169    #region ISymbolicExpressionGrammar methods
     170    void ISymbolicExpressionGrammar.AddSymbol(ISymbol symbol) {
     171      if (ReadOnly) throw new InvalidOperationException();
     172      base.AddSymbol(symbol);
     173    }
     174    void ISymbolicExpressionGrammar.RemoveSymbol(ISymbol symbol) {
     175      if (ReadOnly) throw new InvalidOperationException();
     176      base.RemoveSymbol(symbol);
     177    }
     178
     179    void ISymbolicExpressionGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child) {
     180      if (ReadOnly) throw new InvalidOperationException();
     181      base.AddAllowedChildSymbol(parent, child);
     182    }
     183    void ISymbolicExpressionGrammar.AddAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     184      if (ReadOnly) throw new InvalidOperationException();
     185      base.AddAllowedChildSymbol(parent, child, argumentIndex);
     186    }
     187    void ISymbolicExpressionGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child) {
     188      if (ReadOnly) throw new InvalidOperationException();
     189      base.RemoveAllowedChildSymbol(parent, child);
     190    }
     191    void ISymbolicExpressionGrammar.RemoveAllowedChildSymbol(ISymbol parent, ISymbol child, int argumentIndex) {
     192      if (ReadOnly) throw new InvalidOperationException();
     193      base.RemoveAllowedChildSymbol(parent, child, argumentIndex);
     194    }
     195
     196    void ISymbolicExpressionGrammar.SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
     197      if (ReadOnly) throw new InvalidOperationException();
     198      base.SetSubtreeCount(symbol, minimumSubtreeCount, maximumSubtreeCount);
     199    }
     200    #endregion
    168201  }
    169202}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6233 r6284  
    9393      cachedMinExpressionDepth = new Dictionary<string, int>();
    9494
    95 
    9695      symbols = original.symbols.ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value));
    9796      symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubtreeCount);
     
    128127      symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0));
    129128      ClearCaches();
     129      OnChanged();
    130130    }
    131131
     
    133133      symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
    134134      symbol.NameChanged += new EventHandler(Symbol_NameChanged);
     135      symbol.Changed += new EventHandler(Symbol_Changed);
    135136    }
    136137    private void DeregisterSymbolEvents(ISymbol symbol) {
    137138      symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
    138139      symbol.NameChanged -= new EventHandler(Symbol_NameChanged);
     140      symbol.Changed -= new EventHandler(Symbol_Changed);
    139141    }
    140142
     
    179181
    180182      ClearCaches();
     183      OnChanged();
     184    }
     185
     186    private void Symbol_Changed(object sende, EventArgs e) {
     187      ClearCaches();
     188      OnChanged();
    181189    }
    182190
     
    200208      DeregisterSymbolEvents(symbol);
    201209      ClearCaches();
     210      OnChanged();
    202211    }
    203212
     
    217226      childSymbols.Add(child.Name);
    218227      ClearCaches();
     228      OnChanged();
    219229    }
    220230
     
    231241      childSymbols.Add(child.Name);
    232242      ClearCaches();
     243      OnChanged();
    233244    }
    234245
     
    236247      List<string> childSymbols;
    237248      if (allowedChildSymbols.TryGetValue(child.Name, out childSymbols)) {
    238         if (allowedChildSymbols[parent.Name].Remove(child.Name))
     249        if (allowedChildSymbols[parent.Name].Remove(child.Name)) {
    239250          ClearCaches();
     251          OnChanged();
     252        }
    240253      }
    241254    }
     
    245258      List<string> childSymbols;
    246259      if (allowedChildSymbolsPerIndex.TryGetValue(key, out childSymbols)) {
    247         if (allowedChildSymbolsPerIndex[key].Remove(child.Name))
     260        if (allowedChildSymbolsPerIndex[key].Remove(child.Name)) {
    248261          ClearCaches();
     262          OnChanged();
     263        }
    249264      }
    250265    }
     
    258273      symbolSubtreeCount[symbol.Name] = Tuple.Create(minimumSubtreeCount, maximumSubtreeCount);
    259274      ClearCaches();
     275      OnChanged();
    260276    }
    261277    #endregion
     
    304320        result = result.Union(temp);
    305321
    306       return result.Select(x => GetSymbol(x));
     322      return result.Select(x => GetSymbol(x)).Where(s => !s.InitialFrequency.IsAlmost(0.0));
    307323    }
    308324
     
    313329      return symbolSubtreeCount[symbol.Name].Item2;
    314330    }
    315 
    316331
    317332    private void ClearCaches() {
     
    369384      return temp;
    370385    }
     386
     387    public event EventHandler Changed;
     388    protected virtual void OnChanged() {
     389      var handler = Changed;
     390      if (handler != null) Changed(this, EventArgs.Empty);
     391    }
    371392    #endregion
    372393  }
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Symbol.cs

    r6233 r6284  
    4242      }
    4343    }
     44
     45    [Storable(DefaultValue = false)]
     46    private bool @fixed;
     47    public bool Fixed {
     48      get { return @fixed; }
     49      set {
     50        if (value != @fixed) {
     51          @fixed = value;
     52          OnChanged(EventArgs.Empty);
     53        }
     54      }
     55    }
     56
    4457    public override bool CanChangeName {
    4558      get { return !(this is IReadOnlySymbol); }
     
    5568      : base(original, cloner) {
    5669      initialFrequency = original.initialFrequency;
     70      @fixed = original.@fixed;
    5771    }
    5872
     
    6074      : base(name, description) {
    6175      initialFrequency = 1.0;
     76      @fixed = false;
    6277    }
    6378
     
    6883    #region events
    6984    public event EventHandler Changed;
    70     protected void OnChanged(EventArgs e) {
     85    protected virtual void OnChanged(EventArgs e) {
    7186      EventHandler handlers = Changed;
    7287      if (handlers != null)
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/MwDruGrammar.cs

    r6179 r6284  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2829namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2930  [StorableClass]
    30   [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")]
    31   public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     31  [Item("MwDruGrammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")]
     32  public class MwDruGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
    3233
    3334    [StorableConstructor]
    34     protected TypeCoherentExpressionGrammar(bool deserializing) : base(deserializing) { }
    35     protected TypeCoherentExpressionGrammar(TypeCoherentExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
    36     public TypeCoherentExpressionGrammar()
    37       : base(ItemAttribute.GetName(typeof(TypeCoherentExpressionGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
     35    protected MwDruGrammar(bool deserializing) : base(deserializing) { }
     36    protected MwDruGrammar(MwDruGrammar original, Cloner cloner) : base(original, cloner) { }
     37    public MwDruGrammar()
     38      : base(ItemAttribute.GetName(typeof(MwDruGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
    3839      Initialize();
    3940    }
    4041    public override IDeepCloneable Clone(Cloner cloner) {
    41       return new TypeCoherentExpressionGrammar(this, cloner);
     42      return new MwDruGrammar(this, cloner);
    4243    }
     44
     45    private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable ggDru;
     46    private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable flamTmp;
    4347
    4448    private void Initialize() {
     
    4751      var mul = new Multiplication();
    4852      var div = new Division();
    49       var mean = new Average();
    50       var sin = new Sine();
    51       var cos = new Cosine();
    52       var tan = new Tangent();
    5353      var log = new Logarithm();
    54       var pow = new Power();
    55       pow.InitialFrequency = 0.0;
    56       var root = new Root();
    57       root.InitialFrequency = 0.0;
    5854      var exp = new Exponential();
    59       var @if = new IfThenElse();
    60       var gt = new GreaterThan();
    61       var lt = new LessThan();
    62       var and = new And();
    63       var or = new Or();
    64       var not = new Not();
    65 
    66       var timeLag = new TimeLag();
    67       timeLag.InitialFrequency = 0.0;
    68       var integral = new Integral();
    69       integral.InitialFrequency = 0.0;
    70       var derivative = new Derivative();
    71       derivative.InitialFrequency = 0.0;
    72       var variableCondition = new VariableCondition();
    73       variableCondition.InitialFrequency = 0.0;
    7455
    7556      var constant = new Constant();
     
    7758      constant.MaxValue = 20;
    7859      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    79       var laggedVariable = new LaggedVariable();
    8060
    81       laggedVariable.InitialFrequency = 0.0;
    82       mean.InitialFrequency = 0.0;
     61      var fixedAdd1 = new Addition();
     62      fixedAdd1.Name = "fixed Addition 1";
     63      fixedAdd1.Fixed = true;
    8364
    84       /*
    85        * Start = RealValueExpression
    86        *
    87        * RealValueExpression =
    88        *   "Variable"  |
    89        *   "Constant" |
    90        *   BinaryOperator RealValueExpression RealValueExpression |
    91        *   UnaryOperator RealValueExpression |
    92        *   "IF" BooleanExpression RealValueExpression RealValueExpression |
    93        *   "VariableCondition" RealValueExpression RealValueExpression
    94        *
    95        * BinaryOperator =
    96        *   "+" | "-" | "*" | "/" | "Power"
    97        *
    98        * UnaryOperator =
    99        *   "Sin" | "Cos" | "Tan" | "Log" | "Exp"
    100        *
    101        * BooleanExpression =
    102        *   "AND" BooleanExpression BooleanExpression |
    103        *   "OR" BooleanExpression BooleanExpression |
    104        *   "NOT" BooleanExpression |
    105        *   ">" RealValueExpression RealValueExpression |
    106        *   "<" RealValueExpression RealValueExpression
    107        */
     65      var fixedAdd2 = new Addition();
     66      fixedAdd2.Name = "fixed Addition 2";
     67      fixedAdd2.Fixed = true;
    10868
    109       var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, pow, root, exp, @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition };
     69      var fixedMul = new Multiplication();
     70      fixedMul.Name = "fixed Multiplication";
     71      fixedMul.Fixed = true;
    11072
    111       var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, timeLag, integral, derivative };
    112       var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition };
     73      ggDru = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     74      ggDru.Name = "fixed Variable GGDru";
     75      ggDru.Fixed = true;
     76      ggDru.VariableNames = new List<string>() { "GGDRU" };
     77      ggDru.WeightManipulatorMu = 1;
     78      ggDru.WeightManipulatorSigma = 0;
     79      ggDru.WeightMu = 1;
     80      ggDru.WeightSigma = 0;
     81      ggDru.MultiplicativeWeightManipulatorSigma = 0;
     82      ggDru.Changed += new EventHandler(ggDru_Changed);
    11383
    114       var unaryBooleanFunctionSymbols = new List<Symbol>() { not };
    115       var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and };
    116       var relationalFunctionSymbols = new List<Symbol>() { gt, lt };
    117       var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
    118       var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if });
    119       var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols);
     84      flamTmp = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     85      flamTmp.Name = "fixed Variable FlamTmp";
     86      flamTmp.Fixed = true;
     87      flamTmp.VariableNames = new List<string>() { "FLAMTMP" };
     88      flamTmp.WeightManipulatorMu = 1;
     89      flamTmp.WeightManipulatorSigma = 0;
     90      flamTmp.WeightMu = 1;
     91      flamTmp.WeightSigma = 0;
     92      flamTmp.MultiplicativeWeightManipulatorSigma = 0;
     93      flamTmp.Changed += new EventHandler(flamTmp_Changed);
     94
     95      var c273 = new Constant();
     96      c273.Name = "fixed Constant 273";
     97      c273.Fixed = true;
     98      c273.MinValue = 273;
     99      c273.MaxValue = 273;
     100      c273.ManipulatorMu = 0;
     101      c273.ManipulatorSigma = 0;
     102      c273.MultiplicativeManipulatorSigma = 0;
     103
     104      var allSymbols = new List<Symbol>()
     105        { add, sub, mul, div, log, exp, constant, variableSymbol,
     106          fixedAdd1,fixedAdd2,fixedMul,ggDru,flamTmp,c273};
     107
     108      var unaryFunctionSymbols = new List<Symbol>() { log, exp };
     109      var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div };
     110
     111      var terminalSymbols = new List<Symbol>() { variableSymbol, constant };
     112      var fixedTerminalSymbols = new List<Symbol>() { ggDru, flamTmp, c273 };
     113      var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols);
    120114
    121115      foreach (var symb in allSymbols)
    122116        AddSymbol(symb);
    123 
    124       foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) {
     117      foreach (var terminalSymbol in terminalSymbols) {
     118        SetSubtreeCount(terminalSymbol, 0, 0);
     119      }
     120      foreach (var terminalSymbol in fixedTerminalSymbols) {
     121        SetSubtreeCount(terminalSymbol, 0, 0);
     122      }
     123      foreach (var unaryFun in unaryFunctionSymbols) {
    125124        SetSubtreeCount(unaryFun, 1, 1);
    126125      }
    127       foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {
     126      foreach (var binaryFun in binaryFunctionSymbols) {
    128127        SetSubtreeCount(binaryFun, 2, 2);
    129128      }
    130129
    131       foreach (var terminalSymbol in terminalSymbols) {
    132         SetSubtreeCount(terminalSymbol, 0, 0);
    133       }
     130      SetSubtreeCount(fixedAdd1, 3, 3);
     131      SetSubtreeCount(fixedMul, 3, 3);
     132      SetSubtreeCount(fixedAdd2, 2, 2);
    134133
    135       SetSubtreeCount(@if, 3, 3);
     134      AddAllowedChildSymbol(StartSymbol, fixedAdd1);
    136135
     136      AddAllowedChildSymbol(fixedAdd1, fixedMul, 0);
     137      AddAllowedChildSymbol(fixedAdd1, ggDru, 1);
     138      foreach (var symb in unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols))
     139        AddAllowedChildSymbol(fixedAdd1, symb, 2);
    137140
    138       // allow only real-valued expressions as child of the start symbol
    139       foreach (var symb in realValuedSymbols) {
    140         AddAllowedChildSymbol(StartSymbol, symb);
    141         AddAllowedChildSymbol(DefunSymbol, symb);
    142       }
     141      AddAllowedChildSymbol(fixedMul, constant, 0);
     142      AddAllowedChildSymbol(fixedMul, fixedAdd2, 1);
     143      foreach (var symb in realValuedSymbols)
     144        AddAllowedChildSymbol(fixedMul, symb, 2);
     145
     146      AddAllowedChildSymbol(fixedAdd2, c273, 0);
     147      AddAllowedChildSymbol(fixedAdd2, flamTmp, 1);
    143148
    144149      foreach (var symb in unaryFunctionSymbols) {
     
    153158        }
    154159      }
     160    }
    155161
    156       foreach (var childSymb in booleanSymbols) {
    157         AddAllowedChildSymbol(@if, childSymb, 0);
    158       }
    159       foreach (var childSymb in realValuedSymbols) {
    160         AddAllowedChildSymbol(@if, childSymb, 1);
    161         AddAllowedChildSymbol(@if, childSymb, 2);
    162       }
     162    private void flamTmp_Changed(object sender, System.EventArgs e) {
     163      if (flamTmp.VariableNames.Count() != 1 || flamTmp.VariableNames.ElementAt(0) != "FLAMTMP")
     164        flamTmp.VariableNames = new List<string>() { "FLAMTMP" };
     165    }
    163166
    164       foreach (var symb in relationalFunctionSymbols) {
    165         foreach (var childSymb in realValuedSymbols) {
    166           AddAllowedChildSymbol(symb, childSymb);
    167         }
    168       }
    169       foreach (var symb in binaryBooleanFunctionSymbols) {
    170         foreach (var childSymb in booleanSymbols) {
    171           AddAllowedChildSymbol(symb, childSymb);
    172         }
    173       }
    174       foreach (var symb in unaryBooleanFunctionSymbols) {
    175         foreach (var childSymb in booleanSymbols) {
    176           AddAllowedChildSymbol(symb, childSymb);
    177         }
    178       }
     167    private void ggDru_Changed(object sender, System.EventArgs e) {
     168      if (ggDru.VariableNames.Count() != 1 || ggDru.VariableNames.ElementAt(0) != "GGDRU")
     169        ggDru.VariableNames = new List<string>() { "GGDRU" };
    179170    }
    180171  }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/Poly10Grammar.cs

    r6179 r6284  
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2929  [StorableClass]
    30   [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")]
    31   public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     30  [Item("Poly10Grammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")]
     31  public class Poly10Grammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
    3232
    3333    [StorableConstructor]
    34     protected TypeCoherentExpressionGrammar(bool deserializing) : base(deserializing) { }
    35     protected TypeCoherentExpressionGrammar(TypeCoherentExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
    36     public TypeCoherentExpressionGrammar()
    37       : base(ItemAttribute.GetName(typeof(TypeCoherentExpressionGrammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
     34    protected Poly10Grammar(bool deserializing) : base(deserializing) { }
     35    protected Poly10Grammar(Poly10Grammar original, Cloner cloner) : base(original, cloner) { }
     36    public Poly10Grammar()
     37      : base(ItemAttribute.GetName(typeof(Poly10Grammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
    3838      Initialize();
    3939    }
    4040    public override IDeepCloneable Clone(Cloner cloner) {
    41       return new TypeCoherentExpressionGrammar(this, cloner);
     41      return new Poly10Grammar(this, cloner);
    4242    }
    4343
     
    4747      var mul = new Multiplication();
    4848      var div = new Division();
    49       var mean = new Average();
    50       var sin = new Sine();
    51       var cos = new Cosine();
    52       var tan = new Tangent();
    53       var log = new Logarithm();
    54       var pow = new Power();
    55       pow.InitialFrequency = 0.0;
    56       var root = new Root();
    57       root.InitialFrequency = 0.0;
    58       var exp = new Exponential();
    59       var @if = new IfThenElse();
    60       var gt = new GreaterThan();
    61       var lt = new LessThan();
    62       var and = new And();
    63       var or = new Or();
    64       var not = new Not();
    65 
    66       var timeLag = new TimeLag();
    67       timeLag.InitialFrequency = 0.0;
    68       var integral = new Integral();
    69       integral.InitialFrequency = 0.0;
    70       var derivative = new Derivative();
    71       derivative.InitialFrequency = 0.0;
    72       var variableCondition = new VariableCondition();
    73       variableCondition.InitialFrequency = 0.0;
    7449
    7550      var constant = new Constant();
    76       constant.MinValue = -20;
    77       constant.MaxValue = 20;
    7851      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    79       var laggedVariable = new LaggedVariable();
    8052
    81       laggedVariable.InitialFrequency = 0.0;
    82       mean.InitialFrequency = 0.0;
     53      var fixedAdd1 = new Addition();
     54      fixedAdd1.Name = "fixed Addition1";
     55      fixedAdd1.Fixed = true;
    8356
    84       /*
    85        * Start = RealValueExpression
    86        *
    87        * RealValueExpression =
    88        *   "Variable"  |
    89        *   "Constant" |
    90        *   BinaryOperator RealValueExpression RealValueExpression |
    91        *   UnaryOperator RealValueExpression |
    92        *   "IF" BooleanExpression RealValueExpression RealValueExpression |
    93        *   "VariableCondition" RealValueExpression RealValueExpression
    94        *
    95        * BinaryOperator =
    96        *   "+" | "-" | "*" | "/" | "Power"
    97        *
    98        * UnaryOperator =
    99        *   "Sin" | "Cos" | "Tan" | "Log" | "Exp"
    100        *
    101        * BooleanExpression =
    102        *   "AND" BooleanExpression BooleanExpression |
    103        *   "OR" BooleanExpression BooleanExpression |
    104        *   "NOT" BooleanExpression |
    105        *   ">" RealValueExpression RealValueExpression |
    106        *   "<" RealValueExpression RealValueExpression
    107        */
     57      var fixedAdd2 = new Addition();
     58      fixedAdd2.Name = "fixed Addition2";
     59      fixedAdd2.Fixed = true;
    10860
    109       var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, pow, root, exp, @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition };
     61      var fixedAdd3 = new Addition();
     62      fixedAdd3.Name = "fixed Addition3";
     63      fixedAdd3.Fixed = true;
    11064
    111       var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, timeLag, integral, derivative };
    112       var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div, mean, pow, root, variableCondition };
     65      var fixedMul1 = new Multiplication();
     66      fixedMul1.Name = "fixed Multiplication1";
     67      fixedMul1.Fixed = true;
    11368
    114       var unaryBooleanFunctionSymbols = new List<Symbol>() { not };
    115       var binaryBooleanFunctionSymbols = new List<Symbol>() { or, and };
    116       var relationalFunctionSymbols = new List<Symbol>() { gt, lt };
    117       var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
    118       var realValuedSymbols = unaryFunctionSymbols.Concat(binaryFunctionSymbols).Concat(terminalSymbols).Concat(new List<Symbol>() { @if });
    119       var booleanSymbols = unaryBooleanFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols);
     69      var fixedMul2 = new Multiplication();
     70      fixedMul2.Name = "fixed Multiplication2";
     71      fixedMul2.Fixed = true;
     72
     73
     74      #region fixed variables
     75      var x1 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     76      x1.Name = "fixed X1";
     77      x1.VariableNames = new List<string>() { "x1" };
     78      x1.Fixed = true;
     79
     80
     81      var x2 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     82      x2.Name = "fixed X2";
     83      x2.VariableNames = new List<string>() { "x2" };
     84      x2.Fixed = true;
     85
     86      var x3 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     87      x3.Name = "fixed X3";
     88      x3.VariableNames = new List<string>() { "x3" };
     89      x3.Fixed = true;
     90
     91      var x4 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     92      x4.Name = "fixed X4";
     93      x4.VariableNames = new List<string>() { "x4" };
     94      x4.Fixed = true;
     95
     96      var x5 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     97      x5.Name = "fixed X5";
     98      x5.VariableNames = new List<string>() { "x5" };
     99      x5.Fixed = true;
     100
     101      var x6 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     102      x6.Name = "fixed X6";
     103      x6.VariableNames = new List<string>() { "x6" };
     104      x6.Fixed = true;
     105
     106      var x7 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     107      x7.Name = "fixed X7";
     108      x7.VariableNames = new List<string>() { "x7" };
     109      x7.Fixed = true;
     110
     111      var x8 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     112      x8.Name = "fixed X8";
     113      x8.VariableNames = new List<string>() { "x8" };
     114      x8.Fixed = true;
     115
     116      var x9 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     117      x9.Name = "fixed X9";
     118      x9.VariableNames = new List<string>() { "x9" };
     119      x9.Fixed = true;
     120
     121      var x10 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     122      x10.Name = "fixed X10";
     123      x10.VariableNames = new List<string>() { "x10" };
     124      x10.Fixed = true;
     125      #endregion
     126
     127      var fixedTerminalSymbols = new List<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>() { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 };
     128      var allSymbols = new List<Symbol>()
     129        { add, sub, mul, div, constant, variableSymbol,
     130          fixedAdd1,fixedMul1,fixedMul2}.Union(fixedTerminalSymbols);
     131
     132      var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div };
     133      var terminalSymbols = new List<Symbol>() { variableSymbol, constant };
     134      var realValuedSymbols = binaryFunctionSymbols.Concat(terminalSymbols);
    120135
    121136      foreach (var symb in allSymbols)
    122137        AddSymbol(symb);
    123 
    124       foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) {
    125         SetSubtreeCount(unaryFun, 1, 1);
     138      foreach (var terminalSymbol in terminalSymbols.Union(fixedTerminalSymbols)) {
     139        SetSubtreeCount(terminalSymbol, 0, 0);
    126140      }
    127       foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) {
     141      foreach (var binaryFun in binaryFunctionSymbols) {
    128142        SetSubtreeCount(binaryFun, 2, 2);
    129143      }
     144      SetSubtreeCount(fixedAdd1, 3, 3);
     145      SetSubtreeCount(fixedMul1, 3, 3);
     146      SetSubtreeCount(fixedMul2, 3, 3);
    130147
    131       foreach (var terminalSymbol in terminalSymbols) {
    132         SetSubtreeCount(terminalSymbol, 0, 0);
     148      AddAllowedChildSymbol(StartSymbol, fixedAdd1);
     149      foreach (var symb in realValuedSymbols) {
     150        AddAllowedChildSymbol(fixedAdd1, symb, 0);
    133151      }
    134152
    135       SetSubtreeCount(@if, 3, 3);
     153      AddAllowedChildSymbol(fixedAdd1, fixedMul1, 1);
     154      AddAllowedChildSymbol(fixedAdd1, fixedMul2, 2);
    136155
    137156
    138       // allow only real-valued expressions as child of the start symbol
    139       foreach (var symb in realValuedSymbols) {
    140         AddAllowedChildSymbol(StartSymbol, symb);
    141         AddAllowedChildSymbol(DefunSymbol, symb);
    142       }
     157      AddAllowedChildSymbol(fixedMul1, x1, 0);
     158      AddAllowedChildSymbol(fixedMul1, x7, 1);
     159      AddAllowedChildSymbol(fixedMul1, x9, 2);
    143160
    144       foreach (var symb in unaryFunctionSymbols) {
    145         foreach (var childSymb in realValuedSymbols) {
    146           AddAllowedChildSymbol(symb, childSymb);
    147         }
    148       }
     161      AddAllowedChildSymbol(fixedMul2, x3, 0);
     162      AddAllowedChildSymbol(fixedMul2, x6, 1);
     163      AddAllowedChildSymbol(fixedMul2, x10, 2);
    149164
    150165      foreach (var symb in binaryFunctionSymbols) {
     
    153168        }
    154169      }
    155 
    156       foreach (var childSymb in booleanSymbols) {
    157         AddAllowedChildSymbol(@if, childSymb, 0);
    158       }
    159       foreach (var childSymb in realValuedSymbols) {
    160         AddAllowedChildSymbol(@if, childSymb, 1);
    161         AddAllowedChildSymbol(@if, childSymb, 2);
    162       }
    163 
    164       foreach (var symb in relationalFunctionSymbols) {
    165         foreach (var childSymb in realValuedSymbols) {
    166           AddAllowedChildSymbol(symb, childSymb);
    167         }
    168       }
    169       foreach (var symb in binaryBooleanFunctionSymbols) {
    170         foreach (var childSymb in booleanSymbols) {
    171           AddAllowedChildSymbol(symb, childSymb);
    172         }
    173       }
    174       foreach (var symb in unaryBooleanFunctionSymbols) {
    175         foreach (var childSymb in booleanSymbols) {
    176           AddAllowedChildSymbol(symb, childSymb);
    177         }
    178       }
    179170    }
    180171  }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r6135 r6284  
    123123    <Compile Include="Formatters\SymbolicDataAnalysisExpressionLatexFormatter.cs" />
    124124    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMATLABFormatter.cs" />
     125    <Compile Include="Grammars\Poly10Grammar.cs" />
     126    <Compile Include="Grammars\MwDruGrammar.cs" />
    125127    <Compile Include="Interfaces\ISymbolicDataAnalysisBoundedOperator.cs" />
    126128    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionTreeInterpreter.cs" />
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r6135 r6284  
    190190      SymbolicExpressionTreeGrammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
    191191      foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) {
    192         varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     192        if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables;
    193193      }
    194194      foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {
    195         varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     195        if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables;
    196196      }
    197197    }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs

    r5809 r6284  
    126126    }
    127127
     128    protected override void OnChanged(EventArgs e) {
     129      if (@Fixed) {
     130        weightManipulatorMu = 1;
     131        weightManipulatorSigma = 0;
     132        weightMu = 1;
     133        weightSigma = 0;
     134        multiplicativeWeightManipulatorSigma = 0;
     135      }
     136      base.OnChanged(e);
     137    }
     138
    128139    public override ISymbolicExpressionTreeNode CreateTreeNode() {
    129140      return new VariableTreeNode(this);
Note: See TracChangeset for help on using the changeset viewer.