Changeset 9739
- Timestamp:
- 07/24/13 09:56:56 (11 years ago)
- Location:
- branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter
- Files:
-
- 2 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r9738 r9739 173 173 <Compile Include="Compiler\Instruction.cs" /> 174 174 <Compile Include="Compiler\SymbolicExpressionTreeCompiler.cs" /> 175 <Compile Include="Compiler\SymbolicExpressionTreeLinearCompiler.cs" /> 175 176 <Compile Include="Creators\FullTreeCreator.cs"> 176 177 <SubType>Code</SubType> -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r9738 r9739 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 121 122 } 122 123 123 var root = tree.Root.GetSubtree(0).GetSubtree(0); 124 var nodes = new List<ISymbolicExpressionTreeNode> { root }; 125 var code = new List<LinearInstruction>{ 126 new LinearInstruction { dynamicNode = root, 127 nArguments = (byte) root.SubtreeCount, 128 opCode = OpCodes.MapSymbolToOpCode(root) 129 } 130 }; 131 132 // iterate breadth-wise over tree nodes and produce an array of instructions 133 int i = 0; 134 while (i != nodes.Count) { 135 if (nodes[i].SubtreeCount > 0) { 136 // save index of the first child in the instructions array 137 code[i].childIndex = code.Count; 138 for (int j = 0; j != nodes[i].SubtreeCount; ++j) { 139 var s = nodes[i].GetSubtree(j); 140 nodes.Add(s); 141 code.Add(new LinearInstruction { 142 dynamicNode = s, 143 nArguments = (byte)s.SubtreeCount, 144 opCode = OpCodes.MapSymbolToOpCode(s) 145 }); 146 } 147 } 148 ++i; 149 } 150 // fill in iArg0 value for terminal nodes 151 foreach (var instr in code) { 124 var code = SymbolicExpressionTreeLinearCompiler.Compile(tree, OpCodes.MapSymbolToOpCode); 125 PrepareInterpreterState(code, dataset); 126 return rows.Select(row => Evaluate(dataset, ref row, code)); 127 } 128 129 private static void PrepareInterpreterState(LinearInstruction[] code, Dataset dataset) { 130 for (int i = code.Length - 1; i >= 0; --i) { 131 var instr = code[i]; 132 #region opcode switch 152 133 switch (instr.opCode) { 134 case OpCodes.Constant: { 135 var constTreeNode = (ConstantTreeNode)instr.dynamicNode; 136 instr.value = constTreeNode.Value; 137 } 138 break; 153 139 case OpCodes.Variable: { 154 140 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; … … 167 153 break; 168 154 } 155 #endregion 169 156 } 170 171 var array = code.ToArray(); 172 173 foreach (var rowEnum in rows) { 174 int row = rowEnum; 175 EvaluateFast(dataset, ref row, array); 176 yield return code[0].value; 177 } 178 } 179 180 private void EvaluateFast(Dataset dataset, ref int row, LinearInstruction[] code) { 157 } 158 159 private static double Evaluate(Dataset dataset, ref int row, LinearInstruction[] code) { 181 160 for (int i = code.Length - 1; i >= 0; --i) { 182 161 var instr = code[i]; 183 162 if (instr.opCode == OpCodes.Constant) continue; 163 #region opcode switch 184 164 switch (instr.opCode) { 185 165 case OpCodes.Variable: { … … 194 174 if (actualRow < 0 || actualRow >= dataset.Rows) instr.value = double.NaN; 195 175 instr.value = ((IList<double>)instr.iArg0)[actualRow] * laggedVariableTreeNode.Weight; 196 }197 break;198 case OpCodes.Constant: {199 var constTreeNode = (ConstantTreeNode)instr.dynamicNode;200 instr.value = constTreeNode.Value;201 176 } 202 177 break; … … 462 437 throw new NotSupportedException(); 463 438 } 439 #endregion 464 440 } 441 return code[0].value; 465 442 } 466 443 } -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r9738 r9739 31 31 <DebugType>pdbonly</DebugType> 32 32 <Optimize>true</Optimize> 33 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>33 <OutputPath>bin\</OutputPath> 34 34 <DefineConstants>TRACE</DefineConstants> 35 35 <ErrorReport>prompt</ErrorReport> … … 82 82 <Reference Include="ALGLIB-3.7.0"> 83 83 <HintPath>..\..\..\Trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath> 84 <Private> False</Private>84 <Private>True</Private> 85 85 </Reference> 86 86 <Reference Include="HeuristicLab.Common-3.3"> 87 87 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 88 <Private> False</Private>88 <Private>True</Private> 89 89 </Reference> 90 90 <Reference Include="HeuristicLab.Core-3.3"> 91 91 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 92 <Private> False</Private>92 <Private>True</Private> 93 93 </Reference> 94 94 <Reference Include="HeuristicLab.Data-3.3"> 95 95 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath> 96 <Private> False</Private>96 <Private>True</Private> 97 97 </Reference> 98 98 <Reference Include="HeuristicLab.Operators-3.3"> 99 99 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath> 100 <Private> False</Private>100 <Private>True</Private> 101 101 </Reference> 102 102 <Reference Include="HeuristicLab.Optimization-3.3"> 103 103 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 104 <Private> False</Private>104 <Private>True</Private> 105 105 </Reference> 106 106 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4"> 107 107 <HintPath>..\..\..\Trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath> 108 <Private> False</Private>108 <Private>True</Private> 109 109 </Reference> 110 110 <Reference Include="HeuristicLab.Random-3.3"> 111 111 <HintPath>..\..\..\Trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 112 <Private> False</Private>112 <Private>True</Private> 113 113 </Reference> 114 <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> 114 115 <Reference Include="System" /> 115 116 </ItemGroup> … … 120 121 </ItemGroup> 121 122 </When> 122 <Otherwise> 123 <ItemGroup> 124 <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> 125 </ItemGroup> 126 </Otherwise> 123 <Otherwise /> 127 124 </Choose> 128 125 <ItemGroup> … … 137 134 <Project>{06d4a186-9319-48a0-bade-a2058d462eea}</Project> 138 135 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name> 139 <Private> False</Private>136 <Private>True</Private> 140 137 </ProjectReference> 141 138 <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> 142 139 <Project>{3d28463f-ec96-4d82-afee-38be91a0ca00}</Project> 143 140 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name> 144 <Private> False</Private>141 <Private>True</Private> 145 142 </ProjectReference> 146 143 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.