Changeset 3462 for trunk/sources
- Timestamp:
- 04/21/10 15:21:34 (14 years ago)
- 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 25 25 using System.Linq; 26 26 27 namespace HeuristicLab. Problems.DataAnalysis{28 public static class StatisticExtensions {27 namespace HeuristicLab.Common { 28 public static class EnumerableStatisticExtensions { 29 29 /// <summary> 30 30 /// Calculates the median element of the enumeration. -
trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
r3405 r3462 95 95 <Compile Include="DeepCloneable.cs" /> 96 96 <Compile Include="Content\IContent.cs" /> 97 <Compile Include="EnumerableStatisticExtensions.cs" /> 97 98 <Compile Include="IDeepCloneable.cs" /> 98 99 <Compile Include="ReferenceEqualityComparer.cs" /> -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentCreater.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDeleter.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDuplicater.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/GrammarModifier.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/RandomArchitectureAlteringOperator.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineCreater.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDeleter.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; 34 34 using System.Diagnostics; 35 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 35 36 36 37 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs
r3376 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SymbolicExpressionTreeArchitectureAlteringOperator.cs
r3456 r3462 29 29 using HeuristicLab.Parameters; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 32 using System.Collections.Generic; 33 33 using System.Text; 34 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators; 34 35 35 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {36 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators { 36 37 /// <summary> 37 38 /// Base class for architecture altering operators for symbolic expression trees. -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Compiler/Instruction.cs
r3456 r3462 26 26 using System.Collections.Generic; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 29 29 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 }; 30 namespace 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) 41 34 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 42 40 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; 46 43 } 47 44 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Compiler/SymbolicExpressionTreeCompiler.cs
r3456 r3462 27 27 using System.Collections.Generic; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler { 32 32 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>>(); 43 35 44 public Instruction[] Compile(SymbolicExpressionTree tree ) {36 public Instruction[] Compile(SymbolicExpressionTree tree, Func<SymbolicExpressionTreeNode, byte> opCodeMapper) { 45 37 List<Instruction> code = new List<Instruction>(); 46 38 entryPoint.Clear(); 47 39 // compile main body 48 code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0] ));40 code.AddRange(Compile(tree.Root.SubTrees[0].SubTrees[0], opCodeMapper)); 49 41 // compile branches 50 42 var functionBranches = from node in tree.IterateNodesPrefix() … … 52 44 select node; 53 45 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)); 56 49 } 57 50 // address of all functions is fixed now … … 59 52 for (int i = 0; i < code.Count; i++) { 60 53 Instruction instr = code[i]; 61 if (instr. symbol == CodeSymbol.Call) {54 if (instr.dynamicNode.Symbol is InvokeFunction) { 62 55 var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode; 63 56 instr.iArg0 = entryPoint[invokeNode.Symbol.FunctionName]; 64 instr.dynamicNode = null;65 57 code[i] = instr; 66 58 } … … 70 62 } 71 63 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()) { 74 66 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)"); 76 68 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); 88 77 } 89 78 yield return instr; … … 91 80 } 92 81 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); 99 89 } 100 90 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3442 r3462 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 24 using System.Collections.Generic; 25 using System.Text; 22 26 using HeuristicLab.Common; 23 27 using HeuristicLab.Core; 24 28 using HeuristicLab.Data; 25 29 using HeuristicLab.Random; 26 using System;27 using System.Linq;28 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Collections.Generic;30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;31 using System.Text;32 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 33 34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 33 34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators { 35 35 [StorableClass] 36 36 [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 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators { 32 32 /// <summary> 33 33 /// A base class for operators creating symbolic expression trees. -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs
r3376 r3462 28 28 using System; 29 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols; 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 31 33 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers { 34 33 /// <summary> 35 34 /// 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 30 30 using System.Diagnostics; 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers { 33 33 /// <summary> 34 34 /// A base class for operators that perform a crossover of symbolic expression trees. -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs
r3376 r3462 28 28 using System.Xml; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 31 31 32 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
r3376 r3462 28 28 using System.Xml; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 31 31 32 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj
r3384 r3462 93 93 <Compile Include="ArchitectureAlteringOperators\SubroutineDeleter.cs" /> 94 94 <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" /> 95 101 <Compile Include="SymbolicExpressionTreeTopLevelNode.cs" /> 96 102 <Compile Include="Crossovers\SubtreeCrossover.cs"> … … 102 108 <SubType>Code</SubType> 103 109 </Compile> 104 <Compile Include="SymbolicExpressionTreeArchitectureAlteringOperator.cs" />105 110 <Compile Include="SymbolicExpressionTreeOperator.cs" /> 106 <Compile Include="Instruction.cs" />107 <Compile Include="SymbolicExpressionTreeCompiler.cs" />108 <Compile Include="SymbolicExpressionTreeManipulator.cs" />109 111 <Compile Include="SymbolicExpressionTreeTerminalNode.cs" /> 110 112 <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" /> … … 112 114 <Compile Include="HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs" /> 113 115 <Compile Include="Interfaces\ISymbolicExpressionTreeOperator.cs" /> 114 <Compile Include="SymbolicExpressionTreeCreator.cs" />115 116 <Compile Include="SymbolicExpressionTree.cs" /> 116 117 <Compile Include="Properties\AssemblyInfo.cs" /> 117 <Compile Include="Symbol.cs" />118 <Compile Include="SymbolicExpressionTreeCrossover.cs" />119 118 <Compile Include="SymbolicExpressionTreeNode.cs" /> 120 <Compile Include="Symbols\Addition.cs" />121 119 <Compile Include="Symbols\Argument.cs" /> 122 120 <Compile Include="Symbols\ArgumentTreeNode.cs" /> … … 127 125 <Compile Include="Symbols\Defun.cs" /> 128 126 <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" /> 132 128 </ItemGroup> 133 129 <ItemGroup> … … 178 174 </ProjectReference> 179 175 </ItemGroup> 180 <ItemGroup>181 <Folder Include="Manipulators\" />182 </ItemGroup>183 176 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 184 177 <!-- 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 28 28 using System.Xml; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs
r3456 r3462 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators { 31 31 /// <summary> 32 32 /// A base class for operators that manipulate real-valued vectors. -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs
r3442 r3462 30 30 using HeuristicLab.Data; 31 31 using System.Diagnostics; 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 33 33 34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 38 39 [Storable] 39 40 private Symbol symbol; 40 //[Storable] 41 42 // parent relation is not persisted or cloned (will be set on AddSubtree or RemoveSubtree) 41 43 private SymbolicExpressionTreeNode parent; 42 44 -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTerminalNode.cs
r3376 r3462 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 using HeuristicLab.Data; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTopLevelNode.cs
r3376 r3462 30 30 using HeuristicLab.Data; 31 31 using System.Diagnostics; 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 33 33 34 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 44 45 45 46 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 54 48 internal override ISymbolicExpressionGrammar Grammar { 55 49 get { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Argument.cs
r3376 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 26 26 /// <summary> 27 27 /// Symbol for function arguments -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ArgumentTreeNode.cs
r3369 r3462 22 22 using System; 23 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 25 25 [StorableClass] 26 26 public sealed class ArgumentTreeNode : SymbolicExpressionTreeNode { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Defun.cs
r3376 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 26 26 /// <summary> 27 27 /// Symbol for function defining branches -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs
r3442 r3462 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 27 27 [StorableClass] 28 28 public sealed class DefunTreeNode : SymbolicExpressionTreeTopLevelNode { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunction.cs
r3376 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 26 26 /// <summary> 27 27 /// Symbol for invoking automatically defined functions -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunctionTreeNode.cs
r3369 r3462 22 22 using System; 23 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 25 25 [StorableClass] 26 26 public sealed class InvokeFunctionTreeNode : SymbolicExpressionTreeNode { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ProgramRootSymbol.cs
r3376 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 26 26 [StorableClass] 27 27 [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 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols {25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 26 26 [StorableClass] 27 27 [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 30 30 using HeuristicLab.Parameters; 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { 33 33 [StorableClass] 34 34 [Item("Symbol", "Represents a symbol in a symbolic function tree.")] -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/AllArchitectureAlteringOperatorsTest.cs
r3369 r3462 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 31 using HeuristicLab.Data; 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 33 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers; 32 34 33 35 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentCreaterTest.cs
r3360 r3462 29 29 using System.Diagnostics; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentDeleterTest.cs
r3360 r3462 29 29 using System.Diagnostics; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentDuplicaterTest.cs
r3360 r3462 29 29 using System.Diagnostics; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/Grammars.cs
r3369 r3462 28 28 using HeuristicLab.Random; 29 29 using System.Diagnostics; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 31 31 32 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ProbabilisticTreeCreaterTest.cs
r3369 r3462 28 28 using HeuristicLab.Random; 29 29 using System.Diagnostics; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineCreaterTest.cs
r3360 r3462 29 29 using System.Diagnostics; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineDeleterTest.cs
r3360 r3462 29 29 using System.Diagnostics; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineDuplicaterTest.cs
r3360 r3462 29 29 using System.Diagnostics; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 31 32 32 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubtreeCrossoverTest.cs
r3360 r3462 28 28 using HeuristicLab.Random; 29 29 using System.Diagnostics; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 30 32 31 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests { -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntInterpreter.cs
r3457 r3462 25 25 using HeuristicLab.Data; 26 26 using System.Collections.Generic; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 using HeuristicLab.Problems.ArtificialAnt.Symbols; 28 29 29 30 namespace HeuristicLab.Problems.ArtificialAnt { -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs
r3376 r3462 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 31 using HeuristicLab.Problems.ArtificialAnt.Symbols; 31 32 namespace HeuristicLab.Problems.ArtificialAnt { 32 33 [StorableClass] -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs
r3338 r3462 32 32 using HeuristicLab.PluginInfrastructure; 33 33 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 34 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 35 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers; 36 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators; 37 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 34 38 35 39 namespace HeuristicLab.Problems.ArtificialAnt { -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/IfFoodAhead.cs
r3376 r3462 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 namespace HeuristicLab.Problems.ArtificialAnt { 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { 27 28 [StorableClass] 28 29 [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 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 namespace HeuristicLab.Problems.ArtificialAnt { 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { 27 28 [StorableClass] 28 29 [Item("Left", "Represents the turn-left symbol in a artificial ant expression.")] -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Move.cs
r3376 r3462 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 namespace HeuristicLab.Problems.ArtificialAnt { 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { 27 28 [StorableClass] 28 29 [Item("Move", "Represents the move-forward symbol in a artificial ant expression.")] -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Symbols/Prog2.cs
r3376 r3462 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 namespace HeuristicLab.Problems.ArtificialAnt { 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { 28 29 [StorableClass] 29 30 [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 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 namespace HeuristicLab.Problems.ArtificialAnt { 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { 27 28 [StorableClass] 28 29 [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 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 namespace HeuristicLab.Problems.ArtificialAnt { 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { 27 28 [StorableClass] 28 29 [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 39 39 [StorableClass] 40 40 public sealed class BestValidationSymbolicRegressionSolutionVisualizer : SingleSuccessorOperator, ISingleObjectiveSolutionsVisualizer, ISolutionsVisualizer { 41 private const string EvaluatorParameterName = "Evaluator";41 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 42 42 private const string SymbolicRegressionModelParameterName = "SymbolicRegressionModel"; 43 43 private const string DataAnalysisProblemDataParameterName = "DataAnalysisProblemData"; … … 49 49 50 50 #region parameter properties 51 public ILookupParameter<ISymbolic RegressionEvaluator> EvaluatorParameter {52 get { return (ILookupParameter<ISymbolic RegressionEvaluator>)Parameters[EvaluatorParameterName]; }51 public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { 52 get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; } 53 53 } 54 54 public IValueLookupParameter<IntValue> ValidationSamplesStartParameter { … … 82 82 83 83 #region properties 84 public ISymbolic RegressionEvaluator Evaluator {85 get { return EvaluatorParameter.ActualValue; }84 public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { 85 get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; } 86 86 } 87 87 public IntValue ValidationSamplesStart { … … 98 98 Parameters.Add(new SubScopesLookupParameter<DoubleValue>(QualityParameterName, "The quality of the symbolic regression solutions.")); 99 99 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.")); 100 101 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesStartParameterName, "The start index of the validation partition (part of the training partition).")); 101 102 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesEndParameterName, "The end index of the validation partition (part of the training partition).")); … … 113 114 114 115 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) 116 121 select new { Expression = expression, ValidationQuality = validationQuality }) 117 122 .OrderBy(x => x.ValidationQuality) … … 121 126 if (bestOfRunSolution == null) { 122 127 // no best of run solution yet -> make a solution from the currentBestExpression 123 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression );128 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter); 124 129 } else { 125 130 // compare quality of current best with best of run solution … … 127 132 var bestOfRunValidationQuality = SimpleMSEEvaluator.Calculate(validationValues, estimatedValidationValues); 128 133 if (bestOfRunValidationQuality > currentBestExpression.ValidationQuality) { 129 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression );134 UpdateBestOfRunSolution(problemData, currentBestExpression.Expression, SymbolicExpressionTreeInterpreter); 130 135 } 131 136 } … … 135 140 } 136 141 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; 140 149 141 150 var trainingValues = problemData.Dataset.GetVariableValues(problemData.TargetVariable.Value, problemData.TrainingSamplesStart.Value, problemData.TrainingSamplesEnd.Value); … … 160 169 } 161 170 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); 168 174 } 169 175 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs
r3452 r3462 34 34 using HeuristicLab.Problems.DataAnalysis; 35 35 using HeuristicLab.Operators; 36 using HeuristicLab.Problems.DataAnalysis.Symbolic; 36 37 37 38 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { … … 40 41 public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator { 41 42 private const string QualityParameterName = "Quality"; 43 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 42 44 private const string FunctionTreeParameterName = "FunctionTree"; 43 45 private const string RegressionProblemDataParameterName = "RegressionProblemData"; … … 49 51 public ILookupParameter<DoubleValue> QualityParameter { 50 52 get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; } 53 } 54 55 public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { 56 get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; } 51 57 } 52 58 … … 72 78 #endregion 73 79 #region properties 80 public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter { 81 get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; } 82 } 74 83 public SymbolicExpressionTree SymbolicExpressionTree { 75 84 get { return SymbolicExpressionTreeParameter.ActualValue; } … … 89 98 : base() { 90 99 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.")); 91 101 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree.")); 92 102 Parameters.Add(new LookupParameter<DataAnalysisProblemData>(RegressionProblemDataParameterName, "The problem data on which the symbolic regression solution should be evaluated.")); … … 98 108 public override IOperation Apply() { 99 109 DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue; 100 QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTree , RegressionProblemData.Dataset,110 QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset, 101 111 RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd, numberOfEvaluatedNodes)); 102 112 return null; 103 113 } 104 114 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); 106 121 } 107 122 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r3374 r3462 41 41 [StorableClass] 42 42 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); 45 45 numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value); 46 46 return mse; 47 47 } 48 48 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) { 51 50 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)); 53 52 var originalValues = from row in Enumerable.Range(start, end - start) select dataset[row, targetVariableIndex]; 54 53 return SimpleMSEEvaluator.Calculate(originalValues, estimatedValues); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
r3442 r3462 38 38 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 39 39 [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 { 41 42 [Storable] 42 43 private SymbolicExpressionTree tree; … … 45 46 } 46 47 [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; } 50 51 } 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 } 53 57 54 58 public SymbolicRegressionModel() : base() { } // for cloning 55 59 56 public SymbolicRegressionModel( SymbolicExpressionTree tree, IEnumerable<string> inputVariables)60 public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree, IEnumerable<string> inputVariables) 57 61 : base() { 58 62 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(); 61 65 } 62 66 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)); 71 69 } 72 70 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 } 74 78 } 75 79 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r3452 r3462 34 34 using HeuristicLab.Problems.DataAnalysis.Regression; 35 35 using HeuristicLab.Problems.DataAnalysis.Symbolic; 36 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators; 37 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators; 38 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers; 39 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 36 40 37 41 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { … … 144 148 var globalGrammar = new GlobalSymbolicExpressionGrammar(grammar); 145 149 var visualizer = new BestValidationSymbolicRegressionSolutionVisualizer(); 150 var interpreter = new SimpleArithmeticExpressionInterpreter(); 146 151 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", new BoolValue(false))); 147 152 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)); 148 154 Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator)); 149 155 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 36 36 [StorableClass] 37 37 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 } 41 48 } 42 49 43 50 public SymbolicRegressionSolution() : base() { } 44 51 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 } 46 95 } 47 96 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/DataAnalysisProblemDataView.cs
r3442 r3462 29 29 : this() { 30 30 Content = content; 31 variableCollectionView.Content = content.Variables.AsReadOnly(); 31 } 32 33 protected override void OnContentChanged() { 34 base.OnContentChanged(); 35 variableCollectionView.Content = Content.Variables.AsReadOnly(); 32 36 } 33 37 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/EstimatedValuesView.cs
r3442 r3462 68 68 protected override void RegisterContentEvents() { 69 69 base.RegisterContentEvents(); 70 Content. ModelChanged += new EventHandler(Content_ModelChanged);70 Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged); 71 71 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 72 72 } … … 74 74 protected override void DeregisterContentEvents() { 75 75 base.DeregisterContentEvents(); 76 Content. ModelChanged -= new EventHandler(Content_ModelChanged);76 Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged); 77 77 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); 78 78 } … … 82 82 } 83 83 84 void Content_ ModelChanged(object sender, EventArgs e) {84 void Content_EstimatedValuesChanged(object sender, EventArgs e) { 85 85 OnContentChanged(); 86 86 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/LineChartView.cs
r3442 r3462 65 65 : this() { 66 66 Content = dataAnalysisSolution; 67 DrawTargetVariableValues(); 68 DrawEstimatedValues(); 67 RedrawChart(); 69 68 } 70 69 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 72 78 this.chart.Series.Add(ESTIMATEDVALUES_SERIES_NAME); 73 79 this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].LegendText = Content.ItemName; … … 77 83 } 78 84 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 88 85 #region events 89 86 protected override void RegisterContentEvents() { 90 87 base.RegisterContentEvents(); 91 Content. ModelChanged += new EventHandler(Content_ModelChanged);88 Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged); 92 89 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 93 90 } … … 95 92 protected override void DeregisterContentEvents() { 96 93 base.DeregisterContentEvents(); 97 Content. ModelChanged -= new EventHandler(Content_ModelChanged);94 Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged); 98 95 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); 99 96 } 100 97 101 98 void Content_ProblemDataChanged(object sender, EventArgs e) { 102 OnContentChanged();99 RedrawChart(); 103 100 } 104 101 105 void Content_ ModelChanged(object sender, EventArgs e) {106 OnContentChanged();102 void Content_EstimatedValuesChanged(object sender, EventArgs e) { 103 UpdateEstimatedValuesLineChart(); 107 104 } 108 105 109 106 protected override void OnContentChanged() { 110 107 base.OnContentChanged(); 111 UpdateEstimatedValuesLineChart();108 RedrawChart(); 112 109 } 113 110 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.cs
r3442 r3462 84 84 : this() { 85 85 Content = dataAnalysisSolution; 86 UpdateChart(); 86 87 } 87 88 88 89 protected override void RegisterContentEvents() { 89 90 base.RegisterContentEvents(); 90 Content. ModelChanged += new EventHandler(Content_ModelChanged);91 Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged); 91 92 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 92 93 } 93 94 protected override void DeregisterContentEvents() { 94 95 base.DeregisterContentEvents(); 95 Content. ModelChanged -= new EventHandler(Content_ModelChanged);96 Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged); 96 97 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); 97 98 } … … 99 100 100 101 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(); 106 107 } 107 108 … … 127 128 128 129 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 } 155 159 } 156 160 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/SimplifiedSymbolicExpressionModelView.cs
r3461 r3462 44 44 public new SymbolicRegressionSolution Content { 45 45 get { return (SymbolicRegressionSolution)base.Content; } 46 set { base.Content = value;}46 set { base.Content = value; } 47 47 } 48 48 … … 58 58 } 59 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 60 74 protected override void OnContentChanged() { 61 75 base.OnContentChanged(); 76 UpdateTreeChart(); 77 } 78 79 private void UpdateTreeChart() { 62 80 var simplifier = new SymbolicSimplifier(); 63 81 var simplifiedTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/SymbolicExpressionModelView.cs
r3461 r3462 57 57 } 58 58 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 59 74 protected override void OnContentChanged() { 60 75 base.OnContentChanged(); 76 UpdateTreeChart(); 77 } 78 79 private void UpdateTreeChart() { 61 80 viewHost.Content = Content.Model.SymbolicExpressionTree; 62 81 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisSolution.cs
r3452 r3462 35 35 [Item("DataAnalysisSolution", "Represents a solution for a data analysis problem which can be visualized in the GUI.")] 36 36 [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 { 50 38 [Storable] 51 39 private DataAnalysisProblemData problemData; … … 58 46 problemData = value; 59 47 RegisterProblemDataEvents(); 60 OnProblemDataChanged( );48 OnProblemDataChanged(EventArgs.Empty); 61 49 } 62 50 } 63 51 } 64 52 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; } 71 56 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) 88 59 : this() { 89 60 this.problemData = problemData; 90 this.model = model;91 61 Initialize(); 92 62 } … … 98 68 private void Initialize() { 99 69 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 }120 70 } 121 71 122 72 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! 126 75 clone.problemData = problemData; 127 76 clone.Initialize(); … … 130 79 131 80 #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() { 148 82 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 149 83 } 150 pr ivatevoid DeregisterProblemDataEvents() {84 protected virtual void DeregisterProblemDataEvents() { 151 85 ProblemData.ProblemDataChanged += new EventHandler(ProblemData_Changed); 152 86 } 153 87 154 88 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); 156 104 } 157 105 #endregion -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMSEEvaluator.cs
r3452 r3462 73 73 select values[row, ORIGINAL_INDEX]; 74 74 var estimated = from row in Enumerable.Range(0, values.Rows) 75 select values[row, ORIGINAL_INDEX];75 select values[row, ESTIMATION_INDEX]; 76 76 return Calculate(original, estimated); 77 77 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleNMSEEvaluator.cs
r3452 r3462 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
r3452 r3462 98 98 <Compile Include="Evaluators\SimpleVarianceAccountedForEvaluator.cs" /> 99 99 <Compile Include="HeuristicLabProblemsDataAnalysisPlugin.cs" /> 100 <Compile Include="Interfaces\IModel.cs" />101 100 <Compile Include="MatrixExtensions.cs" /> 102 101 <Compile Include="Properties\AssemblyInfo.cs" /> 103 <Compile Include="Statistics.cs" />104 102 <Compile Include="Symbolic\ArithmeticExpressionGrammar.cs" /> 105 <Compile Include="Symbolic\SimpleArithmeticExpressionEvaluator.cs" /> 103 <Compile Include="Symbolic\ISymbolicExpressionTreeInterpreter.cs" /> 104 <Compile Include="Symbolic\SimpleArithmeticExpressionInterpreter.cs" /> 106 105 <Compile Include="Symbolic\SymbolicSimplifier.cs" /> 106 <Compile Include="Symbolic\Symbols\Addition.cs" /> 107 107 <Compile Include="Symbolic\Symbols\Constant.cs" /> 108 108 <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" /> 109 112 <Compile Include="Symbolic\Symbols\Variable.cs" /> 110 113 <Compile Include="Symbolic\Symbols\VariableTreeNode.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/ArithmeticExpressionGrammar.cs
r3442 r3462 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 30 30 using HeuristicLab.Data; 31 31 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs
r3456 r3462 26 26 using System.Collections.Generic; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 29 29 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler; 30 31 31 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 32 33 [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 35 47 private Dataset dataset; 36 48 private int row; 37 49 private Instruction[] code; 38 50 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) { 40 53 this.dataset = dataset; 41 54 var compiler = new SymbolicExpressionTreeCompiler(); 42 code = compiler.Compile(tree); 55 compiler.AddInstructionPostProcessingHook(PostProcessInstruction); 56 code = compiler.Compile(tree, MapSymbolToOpCode); 43 57 foreach (var row in rows) { 44 58 this.row = row; … … 51 65 } 52 66 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 53 87 private Stack<List<double>> argumentStack = new Stack<List<double>>(); 54 88 public double Evaluate() { 55 89 var currentInstr = code[pc++]; 56 switch (currentInstr. symbol) {57 case CodeSymbol.Add: {90 switch (currentInstr.opCode) { 91 case OpCodes.Add: { 58 92 double s = 0.0; 59 93 for (int i = 0; i < currentInstr.nArguments; i++) { … … 62 96 return s; 63 97 } 64 case CodeSymbol.Sub: {98 case OpCodes.Sub: { 65 99 double s = Evaluate(); 66 100 for (int i = 1; i < currentInstr.nArguments; i++) { … … 69 103 return s; 70 104 } 71 case CodeSymbol.Mul: {105 case OpCodes.Mul: { 72 106 double p = Evaluate(); 73 107 for (int i = 1; i < currentInstr.nArguments; i++) { … … 76 110 return p; 77 111 } 78 case CodeSymbol.Div: {112 case OpCodes.Div: { 79 113 double p = Evaluate(); 80 114 for (int i = 1; i < currentInstr.nArguments; i++) { … … 83 117 return p; 84 118 } 85 case CodeSymbol.Call: {119 case OpCodes.Call: { 86 120 // save current arguments 87 121 List<double> arguments = new List<double>(); … … 102 136 return v; 103 137 } 104 case CodeSymbol.Arg: {138 case OpCodes.Arg: { 105 139 return argumentStack.Peek()[currentInstr.iArg0]; 106 140 } 107 case CodeSymbol.Dynamic: {141 case OpCodes.Variable: { 108 142 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: { 112 146 var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode; 113 if (constTreeNode != null) { 114 return constTreeNode.Value; 115 } else throw new NotSupportedException(); 147 return constTreeNode.Value; 116 148 } 117 149 default: throw new NotSupportedException(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SymbolicSimplifier.cs
r3442 r3462 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding. GeneralSymbols;27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 29 29 using System.Diagnostics; … … 38 38 /// </summary> 39 39 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 40 46 public SymbolicExpressionTree Simplify(SymbolicExpressionTree originalTree) { 41 47 var clone = (SymbolicExpressionTreeNode)originalTree.Root.Clone(); … … 194 200 return a; 195 201 } else { 196 var div = (new Division()).CreateTreeNode();202 var div = divSymbol.CreateTreeNode(); 197 203 div.SubTrees.Add(a); 198 204 div.SubTrees.Add(b); … … 215 221 } else if (IsAddition(a) && IsAddition(b)) { 216 222 // merge additions 217 var add = (new Addition()).CreateTreeNode();223 var add = addSymbol.CreateTreeNode(); 218 224 for (int i = 0; i < a.SubTrees.Count - 1; i++) add.AddSubTree(a.SubTrees[i]); 219 225 for (int i = 0; i < b.SubTrees.Count - 1; i++) add.AddSubTree(b.SubTrees[i]); … … 232 238 return MakeAddition(b, a); 233 239 } else if (IsAddition(a) && IsConstant(b)) { 234 var add = (new Addition()).CreateTreeNode();240 var add = addSymbol.CreateTreeNode(); 235 241 for (int i = 0; i < a.SubTrees.Count - 1; i++) add.AddSubTree(a.SubTrees[i]); 236 242 if (IsConstant(a.SubTrees.Last())) … … 242 248 return add; 243 249 } else if (IsAddition(a)) { 244 var add = (new Addition()).CreateTreeNode();250 var add = addSymbol.CreateTreeNode(); 245 251 add.AddSubTree(b); 246 252 foreach (var subTree in a.SubTrees) { … … 250 256 return add; 251 257 } else { 252 var add = (new Addition()).CreateTreeNode();258 var add = addSymbol.CreateTreeNode(); 253 259 add.SubTrees.Add(a); 254 260 add.SubTrees.Add(b); … … 296 302 return MakeDivision(MakeMultiplication(b.SubTrees[0], a), b.SubTrees[1]); 297 303 } else if (IsMultiplication(a) && IsMultiplication(b)) { 298 var mul = (new Multiplication()).CreateTreeNode();304 var mul = mulSymbol.CreateTreeNode(); 299 305 for (int i = 0; i < a.SubTrees.Count - 1; i++) mul.AddSubTree(a.SubTrees[i]); 300 306 for (int i = 0; i < b.SubTrees.Count - 1; i++) mul.AddSubTree(b.SubTrees[i]); … … 302 308 return mul; 303 309 } else if (IsMultiplication(a)) { 304 var mul = (new Multiplication()).CreateTreeNode();310 var mul = mulSymbol.CreateTreeNode(); 305 311 for (int i = 0; i < a.SubTrees.Count - 1; i++) mul.AddSubTree(a.SubTrees[i]); 306 312 mul.AddSubTree(MakeMultiplication(a.SubTrees.Last(), b)); 307 313 return mul; 308 314 } else if (IsMultiplication(b)) { 309 var mul = (new Multiplication()).CreateTreeNode();315 var mul = mulSymbol.CreateTreeNode(); 310 316 for (int i = 0; i < b.SubTrees.Count - 1; i++) mul.AddSubTree(b.SubTrees[i]); 311 317 mul.AddSubTree(MakeMultiplication(b.SubTrees.Last(), a)); 312 318 return mul; 313 319 } else { 314 var mul = (new Multiplication()).CreateTreeNode();320 var mul = mulSymbol.CreateTreeNode(); 315 321 mul.SubTrees.Add(a); 316 322 mul.SubTrees.Add(b); … … 346 352 347 353 private SymbolicExpressionTreeNode MakeConstant(double value) { 348 ConstantTreeNode constantTreeNode = (ConstantTreeNode)( new Constant().CreateTreeNode());354 ConstantTreeNode constantTreeNode = (ConstantTreeNode)(constSymbol.CreateTreeNode()); 349 355 constantTreeNode.Value = value; 350 356 return (SymbolicExpressionTreeNode)constantTreeNode; … … 352 358 353 359 private SymbolicExpressionTreeNode MakeVariable(double weight, string name) { 354 var tree = (VariableTreeNode) (new Variable().CreateTreeNode());360 var tree = (VariableTreeNode)varSymbol.CreateTreeNode(); 355 361 tree.Weight = weight; 356 362 tree.VariableName = name; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Addition.cs
r3456 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols { 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 26 27 [StorableClass] 27 28 [Item("Addition", "Symbol that represents the + operator.")] -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Constant.cs
r3376 r3462 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 30 31 [StorableClass] -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Division.cs
r3456 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols { 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 26 27 [StorableClass] 27 28 [Item("Division", "Symbol that represents the / operator.")] -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Multiplication.cs
r3456 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols { 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 26 27 [StorableClass] 27 28 [Item("Multiplication", "Symbol that represents the * operator.")] -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Subtraction.cs
r3456 r3462 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols { 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 26 27 [StorableClass] 27 28 [Item("Subtraction", "Symbol that represents the - operator.")] -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Symbols/Variable.cs
r3442 r3462 30 30 using System.Collections.Generic; 31 31 using System; 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 32 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols { 33 34 [StorableClass]
Note: See TracChangeset
for help on using the changeset viewer.