- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 13 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs
r6135 r6760 20 20 #endregion 21 21 22 using System ;22 using System.Collections.Generic; 23 23 using System.Linq; 24 using System.Text; 24 25 using HeuristicLab.Analysis; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using System.Collections.Generic;31 using System.Text;32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;33 32 34 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 47 46 } 48 47 49 public I ValueParameter<IntValue> AlleleTreeDepthParameter {48 public IFixedValueParameter<IntValue> AlleleTreeDepthParameter { 50 49 get { return (IFixedValueParameter<IntValue>)Parameters[AlleleTreeDepthParameterName]; } 51 50 } … … 71 70 72 71 protected override Allele[] CalculateAlleles(ISymbolicExpressionTree solution) { 73 List<Allele> alleles = new List<Allele>(); 74 75 foreach (var subtree in GetAllSubtreesOfDepth(solution, AlleleTreeDepth)) { 76 alleles.Add(GetAlleleFromSubtreeOfDepth(subtree, AlleleTreeDepth)); 77 } 78 return alleles.ToArray(); 72 return GetAllSubtreesOfDepth(solution, AlleleTreeDepth) 73 .AsParallel() 74 .Select(t => GetAlleleFromSubtreeOfDepth(t, AlleleTreeDepth)) 75 .ToArray(); 79 76 } 80 77 -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs
r5907 r6760 93 93 IList<int> nonDominatedIndexes = new List<int>(); 94 94 ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray(); 95 List<double[]> qualities = new List<double[]>();96 95 bool[] maximization = Maximization.ToArray(); 97 96 List<double[]> newNonDominatedQualities = new List<double[]>(); 98 97 var evaluator = EvaluatorParameter.ActualValue; 98 var problemData = ProblemDataParameter.ActualValue; 99 99 IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator); 100 101 var qualities = tree 102 .AsParallel() 103 .Select(t => evaluator.Evaluate(childContext, t, problemData, rows)) 104 .ToArray(); 100 105 for (int i = 0; i < tree.Length; i++) { 101 qualities.Add(evaluator.Evaluate(childContext, tree[i], ProblemDataParameter.ActualValue, rows)); // qualities[i] = ...102 106 if (IsNonDominated(qualities[i], trainingBestQualities, maximization) && 103 107 IsNonDominated(qualities[i], qualities, maximization)) { -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs
r5907 r6760 76 76 ISymbolicExpressionTree bestTree = null; 77 77 ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray(); 78 double[] quality = new double[tree.Length];79 78 var evaluator = EvaluatorParameter.ActualValue; 79 var problemData = ProblemDataParameter.ActualValue; 80 80 IEnumerable<int> rows = GenerateRowsToEvaluate(); 81 81 if (!rows.Any()) return base.Apply(); 82 82 83 83 IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator); 84 var quality = tree 85 .AsParallel() 86 .Select(t => evaluator.Evaluate(childContext, t, problemData, rows)) 87 .ToArray(); 88 84 89 for (int i = 0; i < tree.Length; i++) { 85 quality[i] = evaluator.Evaluate(childContext, tree[i], ProblemDataParameter.ActualValue, rows);86 90 if (IsBetter(quality[i], bestQuality, Maximization.Value)) { 87 91 bestQuality = quality[i]; -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs
r5924 r6760 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 104 105 datatable.Rows.Add(row); 105 106 } 106 datatable.Rows[pair.Key].Values.Add( pair.Value);107 datatable.Rows[pair.Key].Values.Add(Math.Round(pair.Value, 3)); 107 108 } 108 109 … … 130 131 131 132 public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<ISymbolicExpressionTree> trees, bool aggregateLaggedVariables = true) { 132 Dictionary<string, double> variableFrequencies = new Dictionary<string, double>(); 133 int totalNumberOfSymbols = 0; 134 135 foreach (var tree in trees) { 136 var variableReferences = GetVariableReferences(tree, aggregateLaggedVariables); 137 foreach (var pair in variableReferences) { 138 totalNumberOfSymbols += pair.Value; 139 if (variableFrequencies.ContainsKey(pair.Key)) { 140 variableFrequencies[pair.Key] += pair.Value; 141 } else { 142 variableFrequencies.Add(pair.Key, pair.Value); 143 } 144 } 145 } 133 134 var variableFrequencies = trees 135 .AsParallel() 136 .SelectMany(t => GetVariableReferences(t, aggregateLaggedVariables)) 137 .GroupBy(pair => pair.Key, pair => pair.Value) 138 .ToDictionary(g => g.Key, g => (double)g.Sum()); 139 140 double totalNumberOfSymbols = variableFrequencies.Values.Sum(); 146 141 147 142 foreach (var pair in variableFrequencies) -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r6135 r6760 121 121 <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" /> 122 122 <Compile Include="Analyzers\SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs" /> 123 <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" /> 123 124 <Compile Include="Formatters\SymbolicDataAnalysisExpressionLatexFormatter.cs" /> 124 125 <Compile Include="Formatters\SymbolicDataAnalysisExpressionMATLABFormatter.cs" /> -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLabProblemsDataAnalysisSymbolicPlugin.cs.frame
r5860 r6760 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4. 0.$WCREV$")]28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.1.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties/AssemblyInfo.frame
r5860 r6760 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 0.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.1.$WCREV$")] -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r5987 r6760 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Parameters; 27 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Data;29 using HeuristicLab.Parameters;30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 208 208 if (instr.opCode == OpCodes.Variable) { 209 209 var variableTreeNode = instr.dynamicNode as VariableTreeNode; 210 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);210 instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 211 211 code[i] = instr; 212 212 } else if (instr.opCode == OpCodes.LagVariable) { 213 var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode;214 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);213 var laggedVariableTreeNode = instr.dynamicNode as LaggedVariableTreeNode; 214 instr.iArg0 = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName); 215 215 code[i] = instr; 216 216 } else if (instr.opCode == OpCodes.VariableCondition) { 217 217 var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode; 218 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableConditionTreeNode.VariableName);218 instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName); 219 219 } else if (instr.opCode == OpCodes.Call) { 220 220 necessaryArgStackSize += instr.nArguments + 1; … … 308 308 double result = Evaluate(dataset, ref row, state); 309 309 for (int i = 1; i < currentInstr.nArguments; i++) { 310 if (result <= 0.0) SkipInstructions(state);310 if (result > 0.0) result = Evaluate(dataset, ref row, state); 311 311 else { 312 result = Evaluate(dataset, ref row,state);312 SkipInstructions(state); 313 313 } 314 314 } 315 return result <= 0.0 ? -1.0 :1.0;315 return result > 0.0 ? 1.0 : -1.0; 316 316 } 317 317 case OpCodes.OR: { 318 318 double result = Evaluate(dataset, ref row, state); 319 319 for (int i = 1; i < currentInstr.nArguments; i++) { 320 if (result > 0.0) SkipInstructions(state);320 if (result <= 0.0) result = Evaluate(dataset, ref row, state); 321 321 else { 322 result = Evaluate(dataset, ref row,state);322 SkipInstructions(state); 323 323 } 324 324 } … … 390 390 int savedPc = state.ProgramCounter; 391 391 // set pc to start of function 392 state.ProgramCounter = currentInstr.iArg0;392 state.ProgramCounter = (ushort)currentInstr.iArg0; 393 393 // evaluate the function 394 394 double v = Evaluate(dataset, ref row, state); … … 402 402 } 403 403 case OpCodes.Arg: { 404 return state.GetStackFrameValue( currentInstr.iArg0);404 return state.GetStackFrameValue((ushort)currentInstr.iArg0); 405 405 } 406 406 case OpCodes.Variable: { 407 407 if (row < 0 || row >= dataset.Rows) 408 408 return double.NaN; 409 var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode;410 return dataset[row, currentInstr.iArg0] * variableTreeNode.Weight;409 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 410 return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight; 411 411 } 412 412 case OpCodes.LagVariable: { 413 var laggedVariableTreeNode = currentInstr.dynamicNode as LaggedVariableTreeNode;413 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; 414 414 int actualRow = row + laggedVariableTreeNode.Lag; 415 415 if (actualRow < 0 || actualRow >= dataset.Rows) 416 416 return double.NaN; 417 return dataset[actualRow, currentInstr.iArg0] * laggedVariableTreeNode.Weight;417 return ((IList<double>)currentInstr.iArg0)[row] * laggedVariableTreeNode.Weight; 418 418 } 419 419 case OpCodes.Constant: { … … 428 428 return double.NaN; 429 429 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode; 430 double variableValue = dataset[row, currentInstr.iArg0];430 double variableValue = ((IList<double>)currentInstr.iArg0)[row]; 431 431 double x = variableValue - variableConditionTreeNode.Threshold; 432 432 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r6135 r6760 202 202 Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer()); 203 203 Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 204 Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer());205 204 ParameterizeOperators(); 206 205 } -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs
r5847 r6760 79 79 80 80 MaximizationParameter.Hidden = true; 81 InitializeOperators(); 81 82 RegisterEventHandler(); 82 83 } … … 85 86 private void AfterDeserialization() { 86 87 RegisterEventHandler(); 88 } 89 90 private void InitializeOperators() { 91 Operators.Add(new SymbolicDataAnalysisAlleleFrequencyAnalyzer()); 92 ParameterizeOperators(); 87 93 } 88 94 -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/Properties/AssemblyInfo.cs
r5809 r6760 52 52 // by using the '*' as shown below: 53 53 [assembly: AssemblyVersion("3.4.0.0")] 54 [assembly: AssemblyFileVersion("3.4. 0.0")]54 [assembly: AssemblyFileVersion("3.4.1.0")] -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tests/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r5809 r6760 30 30 31 31 32 /// <summary>33 ///This is a test class for SimpleArithmeticExpressionInterpreter and is intended34 ///to contain all SimpleArithmeticExpressionInterpreter Unit Tests35 ///</summary>36 32 [TestClass()] 37 33 public class SymbolicDataAnalysisExpressionTreeInterpreterTest { … … 55 51 56 52 [TestMethod] 57 public void FullGrammarSimpleArithmeticExpressionInterpreterPerformanceTest() { 53 public void SymbolicDataAnalysisExpressionTreeInterpreterFullGrammarPerformanceTest() { 54 FullGrammarPerformanceTest(new SymbolicDataAnalysisExpressionTreeInterpreter(), 12.5e6); 55 } 56 [TestMethod] 57 public void SymbolicDataAnalysisExpressionTreeInterpreterArithmeticGrammarPerformanceTest() { 58 FullGrammarPerformanceTest(new SymbolicDataAnalysisExpressionTreeInterpreter(), 12.5e6); 59 } 60 61 [TestMethod] 62 public void SymbolicDataAnalysisExpressionTreeILEmittingInterpreterFullGrammarPerformanceTest() { 63 FullGrammarPerformanceTest(new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(), 10e6); 64 } 65 [TestMethod] 66 public void SymbolicDataAnalysisExpressionTreeILEmittingInterpreterArithmeticGrammarPerformanceTest() { 67 FullGrammarPerformanceTest(new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(), 10e6); 68 } 69 70 private void FullGrammarPerformanceTest(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double nodesPerSecThreshold) { 58 71 var twister = new MersenneTwister(31415); 59 72 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); … … 64 77 grammar.MinimumFunctionDefinitions = 0; 65 78 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 66 double[] estimation = new double[Rows];67 79 foreach (ISymbolicExpressionTree tree in randomTrees) { 68 80 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); 69 81 } 70 SymbolicDataAnalysisExpressionTreeInterpreter interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter();71 82 double nodesPerSec = Util.CalculateEvaluatedNodesPerSec(randomTrees, interpreter, dataset, 3); 72 Assert.IsTrue(nodesPerSec > 12.5e6); // evaluated nodes per seconds must be larger than 15mNodes/sec 73 } 74 75 [TestMethod] 76 public void ArithmeticGrammarSimpleArithmeticExpressionInterpreterPerformanceTest() { 83 Assert.IsTrue(nodesPerSec > nodesPerSecThreshold); // evaluated nodes per seconds must be larger than 15mNodes/sec 84 } 85 86 private void ArithmeticGrammarPerformanceTest(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double nodesPerSecThreshold) { 77 87 var twister = new MersenneTwister(31415); 78 88 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); … … 83 93 grammar.MinimumFunctionDefinitions = 0; 84 94 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 85 double[] estimation = new double[Rows];86 95 foreach (SymbolicExpressionTree tree in randomTrees) { 87 96 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); 88 97 } 89 SymbolicDataAnalysisExpressionTreeInterpreter interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 98 90 99 double nodesPerSec = Util.CalculateEvaluatedNodesPerSec(randomTrees, interpreter, dataset, 3); 91 Assert.IsTrue(nodesPerSec > 12.5e6); // evaluated nodes per seconds must be larger than 15mNodes/sec100 Assert.IsTrue(nodesPerSec > nodesPerSecThreshold); // evaluated nodes per seconds must be larger than 15mNodes/sec 92 101 } 93 102 … … 97 106 ///</summary> 98 107 [TestMethod] 99 public void SimpleArithmeticExpressionInterpreterEvaluateTest() { 100 108 public void SymbolicDataAnalysisExpressionTreeInterpreterEvaluateTest() { 101 109 Dataset ds = new Dataset(new string[] { "Y", "A", "B" }, new double[,] { 102 110 { 1.0, 1.0, 1.0 }, … … 105 113 }); 106 114 107 SymbolicDataAnalysisExpressionTreeInterpreter interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 108 115 var interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 116 EvaluateTerminals(interpreter, ds); 117 EvaluateOperations(interpreter, ds); 118 EvaluateAdf(interpreter, ds); 119 } 120 121 [TestMethod] 122 public void SymbolicDataAnalysisExpressionILEmittingTreeInterpreterEvaluateTest() { 123 Dataset ds = new Dataset(new string[] { "Y", "A", "B" }, new double[,] { 124 { 1.0, 1.0, 1.0 }, 125 { 2.0, 2.0, 2.0 }, 126 { 3.0, 1.0, 2.0 } 127 }); 128 129 var interpreter = new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(); 130 EvaluateTerminals(interpreter, ds); 131 EvaluateOperations(interpreter, ds); 132 } 133 134 private void EvaluateTerminals(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds) { 109 135 // constants 110 136 Evaluate(interpreter, ds, "(+ 1.5 3.5)", 0, 5.0); … … 113 139 Evaluate(interpreter, ds, "(variable 2.0 a)", 0, 2.0); 114 140 Evaluate(interpreter, ds, "(variable 2.0 a)", 1, 4.0); 115 116 141 } 142 143 private void EvaluateAdf(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds) { 144 145 // ADF 146 Evaluate(interpreter, ds, @"(PROG 147 (MAIN 148 (CALL ADF0)) 149 (defun ADF0 1.0))", 1, 1.0); 150 Evaluate(interpreter, ds, @"(PROG 151 (MAIN 152 (* (CALL ADF0) (CALL ADF0))) 153 (defun ADF0 2.0))", 1, 4.0); 154 Evaluate(interpreter, ds, @"(PROG 155 (MAIN 156 (CALL ADF0 2.0 3.0)) 157 (defun ADF0 158 (+ (ARG 0) (ARG 1))))", 1, 5.0); 159 Evaluate(interpreter, ds, @"(PROG 160 (MAIN (CALL ADF1 2.0 3.0)) 161 (defun ADF0 162 (- (ARG 1) (ARG 0))) 163 (defun ADF1 164 (+ (CALL ADF0 (ARG 1) (ARG 0)) 165 (CALL ADF0 (ARG 0) (ARG 1)))))", 1, 0.0); 166 Evaluate(interpreter, ds, @"(PROG 167 (MAIN (CALL ADF1 (variable 2.0 a) 3.0)) 168 (defun ADF0 169 (- (ARG 1) (ARG 0))) 170 (defun ADF1 171 (CALL ADF0 (ARG 1) (ARG 0))))", 1, 1.0); 172 Evaluate(interpreter, ds, 173 @"(PROG 174 (MAIN (CALL ADF1 (variable 2.0 a) 3.0)) 175 (defun ADF0 176 (- (ARG 1) (ARG 0))) 177 (defun ADF1 178 (+ (CALL ADF0 (ARG 1) (ARG 0)) 179 (CALL ADF0 (ARG 0) (ARG 1)))))", 1, 0.0); 180 } 181 182 private void EvaluateOperations(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds) { 117 183 // addition 118 184 Evaluate(interpreter, ds, "(+ (variable 2.0 a ))", 1, 4.0); … … 148 214 Evaluate(interpreter, ds, "(> (variable 2.0 a) 1.9)", 0, 1.0); 149 215 Evaluate(interpreter, ds, "(> 1.9 (variable 2.0 a))", 0, -1.0); 150 //Evaluate(interpreter, ds, "(> (sqrt-1.0) (log -1.0))", 0, -1.0); // (> nan nan) should be false216 Evaluate(interpreter, ds, "(> (log -1.0) (log -1.0))", 0, -1.0); // (> nan nan) should be false 151 217 152 218 // lt … … 155 221 Evaluate(interpreter, ds, "(< (variable 2.0 a) 1.9)", 0, -1.0); 156 222 Evaluate(interpreter, ds, "(< 1.9 (variable 2.0 a))", 0, 1.0); 157 //Evaluate(interpreter, ds, "(< (sqrt -1,0) (log -1,0))", 0, -1.0); // (< nan nan) should be false223 Evaluate(interpreter, ds, "(< (log -1.0) (log -1.0))", 0, -1.0); // (< nan nan) should be false 158 224 159 225 // If … … 163 229 Evaluate(interpreter, ds, "(if 1.0 2.0 3.0)", 0, 2.0); 164 230 Evaluate(interpreter, ds, "(if 10.0 2.0 3.0)", 0, 2.0); 165 // Evaluate(interpreter, ds, "(if (sqrt-1.0) 2.0 3.0)", 0, 3.0); // if(nan) should return the else branch231 Evaluate(interpreter, ds, "(if (log -1.0) 2.0 3.0)", 0, 3.0); // if(nan) should return the else branch 166 232 167 233 // NOT … … 171 237 Evaluate(interpreter, ds, "(not 2.0)", 0, -1.0); 172 238 Evaluate(interpreter, ds, "(not 0.0)", 0, 1.0); 239 Evaluate(interpreter, ds, "(not (log -1.0))", 0, 1.0); 173 240 174 241 // AND … … 181 248 Evaluate(interpreter, ds, "(and 1.0 2.0 3.0)", 0, 1.0); 182 249 Evaluate(interpreter, ds, "(and 1.0 -2.0 3.0)", 0, -1.0); 250 Evaluate(interpreter, ds, "(and (log -1.0))", 0, -1.0); // (and NaN) 251 Evaluate(interpreter, ds, "(and (log -1.0) 1.0)", 0, -1.0); // (and NaN 1.0) 252 183 253 184 254 // OR … … 190 260 Evaluate(interpreter, ds, "(or -1.0 -2.0 -3.0)", 0, -1.0); 191 261 Evaluate(interpreter, ds, "(or -1.0 -2.0 3.0)", 0, 1.0); 262 Evaluate(interpreter, ds, "(or (log -1.0))", 0, -1.0); // (or NaN) 263 Evaluate(interpreter, ds, "(or (log -1.0) 1.0)", 0, -1.0); // (or NaN 1.0) 192 264 193 265 // sin, cos, tan … … 204 276 Evaluate(interpreter, ds, "(log -3.0)", 0, Math.Log(-3)); 205 277 278 // power 279 Evaluate(interpreter, ds, "(pow 2.0 3.0)", 0, 8.0); 280 Evaluate(interpreter, ds, "(pow 4.0 0.5)", 0, 1.0); // interpreter should round to the nearest integer value value (.5 is rounded to the even number) 281 Evaluate(interpreter, ds, "(pow 4.0 2.5)", 0, 16.0); // interpreter should round to the nearest integer value value (.5 is rounded to the even number) 282 Evaluate(interpreter, ds, "(pow -2.0 3.0)", 0, -8.0); 283 Evaluate(interpreter, ds, "(pow 2.0 -3.0)", 0, 1.0 / 8.0); 284 Evaluate(interpreter, ds, "(pow -2.0 -3.0)", 0, -1.0 / 8.0); 285 286 // root 287 Evaluate(interpreter, ds, "(root 9.0 2.0)", 0, 3.0); 288 Evaluate(interpreter, ds, "(root 27.0 3.0)", 0, 3.0); 289 Evaluate(interpreter, ds, "(root 2.0 -3.0)", 0, Math.Pow(2.0, -1.0 / 3.0)); 290 206 291 // mean 207 292 Evaluate(interpreter, ds, "(mean -1.0 1.0 -1.0)", 0, -1.0 / 3.0); 208 293 209 // ADF 210 Evaluate(interpreter, ds, @"(PROG 211 (MAIN 212 (CALL ADF0)) 213 (defun ADF0 1.0))", 1, 1.0); 214 Evaluate(interpreter, ds, @"(PROG 215 (MAIN 216 (* (CALL ADF0) (CALL ADF0))) 217 (defun ADF0 2.0))", 1, 4.0); 218 Evaluate(interpreter, ds, @"(PROG 219 (MAIN 220 (CALL ADF0 2.0 3.0)) 221 (defun ADF0 222 (+ (ARG 0) (ARG 1))))", 1, 5.0); 223 Evaluate(interpreter, ds, @"(PROG 224 (MAIN (CALL ADF1 2.0 3.0)) 225 (defun ADF0 226 (- (ARG 1) (ARG 0))) 227 (defun ADF1 228 (+ (CALL ADF0 (ARG 1) (ARG 0)) 229 (CALL ADF0 (ARG 0) (ARG 1)))))", 1, 0.0); 230 Evaluate(interpreter, ds, @"(PROG 231 (MAIN (CALL ADF1 (variable 2.0 a) 3.0)) 232 (defun ADF0 233 (- (ARG 1) (ARG 0))) 234 (defun ADF1 235 (CALL ADF0 (ARG 1) (ARG 0))))", 1, 1.0); 236 Evaluate(interpreter, ds, @"(PROG 237 (MAIN (CALL ADF1 (variable 2.0 a) 3.0)) 238 (defun ADF0 239 (- (ARG 1) (ARG 0))) 240 (defun ADF1 241 (+ (CALL ADF0 (ARG 1) (ARG 0)) 242 (CALL ADF0 (ARG 0) (ARG 1)))))", 1, 0.0); 243 } 244 245 private void Evaluate(SymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds, string expr, int index, double expected) { 294 } 295 296 private void Evaluate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds, string expr, int index, double expected) { 246 297 var importer = new SymbolicExpressionImporter(); 247 298 ISymbolicExpressionTree tree = importer.Import(expr);
Note: See TracChangeset
for help on using the changeset viewer.