Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3462


Ignore:
Timestamp:
04/21/10 15:21:34 (14 years ago)
Author:
gkronber
Message:

Refactored symbolic expression tree encoding and problem classes for symbolic regression. #937 , #938

Location:
trunk/sources
Files:
2 added
1 deleted
65 edited
13 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/EnumerableStatisticExtensions.cs

    r3456 r3462  
    2525using System.Linq;
    2626
    27 namespace HeuristicLab.Problems.DataAnalysis {
    28   public static class StatisticExtensions {
     27namespace HeuristicLab.Common {
     28  public static class EnumerableStatisticExtensions {
    2929    /// <summary>
    3030    /// Calculates the median element of the enumeration.
  • trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r3405 r3462  
    9595    <Compile Include="DeepCloneable.cs" />
    9696    <Compile Include="Content\IContent.cs" />
     97    <Compile Include="EnumerableStatisticExtensions.cs" />
    9798    <Compile Include="IDeepCloneable.cs" />
    9899    <Compile Include="ReferenceEqualityComparer.cs" />
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentCreater.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDeleter.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDuplicater.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/GrammarModifier.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/RandomArchitectureAlteringOperator.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineCreater.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDeleter.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
    3434using System.Diagnostics;
     35using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3536
    3637namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs

    r3376 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SymbolicExpressionTreeArchitectureAlteringOperator.cs

    r3456 r3462  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3232using System.Collections.Generic;
    3333using System.Text;
     34using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
    3435
    35 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     36namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators {
    3637  /// <summary>
    3738  /// Base class for architecture altering operators for symbolic expression trees.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Compiler/Instruction.cs

    r3456 r3462  
    2626using System.Collections.Generic;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2929
    30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    31   public enum CodeSymbol : byte {
    32     Add,
    33     Sub,
    34     Mul,
    35     Div,
    36     Call,
    37     Arg,
    38     Values,
    39     Dynamic
    40   };
     30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler {
     31  // total size of this struct should be small to improve cache access while executing the code
     32  // should be aligned to 8/16/32 byte
     33  // size = 4(8) + 1 + 1 + 2 = 8 (12)
    4134  public struct Instruction {
     35    // the tree node can hold additional data that is necessary for the execution of this instruction
     36    public SymbolicExpressionTreeNode dynamicNode;
     37    // op code of the function that determines what operation should be executed
     38    public byte opCode;
     39    // number of arguments of the current instruction
    4240    public byte nArguments;
    43     public CodeSymbol symbol;
    44     public short iArg0;
    45     public SymbolicExpressionTreeNode dynamicNode;
     41    // an optional short value (addresses for calls, argument index for arguments)
     42    public ushort iArg0;
    4643  }
    4744}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Compiler/SymbolicExpressionTreeCompiler.cs

    r3456 r3462  
    2727using System.Collections.Generic;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3030
    31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     31namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler {
    3232  public class SymbolicExpressionTreeCompiler {
    33     private Dictionary<Type, CodeSymbol> codeSymbol = new Dictionary<Type, CodeSymbol>() {
    34       {typeof(Addition), CodeSymbol.Add},
    35       {typeof(Subtraction), CodeSymbol.Sub},
    36       {typeof(Multiplication), CodeSymbol.Mul},
    37       {typeof(Division), CodeSymbol.Div},
    38       {typeof(InvokeFunction), CodeSymbol.Call},
    39       {typeof(Argument), CodeSymbol.Arg},
    40       //{typeof(Values), CodeSymbol.Values}
    41     };
    42     private Dictionary<string, short> entryPoint = new Dictionary<string, short>();
     33    private Dictionary<string, ushort> entryPoint = new Dictionary<string, ushort>();
     34    private List<Func<Instruction, Instruction>> postInstructionCompiledHooks = new List<Func<Instruction, Instruction>>();
    4335
    44     public Instruction[] Compile(SymbolicExpressionTree tree) {
     36    public Instruction[] Compile(SymbolicExpressionTree tree, Func<SymbolicExpressionTreeNode, byte> opCodeMapper) {
    4537      List<Instruction> code = new List<Instruction>();
    4638      entryPoint.Clear();
    4739      // compile main body
    48       code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0]));
     40      code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0], opCodeMapper));
    4941      // compile branches
    5042      var functionBranches = from node in tree.IterateNodesPrefix()
     
    5244                             select node;
    5345      foreach (DefunTreeNode branch in functionBranches) {
    54         entryPoint[branch.FunctionName] = (short)code.Count;
    55         code.AddRange(Compile(branch.SubTrees[0]));
     46        if (code.Count > ushort.MaxValue) throw new ArgumentException("Code for the tree is too long (> ushort.MaxValue).");
     47        entryPoint[branch.FunctionName] = (ushort)code.Count;
     48        code.AddRange(Compile(branch.SubTrees[0], opCodeMapper));
    5649      }
    5750      // address of all functions is fixed now
     
    5952      for (int i = 0; i < code.Count; i++) {
    6053        Instruction instr = code[i];
    61         if (instr.symbol == CodeSymbol.Call) {
     54        if (instr.dynamicNode.Symbol is InvokeFunction) {
    6255          var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode;
    6356          instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName];
    64           instr.dynamicNode = null;
    6557          code[i] = instr;
    6658        }
     
    7062    }
    7163
    72     private IEnumerable<Instruction> Compile(SymbolicExpressionTreeNode branch) {
    73       foreach (var node in IteratePrefix(branch)) {
     64    private IEnumerable<Instruction> Compile(SymbolicExpressionTreeNode branch, Func<SymbolicExpressionTreeNode, byte> opCodeMapper) {
     65      foreach (var node in branch.IterateNodesPrefix()) {
    7466        Instruction instr = new Instruction();
    75         if (node.SubTrees.Count > 255) throw new ArgumentException();
     67        if (node.SubTrees.Count > 255) throw new ArgumentException("Number of subtrees is too big (>255)");
    7668        instr.nArguments = (byte)node.SubTrees.Count;
    77         if (codeSymbol.ContainsKey(node.Symbol.GetType())) {
    78           instr.symbol = codeSymbol[node.Symbol.GetType()];
    79           if (instr.symbol == CodeSymbol.Arg) {
    80             var argNode = (ArgumentTreeNode)node;
    81             instr.iArg0 = (short)argNode.Symbol.ArgumentIndex;
    82           } else if (instr.symbol == CodeSymbol.Call) {
    83             instr.dynamicNode = node; // save node for fixup of jump addresses in second iteration
    84           }
    85         } else {
    86           instr.symbol = CodeSymbol.Dynamic;
    87           instr.dynamicNode = node;
     69        instr.opCode = opCodeMapper(node);
     70        if (branch.Symbol is Argument) {
     71          var argNode = (ArgumentTreeNode)node;
     72          instr.iArg0 = (ushort)argNode.Symbol.ArgumentIndex;
     73        }
     74        instr.dynamicNode = node;
     75        foreach (var hook in postInstructionCompiledHooks) {
     76          instr = hook(instr);
    8877        }
    8978        yield return instr;
     
    9180    }
    9281
    93     private IEnumerable<SymbolicExpressionTreeNode> IteratePrefix(SymbolicExpressionTreeNode branch) {
    94       yield return branch;
    95       foreach (var subtree in branch.SubTrees) {
    96         foreach (var node in IteratePrefix(subtree))
    97           yield return node;
    98       }
     82    /// <summary>
     83    /// Adds a function that will be called every time an instruction is compiled.
     84    /// The compiled will insert the instruction returned by the hook into the code.
     85    /// </summary>
     86    /// <param name="hook">The hook that should be called for each compiled instruction.</param>
     87    public void AddInstructionPostProcessingHook(Func<Instruction, Instruction> hook) {
     88      postInstructionCompiledHooks.Add(hook);
    9989    }
    10090  }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r3442 r3462  
    2020#endregion
    2121
     22using System;
     23using System.Linq;
     24using System.Collections.Generic;
     25using System.Text;
    2226using HeuristicLab.Common;
    2327using HeuristicLab.Core;
    2428using HeuristicLab.Data;
    2529using HeuristicLab.Random;
    26 using System;
    27 using System.Linq;
    2830using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using System.Collections.Generic;
    30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
    31 using System.Text;
    3231using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
    33 
    34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     33
     34namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators {
    3535  [StorableClass]
    3636  [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")]
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/SymbolicExpressionTreeCreator.cs

    r3456 r3462  
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     31namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators {
    3232  /// <summary>
    3333  /// A base class for operators creating symbolic expression trees.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs

    r3376 r3462  
    2828using System;
    2929using HeuristicLab.Parameters;
    30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
    31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3231
    33 
     32namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers {
    3433  /// <summary>
    3534  /// Takes two parent individuals P0 and P1 each. Selects a random node N0 of P0 and a random node N1 of P1.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SymbolicExpressionTreeCrossover.cs

    r3456 r3462  
    3030using System.Diagnostics;
    3131
    32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers {
    3333  /// <summary>
    3434  /// A base class for operators that perform a crossover of symbolic expression trees.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs

    r3376 r3462  
    2828using System.Xml;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3131
    3232namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs

    r3376 r3462  
    2828using System.Xml;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3131
    3232namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj

    r3384 r3462  
    9393    <Compile Include="ArchitectureAlteringOperators\SubroutineDeleter.cs" />
    9494    <Compile Include="ArchitectureAlteringOperators\SubroutineDuplicater.cs" />
     95    <Compile Include="ArchitectureAlteringOperators\SymbolicExpressionTreeArchitectureAlteringOperator.cs" />
     96    <Compile Include="Compiler\Instruction.cs" />
     97    <Compile Include="Compiler\SymbolicExpressionTreeCompiler.cs" />
     98    <Compile Include="Creators\SymbolicExpressionTreeCreator.cs" />
     99    <Compile Include="Crossovers\SymbolicExpressionTreeCrossover.cs" />
     100    <Compile Include="Manipulators\SymbolicExpressionTreeManipulator.cs" />
    95101    <Compile Include="SymbolicExpressionTreeTopLevelNode.cs" />
    96102    <Compile Include="Crossovers\SubtreeCrossover.cs">
     
    102108      <SubType>Code</SubType>
    103109    </Compile>
    104     <Compile Include="SymbolicExpressionTreeArchitectureAlteringOperator.cs" />
    105110    <Compile Include="SymbolicExpressionTreeOperator.cs" />
    106     <Compile Include="Instruction.cs" />
    107     <Compile Include="SymbolicExpressionTreeCompiler.cs" />
    108     <Compile Include="SymbolicExpressionTreeManipulator.cs" />
    109111    <Compile Include="SymbolicExpressionTreeTerminalNode.cs" />
    110112    <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" />
     
    112114    <Compile Include="HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs" />
    113115    <Compile Include="Interfaces\ISymbolicExpressionTreeOperator.cs" />
    114     <Compile Include="SymbolicExpressionTreeCreator.cs" />
    115116    <Compile Include="SymbolicExpressionTree.cs" />
    116117    <Compile Include="Properties\AssemblyInfo.cs" />
    117     <Compile Include="Symbol.cs" />
    118     <Compile Include="SymbolicExpressionTreeCrossover.cs" />
    119118    <Compile Include="SymbolicExpressionTreeNode.cs" />
    120     <Compile Include="Symbols\Addition.cs" />
    121119    <Compile Include="Symbols\Argument.cs" />
    122120    <Compile Include="Symbols\ArgumentTreeNode.cs" />
     
    127125    <Compile Include="Symbols\Defun.cs" />
    128126    <Compile Include="Symbols\ProgramRootSymbol.cs" />
    129     <Compile Include="Symbols\Division.cs" />
    130     <Compile Include="Symbols\Multiplication.cs" />
    131     <Compile Include="Symbols\Subtraction.cs" />
     127    <Compile Include="Symbols\Symbol.cs" />
    132128  </ItemGroup>
    133129  <ItemGroup>
     
    178174    </ProjectReference>
    179175  </ItemGroup>
    180   <ItemGroup>
    181     <Folder Include="Manipulators\" />
    182   </ItemGroup>
    183176  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    184177  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Interfaces/ISymbolicExpressionGrammar.cs

    r3376 r3462  
    2828using System.Xml;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs

    r3456 r3462  
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators {
    3131  /// <summary>
    3232  /// A base class for operators that manipulate real-valued vectors.
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r3442 r3462  
    3030using HeuristicLab.Data;
    3131using System.Diagnostics;
     32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3233
    3334namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3839    [Storable]
    3940    private Symbol symbol;
    40     //[Storable]
     41
     42    // parent relation is not persisted or cloned (will be set on AddSubtree or RemoveSubtree)
    4143    private SymbolicExpressionTreeNode parent;
    4244
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTerminalNode.cs

    r3376 r3462  
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929using HeuristicLab.Data;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTopLevelNode.cs

    r3376 r3462  
    3030using HeuristicLab.Data;
    3131using System.Diagnostics;
     32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3233
    3334namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    4445
    4546    private ISymbolicExpressionGrammar grammar;
    46     //internal virtual ISymbolicExpressionGrammar Grammar {
    47     //  get { return grammar; }
    48     //  set {
    49     //    grammar = value;
    50     //    //foreach (var subtree in subTrees)
    51     //    //  subtree.Grammar = value;
    52     //  }
    53     //}
     47
    5448    internal override ISymbolicExpressionGrammar Grammar {
    5549      get {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Argument.cs

    r3376 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2626  /// <summary>
    2727  /// Symbol for function arguments
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ArgumentTreeNode.cs

    r3369 r3462  
    2222using System;
    2323using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     24namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2525  [StorableClass]
    2626  public sealed class ArgumentTreeNode : SymbolicExpressionTreeNode {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Defun.cs

    r3376 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2626  /// <summary>
    2727  /// Symbol for function defining branches
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs

    r3442 r3462  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     26namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2727  [StorableClass]
    2828  public sealed class DefunTreeNode : SymbolicExpressionTreeTopLevelNode {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunction.cs

    r3376 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2626  /// <summary>
    2727  /// Symbol for invoking automatically defined functions
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunctionTreeNode.cs

    r3369 r3462  
    2222using System;
    2323using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     24namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2525  [StorableClass]
    2626  public sealed class InvokeFunctionTreeNode : SymbolicExpressionTreeNode {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ProgramRootSymbol.cs

    r3376 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2626  [StorableClass]
    2727  [Item("ProgramRootSymbol", "Special symbol that represents the program root node of a symbolic expression tree.")]
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/StartSymbol.cs

    r3376 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2626  [StorableClass]
    2727  [Item("StartSymbol", "Special symbol that represents the starting node of the result producing branch of a symbolic expression tree.")]
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Symbol.cs

    r3456 r3462  
    3030using HeuristicLab.Parameters;
    3131
    32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    3333  [StorableClass]
    3434  [Item("Symbol", "Represents a symbol in a symbolic function tree.")]
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/AllArchitectureAlteringOperatorsTest.cs

    r3369 r3462  
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
    3131using HeuristicLab.Data;
     32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
     33using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
    3234
    3335namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentCreaterTest.cs

    r3360 r3462  
    2929using System.Diagnostics;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentDeleterTest.cs

    r3360 r3462  
    2929using System.Diagnostics;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentDuplicaterTest.cs

    r3360 r3462  
    2929using System.Diagnostics;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/Grammars.cs

    r3369 r3462  
    2828using HeuristicLab.Random;
    2929using System.Diagnostics;
    30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3131
    3232namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ProbabilisticTreeCreaterTest.cs

    r3369 r3462  
    2828using HeuristicLab.Random;
    2929using System.Diagnostics;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineCreaterTest.cs

    r3360 r3462  
    2929using System.Diagnostics;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineDeleterTest.cs

    r3360 r3462  
    2929using System.Diagnostics;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineDuplicaterTest.cs

    r3360 r3462  
    2929using System.Diagnostics;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3132
    3233namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubtreeCrossoverTest.cs

    r3360 r3462  
    2828using HeuristicLab.Random;
    2929using System.Diagnostics;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
     31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3032
    3133namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntInterpreter.cs

    r3457 r3462  
    2525using HeuristicLab.Data;
    2626using System.Collections.Generic;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     28using HeuristicLab.Problems.ArtificialAnt.Symbols;
    2829
    2930namespace HeuristicLab.Problems.ArtificialAnt {
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs

    r3376 r3462  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     31using HeuristicLab.Problems.ArtificialAnt.Symbols;
    3132namespace HeuristicLab.Problems.ArtificialAnt {
    3233  [StorableClass]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs

    r3338 r3462  
    3232using HeuristicLab.PluginInfrastructure;
    3333using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     34using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
     35using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
     36using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
     37using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
    3438
    3539namespace HeuristicLab.Problems.ArtificialAnt {
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/IfFoodAhead.cs

    r3376 r3462  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 namespace HeuristicLab.Problems.ArtificialAnt {
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     27namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
    2728  [StorableClass]
    2829  [Item("IfFoodAhead", "Represents the if-food-ahead symbol in a artificial ant expression.")]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Left.cs

    r3376 r3462  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 namespace HeuristicLab.Problems.ArtificialAnt {
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     27namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
    2728  [StorableClass]
    2829  [Item("Left", "Represents the turn-left symbol in a artificial ant expression.")]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Move.cs

    r3376 r3462  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 namespace HeuristicLab.Problems.ArtificialAnt {
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     27namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
    2728  [StorableClass]
    2829  [Item("Move", "Represents the move-forward symbol in a artificial ant expression.")]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Prog2.cs

    r3376 r3462  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 namespace HeuristicLab.Problems.ArtificialAnt {
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     28namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
    2829  [StorableClass]
    2930  [Item("Prog2", "Represents the sequence symbol with 2 sub-trees in a artificial ant expression.")]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Prog3.cs

    r3376 r3462  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 namespace HeuristicLab.Problems.ArtificialAnt {
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     27namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
    2728  [StorableClass]
    2829  [Item("Prog3", "Represents the sequence symbol with 3 sub-trees in a artificial ant expression.")]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Right.cs

    r3376 r3462  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 namespace HeuristicLab.Problems.ArtificialAnt {
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     27namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
    2728  [StorableClass]
    2829  [Item("Right", "Represents the turn-right symbol in a artificial ant expression.")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/BestValidationSymbolicRegressionSolutionVisualizer.cs

    r3452 r3462  
    3939  [StorableClass]
    4040  public sealed class BestValidationSymbolicRegressionSolutionVisualizer : SingleSuccessorOperator, ISingleObjectiveSolutionsVisualizer, ISolutionsVisualizer {
    41     private const string EvaluatorParameterName = "Evaluator";
     41    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    4242    private const string SymbolicRegressionModelParameterName = "SymbolicRegressionModel";
    4343    private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData";
     
    4949
    5050    #region parameter properties
    51     public ILookupParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
    52       get { return (ILookupParameter<ISymbolicRegressionEvaluator>)Parameters[EvaluatorParameterName]; }
     51    public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
     52      get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
    5353    }
    5454    public IValueLookupParameter<IntValue> ValidationSamplesStartParameter {
     
    8282
    8383    #region properties
    84     public ISymbolicRegressionEvaluator Evaluator {
    85       get { return EvaluatorParameter.ActualValue; }
     84    public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
     85      get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
    8686    }
    8787    public IntValue ValidationSamplesStart {
     
    9898      Parameters.Add(new SubScopesLookupParameter<DoubleValue>(QualityParameterName, "The quality of the symbolic regression solutions."));
    9999      Parameters.Add(new LookupParameter<DataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The symbolic regression problme data on which the best solution should be evaluated."));
     100      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of symbolic expression trees."));
    100101      Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesStartParameterName, "The start index of the validation partition (part of the training partition)."));
    101102      Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesEndParameterName, "The end index of the validation partition (part of the training partition)."));
     
    113114
    114115      var currentBestExpression = (from expression in expressions
    115                                    let validationQuality = SymbolicRegressionMeanSquaredErrorEvaluator.Calculate(expression, problemData.Dataset, problemData.TargetVariable.Value, validationSamplesStart, validationSamplesEnd)
     116                                   let validationQuality =
     117                                     SymbolicRegressionMeanSquaredErrorEvaluator.Calculate(
     118                                       SymbolicExpressionTreeInterpreter, expression,
     119                                       problemData.Dataset, problemData.TargetVariable.Value,
     120                                       validationSamplesStart, validationSamplesEnd)
    116121                                   select new { Expression = expression, ValidationQuality = validationQuality })
    117122                                   .OrderBy(x => x.ValidationQuality)
     
    121126      if (bestOfRunSolution == null) {
    122127        // no best of run solution yet -> make a solution from the currentBestExpression
    123         UpdateBestOfRunSolution(problemData, currentBestExpression.Expression);
     128        UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter);
    124129      } else {
    125130        // compare quality of current best with best of run solution
     
    127132        var bestOfRunValidationQuality = SimpleMSEEvaluator.Calculate(validationValues, estimatedValidationValues);
    128133        if (bestOfRunValidationQuality > currentBestExpression.ValidationQuality) {
    129           UpdateBestOfRunSolution(problemData, currentBestExpression.Expression);
     134          UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter);
    130135        }
    131136      }
     
    135140    }
    136141
    137     private void UpdateBestOfRunSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree tree) {
    138       var newBestSolution = CreateDataAnalysisSolution(problemData, tree);
    139       BestValidationSolutionParameter.ActualValue = newBestSolution;
     142    private void UpdateBestOfRunSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter) {
     143      var newBestSolution = CreateDataAnalysisSolution(problemData, tree, interpreter);
     144      if (BestValidationSolutionParameter.ActualValue == null)
     145        BestValidationSolutionParameter.ActualValue = newBestSolution;
     146      else
     147        // only update model
     148        BestValidationSolutionParameter.ActualValue.Model = newBestSolution.Model;
    140149
    141150      var trainingValues = problemData.Dataset.GetVariableValues(problemData.TargetVariable.Value, problemData.TrainingSamplesStart.Value, problemData.TrainingSamplesEnd.Value);
     
    160169    }
    161170
    162     private SymbolicRegressionModel CreateModel(DataAnalysisProblemData problemData, SymbolicExpressionTree expression) {
    163       return new SymbolicRegressionModel(expression, problemData.InputVariables.Select(x => x.Value));
    164     }
    165 
    166     private SymbolicRegressionSolution CreateDataAnalysisSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree expression) {
    167       return new SymbolicRegressionSolution(problemData, CreateModel(problemData, expression));
     171    private SymbolicRegressionSolution CreateDataAnalysisSolution(DataAnalysisProblemData problemData, SymbolicExpressionTree expression, ISymbolicExpressionTreeInterpreter interpreter) {
     172      var model = new SymbolicRegressionModel(interpreter, expression, problemData.InputVariables.Select(s => s.Value));
     173      return new SymbolicRegressionSolution(problemData, model);
    168174    }
    169175  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs

    r3452 r3462  
    3434using HeuristicLab.Problems.DataAnalysis;
    3535using HeuristicLab.Operators;
     36using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3637
    3738namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
     
    4041  public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator {
    4142    private const string QualityParameterName = "Quality";
     43    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    4244    private const string FunctionTreeParameterName = "FunctionTree";
    4345    private const string RegressionProblemDataParameterName = "RegressionProblemData";
     
    4951    public ILookupParameter<DoubleValue> QualityParameter {
    5052      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
     53    }
     54
     55    public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
     56      get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
    5157    }
    5258
     
    7278    #endregion
    7379    #region properties
     80    public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
     81      get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
     82    }
    7483    public SymbolicExpressionTree SymbolicExpressionTree {
    7584      get { return SymbolicExpressionTreeParameter.ActualValue; }
     
    8998      : base() {
    9099      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution."));
     100      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree."));
    91101      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
    92102      Parameters.Add(new LookupParameter<DataAnalysisProblemData>(RegressionProblemDataParameterName, "The problem data on which the symbolic regression solution should be evaluated."));
     
    98108    public override IOperation Apply() {
    99109      DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
    100       QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTree, RegressionProblemData.Dataset,
     110      QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset,
    101111        RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd, numberOfEvaluatedNodes));
    102112      return null;
    103113    }
    104114
    105     protected abstract double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes);
     115    protected abstract double Evaluate(ISymbolicExpressionTreeInterpreter interpreter,
     116      SymbolicExpressionTree solution,
     117      Dataset dataset,
     118      StringValue targetVariable,
     119      IntValue samplesStart, IntValue samplesEnd,
     120      DoubleValue numberOfEvaluatedNodes);
    106121  }
    107122}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs

    r3374 r3462  
    4141  [StorableClass]
    4242  public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator {
    43     protected override double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes) {
    44       double mse = Calculate(solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);
     43    protected override double Evaluate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes) {
     44      double mse = Calculate(interpreter, solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);
    4545      numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value);
    4646      return mse;
    4747    }
    4848
    49     public static double Calculate(SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {
    50       SimpleArithmeticExpressionEvaluator evaluator = new SimpleArithmeticExpressionEvaluator();
     49    public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {
    5150      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    52       var estimatedValues = evaluator.EstimatedValues(solution, dataset, Enumerable.Range(start, end - start));
     51      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start));
    5352      var originalValues = from row in Enumerable.Range(start, end - start) select dataset[row, targetVariableIndex];
    5453      return SimpleMSEEvaluator.Calculate(originalValues, estimatedValues);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs

    r3442 r3462  
    3838namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
    3939  [StorableClass]
    40   public class SymbolicRegressionModel : DeepCloneable, IModel {
     40  [Item("SymbolicRegressionModel", "A symbolic regression model represents an entity that provides estimated values based on input values.")]
     41  public class SymbolicRegressionModel : Item {
    4142    [Storable]
    4243    private SymbolicExpressionTree tree;
     
    4546    }
    4647    [Storable]
    47     private SimpleArithmeticExpressionEvaluator evaluator;
    48     public SimpleArithmeticExpressionEvaluator Evaluator {
    49       get { return evaluator; }
     48    private ISymbolicExpressionTreeInterpreter interpreter;
     49    public ISymbolicExpressionTreeInterpreter Interpreter {
     50      get { return interpreter; }
    5051    }
    51     private Dataset emptyDataset;
    52     private IEnumerable<int> firstRow = new int[] { 0 };
     52    [Storable]
     53    private List<string> inputVariables;
     54    public IEnumerable<string> InputVariables {
     55      get { return inputVariables.AsEnumerable(); }
     56    }
    5357
    5458    public SymbolicRegressionModel() : base() { } // for cloning
    5559
    56     public SymbolicRegressionModel(SymbolicExpressionTree tree, IEnumerable<string> inputVariables)
     60    public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree, IEnumerable<string> inputVariables)
    5761      : base() {
    5862      this.tree = tree;
    59       this.evaluator = new SimpleArithmeticExpressionEvaluator();
    60       emptyDataset = new Dataset(inputVariables, new double[1, inputVariables.Count()]);
     63      this.interpreter = interpreter;
     64      this.inputVariables = inputVariables.ToList();
    6165    }
    6266
    63     #region IModel Members
    64 
    65     public double GetValue(double[] xs) {
    66       if (xs.Length != emptyDataset.Columns) throw new ArgumentException("Length of input vector doesn't match model");
    67       for (int i = 0; i < xs.Length; i++) {
    68         emptyDataset[0, i] = xs[i];
    69       }
    70       return evaluator.EstimatedValues(tree, emptyDataset, firstRow).First();
     67    public IEnumerable<double> GetEstimatedValues(Dataset dataset, int start, int end) {
     68      return interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Enumerable.Range(start, end - start));
    7169    }
    7270
    73     #endregion
     71    public override IDeepCloneable Clone(Cloner cloner) {
     72      var clone = (SymbolicRegressionModel)base.Clone(cloner);
     73      clone.tree = (SymbolicExpressionTree)tree.Clone(cloner);
     74      clone.interpreter = (ISymbolicExpressionTreeInterpreter)interpreter.Clone(cloner);
     75      clone.inputVariables = new List<string>(inputVariables);
     76      return clone;
     77    }
    7478  }
    7579}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r3452 r3462  
    3434using HeuristicLab.Problems.DataAnalysis.Regression;
    3535using HeuristicLab.Problems.DataAnalysis.Symbolic;
     36using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
     37using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
     38using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
     39using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3640
    3741namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
     
    144148      var globalGrammar = new GlobalSymbolicExpressionGrammar(grammar);
    145149      var visualizer = new BestValidationSymbolicRegressionSolutionVisualizer();
     150      var interpreter = new SimpleArithmeticExpressionInterpreter();
    146151      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", new BoolValue(false)));
    147152      Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new symbolic regression solutions.", creator));
     153      Parameters.Add(new ValueParameter<ISymbolicExpressionTreeInterpreter>("SymbolicExpressionTreeInterpreter", "The interpreter that should be used to evaluate the symbolic expression tree.", interpreter));
    148154      Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
    149155      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs

    r3442 r3462  
    3636  [StorableClass]
    3737  public sealed class SymbolicRegressionSolution : DataAnalysisSolution {
    38     public new SymbolicRegressionModel Model {
    39       get { return (SymbolicRegressionModel)base.Model; }
    40       set { base.Model = value; }
     38    private SymbolicRegressionModel model;
     39    public SymbolicRegressionModel Model {
     40      get { return model; }
     41      set {
     42        if (model != value) {
     43          if (value == null) throw new ArgumentNullException();
     44          model = value;
     45          OnModelChanged(EventArgs.Empty);
     46        }
     47      }
    4148    }
    4249
    4350    public SymbolicRegressionSolution() : base() { }
    4451    public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model)
    45       : base(problemData, model) {
     52      : base(problemData) {
     53      this.model = model;
     54      RecalculateEstimatedValues();
     55    }
     56
     57    public event EventHandler ModelChanged;
     58    private void OnModelChanged(EventArgs e) {
     59      RecalculateEstimatedValues();
     60      var listeners = ModelChanged;
     61      if (listeners != null)
     62        listeners(this, e);
     63    }
     64
     65    protected override void OnProblemDataChanged(EventArgs e) {
     66      RecalculateEstimatedValues();
     67    }
     68
     69    private void RecalculateEstimatedValues() {
     70      estimatedValues = model.GetEstimatedValues(ProblemData.Dataset, 0, ProblemData.Dataset.Rows).ToList();
     71      OnEstimatedValuesChanged(EventArgs.Empty);
     72    }
     73
     74    private List<double> estimatedValues;
     75    public override IEnumerable<double> EstimatedValues {
     76      get {
     77        return estimatedValues.AsEnumerable();
     78      }
     79    }
     80
     81    public override IEnumerable<double> EstimatedTrainingValues {
     82      get {
     83        int start = ProblemData.TrainingSamplesStart.Value;
     84        int n = ProblemData.TrainingSamplesEnd.Value - start;
     85        return estimatedValues.Skip(start).Take(n).ToList();
     86      }
     87    }
     88
     89    public override IEnumerable<double> EstimatedTestValues {
     90      get {
     91        int start = ProblemData.TestSamplesStart.Value;
     92        int n = ProblemData.TestSamplesEnd.Value - start;
     93        return estimatedValues.Skip(start).Take(n).ToList();
     94      }
    4695    }
    4796  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/DataAnalysisProblemDataView.cs

    r3442 r3462  
    2929      : this() {
    3030      Content = content;
    31       variableCollectionView.Content = content.Variables.AsReadOnly();
     31    }
     32
     33    protected override void OnContentChanged() {
     34      base.OnContentChanged();
     35      variableCollectionView.Content = Content.Variables.AsReadOnly();
    3236    }
    3337
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/EstimatedValuesView.cs

    r3442 r3462  
    6868    protected override void RegisterContentEvents() {
    6969      base.RegisterContentEvents();
    70       Content.ModelChanged += new EventHandler(Content_ModelChanged);
     70      Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
    7171      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    7272    }
     
    7474    protected override void DeregisterContentEvents() {
    7575      base.DeregisterContentEvents();
    76       Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     76      Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
    7777      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
    7878    }
     
    8282    }
    8383
    84     void Content_ModelChanged(object sender, EventArgs e) {
     84    void Content_EstimatedValuesChanged(object sender, EventArgs e) {
    8585      OnContentChanged();
    8686    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/LineChartView.cs

    r3442 r3462  
    6565      : this() {
    6666      Content = dataAnalysisSolution;
    67       DrawTargetVariableValues();
    68       DrawEstimatedValues();
     67      RedrawChart();
    6968    }
    7069
    71     private void DrawEstimatedValues() {
     70    private void RedrawChart() {
     71      this.chart.Series.Clear();
     72      this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
     73      this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable.Value;
     74      this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     75      this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset[Content.ProblemData.TargetVariable.Value]);
     76      this.UpdateStripLines();
     77
    7278      this.chart.Series.Add(ESTIMATEDVALUES_SERIES_NAME);
    7379      this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].LegendText = Content.ItemName;
     
    7783    }
    7884
    79     private void DrawTargetVariableValues() {
    80       this.chart.Series.Clear();
    81       this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
    82       this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable.Value;
    83       this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    84       this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset[Content.ProblemData.TargetVariable.Value]);
    85       this.UpdateStripLines();
    86     }
    87 
    8885    #region events
    8986    protected override void RegisterContentEvents() {
    9087      base.RegisterContentEvents();
    91       Content.ModelChanged += new EventHandler(Content_ModelChanged);
     88      Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
    9289      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    9390    }
     
    9592    protected override void DeregisterContentEvents() {
    9693      base.DeregisterContentEvents();
    97       Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     94      Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
    9895      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
    9996    }
    10097
    10198    void Content_ProblemDataChanged(object sender, EventArgs e) {
    102       OnContentChanged();
     99      RedrawChart();
    103100    }
    104101
    105     void Content_ModelChanged(object sender, EventArgs e) {
    106       OnContentChanged();
     102    void Content_EstimatedValuesChanged(object sender, EventArgs e) {
     103      UpdateEstimatedValuesLineChart();
    107104    }
    108105
    109106    protected override void OnContentChanged() {
    110107      base.OnContentChanged();
    111       UpdateEstimatedValuesLineChart();
     108      RedrawChart();
    112109    }
    113110
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.cs

    r3442 r3462  
    8484      : this() {
    8585      Content = dataAnalysisSolution;
     86      UpdateChart();
    8687    }
    8788
    8889    protected override void RegisterContentEvents() {
    8990      base.RegisterContentEvents();
    90       Content.ModelChanged += new EventHandler(Content_ModelChanged);
     91      Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
    9192      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    9293    }
    9394    protected override void DeregisterContentEvents() {
    9495      base.DeregisterContentEvents();
    95       Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     96      Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
    9697      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
    9798    }
     
    99100
    100101    void Content_ProblemDataChanged(object sender, EventArgs e) {
    101       OnContentChanged();
    102     }
    103 
    104     void Content_ModelChanged(object sender, EventArgs e) {
    105       OnContentChanged();
     102      UpdateChart();
     103    }
     104
     105    void Content_EstimatedValuesChanged(object sender, EventArgs e) {
     106      UpdateSeries();
    106107    }
    107108
     
    127128
    128129    private void UpdateSeries() {
    129       string targetVariableName = Content.ProblemData.TargetVariable.Value;
    130       Dataset dataset = Content.ProblemData.Dataset;
    131       int trainingStart = Content.ProblemData.TrainingSamplesStart.Value;
    132       int trainingEnd = Content.ProblemData.TrainingSamplesEnd.Value;
    133       int testStart = Content.ProblemData.TestSamplesStart.Value;
    134       int testEnd = Content.ProblemData.TestSamplesEnd.Value;
    135       if (this.chart.Series[ALL_SERIES].Points.Count > 0)
    136         this.chart.Series[ALL_SERIES].Points.DataBindXY(Content.EstimatedValues.ToArray(), "",
    137           dataset[targetVariableName], "");
    138       if (this.chart.Series[TRAINING_SERIES].Points.Count > 0)
    139         this.chart.Series[TRAINING_SERIES].Points.DataBindXY(Content.EstimatedTrainingValues.ToArray(), "",
    140           dataset.GetVariableValues(targetVariableName, trainingStart, trainingEnd), "");
    141       if (this.chart.Series[TEST_SERIES].Points.Count > 0)
    142         this.chart.Series[TEST_SERIES].Points.DataBindXY(Content.EstimatedTestValues.ToArray(), "",
    143           dataset.GetVariableValues(targetVariableName, testStart, testEnd), "");
    144 
    145       double max = Math.Max(Content.EstimatedValues.Max(), dataset.GetMax(targetVariableName));
    146       double min = Math.Min(Content.EstimatedValues.Min(), dataset.GetMin(targetVariableName));
    147 
    148       max = Math.Ceiling(max) * 1.2;
    149       min = Math.Floor(min) * 0.8;
    150 
    151       this.chart.ChartAreas[0].AxisX.Maximum = max;
    152       this.chart.ChartAreas[0].AxisX.Minimum = min;
    153       this.chart.ChartAreas[0].AxisY.Maximum = max;
    154       this.chart.ChartAreas[0].AxisY.Minimum = min;
     130      if (InvokeRequired) Invoke((Action)UpdateSeries);
     131      else {
     132        string targetVariableName = Content.ProblemData.TargetVariable.Value;
     133        Dataset dataset = Content.ProblemData.Dataset;
     134        int trainingStart = Content.ProblemData.TrainingSamplesStart.Value;
     135        int trainingEnd = Content.ProblemData.TrainingSamplesEnd.Value;
     136        int testStart = Content.ProblemData.TestSamplesStart.Value;
     137        int testEnd = Content.ProblemData.TestSamplesEnd.Value;
     138        if (this.chart.Series[ALL_SERIES].Points.Count > 0)
     139          this.chart.Series[ALL_SERIES].Points.DataBindXY(Content.EstimatedValues.ToArray(), "",
     140            dataset[targetVariableName], "");
     141        if (this.chart.Series[TRAINING_SERIES].Points.Count > 0)
     142          this.chart.Series[TRAINING_SERIES].Points.DataBindXY(Content.EstimatedTrainingValues.ToArray(), "",
     143            dataset.GetVariableValues(targetVariableName, trainingStart, trainingEnd), "");
     144        if (this.chart.Series[TEST_SERIES].Points.Count > 0)
     145          this.chart.Series[TEST_SERIES].Points.DataBindXY(Content.EstimatedTestValues.ToArray(), "",
     146            dataset.GetVariableValues(targetVariableName, testStart, testEnd), "");
     147
     148        double max = Math.Max(Content.EstimatedValues.Max(), dataset.GetMax(targetVariableName));
     149        double min = Math.Min(Content.EstimatedValues.Min(), dataset.GetMin(targetVariableName));
     150
     151        max = Math.Ceiling(max) * 1.2;
     152        min = Math.Floor(min) * 0.8;
     153
     154        this.chart.ChartAreas[0].AxisX.Maximum = max;
     155        this.chart.ChartAreas[0].AxisX.Minimum = min;
     156        this.chart.ChartAreas[0].AxisY.Maximum = max;
     157        this.chart.ChartAreas[0].AxisY.Minimum = min;
     158      }
    155159    }
    156160
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/SimplifiedSymbolicExpressionModelView.cs

    r3461 r3462  
    4444    public new SymbolicRegressionSolution Content {
    4545      get { return (SymbolicRegressionSolution)base.Content; }
    46       set {        base.Content = value;      }
     46      set { base.Content = value; }
    4747    }
    4848
     
    5858    }
    5959
     60    protected override void RegisterContentEvents() {
     61      base.RegisterContentEvents();
     62      Content.ModelChanged += new EventHandler(Content_ModelChanged);
     63    }
     64
     65    protected override void DeregisterContentEvents() {
     66      base.DeregisterContentEvents();
     67      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     68    }
     69
     70    void Content_ModelChanged(object sender, EventArgs e) {
     71      UpdateTreeChart();
     72    }
     73
    6074    protected override void OnContentChanged() {
    6175      base.OnContentChanged();
     76      UpdateTreeChart();
     77    }
     78
     79    private void UpdateTreeChart() {
    6280      var simplifier = new SymbolicSimplifier();
    6381      var simplifiedTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/SymbolicExpressionModelView.cs

    r3461 r3462  
    5757    }
    5858
     59
     60    protected override void RegisterContentEvents() {
     61      base.RegisterContentEvents();
     62      Content.ModelChanged += new EventHandler(Content_ModelChanged);
     63    }
     64
     65    protected override void DeregisterContentEvents() {
     66      base.DeregisterContentEvents();
     67      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
     68    }
     69
     70    void Content_ModelChanged(object sender, EventArgs e) {
     71      UpdateTreeChart();
     72    }
     73
    5974    protected override void OnContentChanged() {
    6075      base.OnContentChanged();
     76      UpdateTreeChart();
     77    }
     78
     79    private void UpdateTreeChart() {
    6180      viewHost.Content = Content.Model.SymbolicExpressionTree;
    6281    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs

    r3452 r3462  
    3535  [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")]
    3636  [StorableClass]
    37   public class DataAnalysisSolution : Item {
    38     [Storable]
    39     private IModel model;
    40     public IModel Model {
    41       get { return model; }
    42       set {
    43         if (model != value) {
    44           model = value;
    45           OnModelChanged();
    46         }
    47       }
    48     }
    49 
     37  public abstract class DataAnalysisSolution : Item {
    5038    [Storable]
    5139    private DataAnalysisProblemData problemData;
     
    5846          problemData = value;
    5947          RegisterProblemDataEvents();
    60           OnProblemDataChanged();
     48          OnProblemDataChanged(EventArgs.Empty);
    6149        }
    6250      }
    6351    }
    6452
    65     private List<double> estimatedValues;
    66     public IEnumerable<double> EstimatedValues {
    67       get {
    68         return estimatedValues;
    69       }
    70     }
     53    public abstract IEnumerable<double> EstimatedValues { get; }
     54    public abstract IEnumerable<double> EstimatedTrainingValues { get; }
     55    public abstract IEnumerable<double> EstimatedTestValues { get; }
    7156
    72     private List<double> estimatedTrainingValues;
    73     public IEnumerable<double> EstimatedTrainingValues {
    74       get {
    75         return estimatedTrainingValues;
    76       }
    77     }
    78 
    79     private List<double> estimatedTestValues;
    80     public IEnumerable<double> EstimatedTestValues {
    81       get {
    82         return estimatedTestValues;
    83       }
    84     }
    85 
    86     public DataAnalysisSolution() : base() { }
    87     public DataAnalysisSolution(DataAnalysisProblemData problemData, IModel model)
     57    protected DataAnalysisSolution() : base() { }
     58    protected DataAnalysisSolution(DataAnalysisProblemData problemData)
    8859      : this() {
    8960      this.problemData = problemData;
    90       this.model = model;
    9161      Initialize();
    9262    }
     
    9868    private void Initialize() {
    9969      if (problemData != null) RegisterProblemDataEvents();
    100       if (problemData != null && model != null) RecalculateEstimatedValues();
    101     }
    102 
    103     private void RecalculateEstimatedValues() {
    104       estimatedValues = GetEstimatedValues(0, problemData.Dataset.Rows).ToList();
    105       int nTrainingValues = problemData.TrainingSamplesEnd.Value - problemData.TrainingSamplesStart.Value;
    106       estimatedTrainingValues = estimatedValues.Skip(problemData.TrainingSamplesStart.Value).Take(nTrainingValues).ToList();
    107       int nTestValues = problemData.TestSamplesEnd.Value - problemData.TestSamplesStart.Value;
    108       estimatedTestValues = estimatedValues.Skip(problemData.TestSamplesStart.Value).Take(nTestValues).ToList();
    109     }
    110 
    111     private IEnumerable<double> GetEstimatedValues(int start, int end) {
    112       double[] xs = new double[ProblemData.InputVariables.Count];
    113       for (int row = 0; row < ProblemData.Dataset.Rows; row++) {
    114         for (int i = 0; i < xs.Length; i++) {
    115           var variableIndex = ProblemData.Dataset.GetVariableIndex(ProblemData.InputVariables[i].Value);
    116           xs[i] = ProblemData.Dataset[row, variableIndex];
    117         }
    118         yield return model.GetValue(xs);
    119       }
    12070    }
    12171
    12272    public override IDeepCloneable Clone(Cloner cloner) {
    123       DataAnalysisSolution clone = new DataAnalysisSolution();
    124       cloner.RegisterClonedObject(this, clone);
    125       clone.model = (IModel)cloner.Clone(model);
     73      DataAnalysisSolution clone = (DataAnalysisSolution)base.Clone(cloner);
     74      // don't clone the problem data!
    12675      clone.problemData = problemData;
    12776      clone.Initialize();
     
    13079
    13180    #region Events
    132     public event EventHandler ModelChanged;
    133     private void OnModelChanged() {
    134       RecalculateEstimatedValues();
    135       var changed = ModelChanged;
    136       if (changed != null)
    137         changed(this, EventArgs.Empty);
    138     }
    139     public event EventHandler ProblemDataChanged;
    140     private void OnProblemDataChanged() {
    141       RecalculateEstimatedValues();
    142       var changed = ProblemDataChanged;
    143       if (changed != null)
    144         changed(this, EventArgs.Empty);
    145     }
    146 
    147     private void RegisterProblemDataEvents() {
     81    protected virtual void RegisterProblemDataEvents() {
    14882      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
    14983    }
    150     private void DeregisterProblemDataEvents() {
     84    protected virtual void DeregisterProblemDataEvents() {
    15185      ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed);
    15286    }
    15387
    15488    private void ProblemData_Changed(object sender, EventArgs e) {
    155       OnProblemDataChanged();
     89      OnProblemDataChanged(EventArgs.Empty);
     90    }
     91
     92    public event EventHandler ProblemDataChanged;
     93    protected virtual void OnProblemDataChanged(EventArgs e) {
     94      var listeners = ProblemDataChanged;
     95      if (listeners != null)
     96        listeners(this, e);
     97    }
     98
     99    public event EventHandler EstimatedValuesChanged;
     100    protected virtual void OnEstimatedValuesChanged(EventArgs e) {
     101      var listeners = EstimatedValuesChanged;
     102      if (listeners != null)
     103        listeners(this, e);
    156104    }
    157105    #endregion
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMSEEvaluator.cs

    r3452 r3462  
    7373                     select values[row, ORIGINAL_INDEX];
    7474      var estimated = from row in Enumerable.Range(0, values.Rows)
    75                       select values[row, ORIGINAL_INDEX];
     75                      select values[row, ESTIMATION_INDEX];
    7676      return Calculate(original, estimated);
    7777    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleNMSEEvaluator.cs

    r3452 r3462  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r3452 r3462  
    9898    <Compile Include="Evaluators\SimpleVarianceAccountedForEvaluator.cs" />
    9999    <Compile Include="HeuristicLabProblemsDataAnalysisPlugin.cs" />
    100     <Compile Include="Interfaces\IModel.cs" />
    101100    <Compile Include="MatrixExtensions.cs" />
    102101    <Compile Include="Properties\AssemblyInfo.cs" />
    103     <Compile Include="Statistics.cs" />
    104102    <Compile Include="Symbolic\ArithmeticExpressionGrammar.cs" />
    105     <Compile Include="Symbolic\SimpleArithmeticExpressionEvaluator.cs" />
     103    <Compile Include="Symbolic\ISymbolicExpressionTreeInterpreter.cs" />
     104    <Compile Include="Symbolic\SimpleArithmeticExpressionInterpreter.cs" />
    106105    <Compile Include="Symbolic\SymbolicSimplifier.cs" />
     106    <Compile Include="Symbolic\Symbols\Addition.cs" />
    107107    <Compile Include="Symbolic\Symbols\Constant.cs" />
    108108    <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" />
     109    <Compile Include="Symbolic\Symbols\Division.cs" />
     110    <Compile Include="Symbolic\Symbols\Multiplication.cs" />
     111    <Compile Include="Symbolic\Symbols\Subtraction.cs" />
    109112    <Compile Include="Symbolic\Symbols\Variable.cs" />
    110113    <Compile Include="Symbolic\Symbols\VariableTreeNode.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs

    r3442 r3462  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3030using HeuristicLab.Data;
    3131using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r3456 r3462  
    2626using System.Collections.Generic;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2929using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler;
    3031
    3132namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3233  [StorableClass]
    33   [Item("SimpleArithmeticExpressionEvaluator", "Default evaluator for arithmetic symbolic expression trees.")]
    34   public class SimpleArithmeticExpressionEvaluator {
     34  [Item("SimpleArithmeticExpressionInterpreter", "Interpreter for arithmetic symbolic expression trees including function calls.")]
     35  public class SimpleArithmeticExpressionInterpreter : Item, ISymbolicExpressionTreeInterpreter {
     36    private class OpCodes {
     37      public const byte Add = 1;
     38      public const byte Sub = 2;
     39      public const byte Mul = 3;
     40      public const byte Div = 4;
     41      public const byte Variable = 5;
     42      public const byte Constant = 6;
     43      public const byte Call = 100;
     44      public const byte Arg = 101;
     45    }
     46
    3547    private Dataset dataset;
    3648    private int row;
    3749    private Instruction[] code;
    3850    private int pc;
    39     public IEnumerable<double> EstimatedValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     51
     52    public IEnumerable<double> GetSymbolicExpressionTreeValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    4053      this.dataset = dataset;
    4154      var compiler = new SymbolicExpressionTreeCompiler();
    42       code = compiler.Compile(tree);
     55      compiler.AddInstructionPostProcessingHook(PostProcessInstruction);
     56      code = compiler.Compile(tree, MapSymbolToOpCode);
    4357      foreach (var row in rows) {
    4458        this.row = row;
     
    5165    }
    5266
     67    private Instruction PostProcessInstruction(Instruction instr) {
     68      if (instr.opCode == OpCodes.Variable) {
     69        var variableTreeNode = instr.dynamicNode as VariableTreeNode;
     70        instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);
     71      }
     72      return instr;
     73    }
     74
     75    private byte MapSymbolToOpCode(SymbolicExpressionTreeNode treeNode) {
     76      if (treeNode.Symbol is Addition) return OpCodes.Add;
     77      if (treeNode.Symbol is Subtraction) return OpCodes.Sub;
     78      if (treeNode.Symbol is Multiplication) return OpCodes.Mul;
     79      if (treeNode.Symbol is Division) return OpCodes.Div;
     80      if (treeNode.Symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable) return OpCodes.Variable;
     81      if (treeNode.Symbol is Constant) return OpCodes.Constant;
     82      if (treeNode.Symbol is InvokeFunction) return OpCodes.Call;
     83      if (treeNode.Symbol is Argument) return OpCodes.Arg;
     84      throw new NotSupportedException("Symbol: " + treeNode.Symbol);
     85    }
     86
    5387    private Stack<List<double>> argumentStack = new Stack<List<double>>();
    5488    public double Evaluate() {
    5589      var currentInstr = code[pc++];
    56       switch (currentInstr.symbol) {
    57         case CodeSymbol.Add: {
     90      switch (currentInstr.opCode) {
     91        case OpCodes.Add: {
    5892            double s = 0.0;
    5993            for (int i = 0; i < currentInstr.nArguments; i++) {
     
    6296            return s;
    6397          }
    64         case CodeSymbol.Sub: {
     98        case OpCodes.Sub: {
    6599            double s = Evaluate();
    66100            for (int i = 1; i < currentInstr.nArguments; i++) {
     
    69103            return s;
    70104          }
    71         case CodeSymbol.Mul: {
     105        case OpCodes.Mul: {
    72106            double p = Evaluate();
    73107            for (int i = 1; i < currentInstr.nArguments; i++) {
     
    76110            return p;
    77111          }
    78         case CodeSymbol.Div: {
     112        case OpCodes.Div: {
    79113            double p = Evaluate();
    80114            for (int i = 1; i < currentInstr.nArguments; i++) {
     
    83117            return p;
    84118          }
    85         case CodeSymbol.Call: {
     119        case OpCodes.Call: {
    86120            // save current arguments
    87121            List<double> arguments = new List<double>();
     
    102136            return v;
    103137          }
    104         case CodeSymbol.Arg: {
     138        case OpCodes.Arg: {
    105139            return argumentStack.Peek()[currentInstr.iArg0];
    106140          }
    107         case CodeSymbol.Dynamic: {
     141        case OpCodes.Variable: {
    108142            var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode;
    109             if (variableTreeNode != null) {
    110               return dataset[row, dataset.GetVariableIndex(variableTreeNode.VariableName)] * variableTreeNode.Weight;
    111             }
     143            return dataset[row, currentInstr.iArg0] * variableTreeNode.Weight;
     144          }
     145        case OpCodes.Constant: {
    112146            var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode;
    113             if (constTreeNode != null) {
    114               return constTreeNode.Value;
    115             } else throw new NotSupportedException();
     147            return constTreeNode.Value;
    116148          }
    117149        default: throw new NotSupportedException();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs

    r3442 r3462  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2828using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    2929using System.Diagnostics;
     
    3838  /// </summary>
    3939  public class SymbolicSimplifier {
     40    private Addition addSymbol = new Addition();
     41    private Multiplication mulSymbol = new Multiplication();
     42    private Division divSymbol = new Division();
     43    private Constant constSymbol = new Constant();
     44    private Variable varSymbol = new Variable();
     45
    4046    public SymbolicExpressionTree Simplify(SymbolicExpressionTree originalTree) {
    4147      var clone = (SymbolicExpressionTreeNode)originalTree.Root.Clone();
     
    194200        return a;
    195201      } else {
    196         var div = (new Division()).CreateTreeNode();
     202        var div = divSymbol.CreateTreeNode();
    197203        div.SubTrees.Add(a);
    198204        div.SubTrees.Add(b);
     
    215221      } else if (IsAddition(a) && IsAddition(b)) {
    216222        // merge additions
    217         var add = (new Addition()).CreateTreeNode();
     223        var add = addSymbol.CreateTreeNode();
    218224        for (int i = 0; i < a.SubTrees.Count - 1; i++) add.AddSubTree(a.SubTrees[i]);
    219225        for (int i = 0; i < b.SubTrees.Count - 1; i++) add.AddSubTree(b.SubTrees[i]);
     
    232238        return MakeAddition(b, a);
    233239      } else if (IsAddition(a) && IsConstant(b)) {
    234         var add = (new Addition()).CreateTreeNode();
     240        var add = addSymbol.CreateTreeNode();
    235241        for (int i = 0; i < a.SubTrees.Count - 1; i++) add.AddSubTree(a.SubTrees[i]);
    236242        if (IsConstant(a.SubTrees.Last()))
     
    242248        return add;
    243249      } else if (IsAddition(a)) {
    244         var add = (new Addition()).CreateTreeNode();
     250        var add = addSymbol.CreateTreeNode();
    245251        add.AddSubTree(b);
    246252        foreach (var subTree in a.SubTrees) {
     
    250256        return add;
    251257      } else {
    252         var add = (new Addition()).CreateTreeNode();
     258        var add = addSymbol.CreateTreeNode();
    253259        add.SubTrees.Add(a);
    254260        add.SubTrees.Add(b);
     
    296302        return MakeDivision(MakeMultiplication(b.SubTrees[0], a), b.SubTrees[1]);
    297303      } else if (IsMultiplication(a) && IsMultiplication(b)) {
    298         var mul = (new Multiplication()).CreateTreeNode();
     304        var mul = mulSymbol.CreateTreeNode();
    299305        for (int i = 0; i < a.SubTrees.Count - 1; i++) mul.AddSubTree(a.SubTrees[i]);
    300306        for (int i = 0; i < b.SubTrees.Count - 1; i++) mul.AddSubTree(b.SubTrees[i]);
     
    302308        return mul;
    303309      } else if (IsMultiplication(a)) {
    304         var mul = (new Multiplication()).CreateTreeNode();
     310        var mul = mulSymbol.CreateTreeNode();
    305311        for (int i = 0; i < a.SubTrees.Count - 1; i++) mul.AddSubTree(a.SubTrees[i]);
    306312        mul.AddSubTree(MakeMultiplication(a.SubTrees.Last(), b));
    307313        return mul;
    308314      } else if (IsMultiplication(b)) {
    309         var mul = (new Multiplication()).CreateTreeNode();
     315        var mul = mulSymbol.CreateTreeNode();
    310316        for (int i = 0; i < b.SubTrees.Count - 1; i++) mul.AddSubTree(b.SubTrees[i]);
    311317        mul.AddSubTree(MakeMultiplication(b.SubTrees.Last(), a));
    312318        return mul;
    313319      } else {
    314         var mul = (new Multiplication()).CreateTreeNode();
     320        var mul = mulSymbol.CreateTreeNode();
    315321        mul.SubTrees.Add(a);
    316322        mul.SubTrees.Add(b);
     
    346352
    347353    private SymbolicExpressionTreeNode MakeConstant(double value) {
    348       ConstantTreeNode constantTreeNode = (ConstantTreeNode)(new Constant().CreateTreeNode());
     354      ConstantTreeNode constantTreeNode = (ConstantTreeNode)(constSymbol.CreateTreeNode());
    349355      constantTreeNode.Value = value;
    350356      return (SymbolicExpressionTreeNode)constantTreeNode;
     
    352358
    353359    private SymbolicExpressionTreeNode MakeVariable(double weight, string name) {
    354       var tree = (VariableTreeNode)(new Variable().CreateTreeNode());
     360      var tree = (VariableTreeNode)varSymbol.CreateTreeNode();
    355361      tree.Weight = weight;
    356362      tree.VariableName = name;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Addition.cs

    r3456 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     26namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    2627  [StorableClass]
    2728  [Item("Addition", "Symbol that represents the + operator.")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Constant.cs

    r3376 r3462  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828using HeuristicLab.Parameters;
     29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    3031  [StorableClass]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Division.cs

    r3456 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     26namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    2627  [StorableClass]
    2728  [Item("Division", "Symbol that represents the / operator.")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Multiplication.cs

    r3456 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     26namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    2627  [StorableClass]
    2728  [Item("Multiplication", "Symbol that represents the * operator.")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Subtraction.cs

    r3456 r3462  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols {
     25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     26namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    2627  [StorableClass]
    2728  [Item("Subtraction", "Symbol that represents the - operator.")]
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs

    r3442 r3462  
    3030using System.Collections.Generic;
    3131using System;
     32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    3233namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols {
    3334  [StorableClass]
Note: See TracChangeset for help on using the changeset viewer.