Changeset 17604 for branches/3040_VectorBasedGP
- Timestamp:
- 06/17/20 11:23:37 (4 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r17180 r17604 33 33 bool HasLocalParameters { get; } 34 34 35 // Can be null for "unknown" 36 Type DataType { get; } 37 35 38 int GetDepth(); 36 39 int GetLength(); -
branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r17180 r17604 96 96 } 97 97 98 public virtual Type DataType { 99 get { return null; } 100 } 101 98 102 public virtual IEnumerable<ISymbolicExpressionTreeNode> Subtrees { 99 103 get { return subtrees; } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r17593 r17604 315 315 private void btnSimplify_Click(object sender, EventArgs e) { 316 316 if (Content.Model.Interpreter is SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter) { // TODO: Own interface for data-dependent node-types-interpreter? 317 var simplifier = new VectorTreeSimplifier(interpreter , Content.ProblemData);317 var simplifier = new VectorTreeSimplifier(interpreter); 318 318 var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree); 319 319 UpdateModel(simplifiedExpressionTree); -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/VectorTreeSimplifier.cs
r17603 r17604 27 27 using HeuristicLab.Common; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>; 29 31 30 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 66 68 67 69 private readonly SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter; 68 private readonly IDataAnalysisProblemData problemData; 69 70 public VectorTreeSimplifier(SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter, IDataAnalysisProblemData problemData) { 70 71 public VectorTreeSimplifier(SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter) { 71 72 this.interpreter = interpreter; 72 this.problemData = problemData;73 73 } 74 74 … … 286 286 #region type predicates 287 287 public bool IsScalarNode(ISymbolicExpressionTreeNode node) { 288 var results = interpreter.EvaluateNode(node, problemData.Dataset, problemData.TrainingIndices); 289 return results.All(r => r.IsScalar); 288 return interpreter.GetNodeType(node) == typeof(double); 290 289 } 291 290 public bool IsVectorNode(ISymbolicExpressionTreeNode node) { 292 var results = interpreter.EvaluateNode(node, problemData.Dataset, problemData.TrainingIndices); 293 return results.All(r => r.IsVector); 291 return interpreter.GetNodeType(node) == typeof(DoubleVector); 294 292 } 295 293 #endregion -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentVectorExpressionGrammar.cs
r17554 r17604 130 130 var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { square, sqrt, cube, cubeRoot, power, root }); 131 131 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variable, binFactorVariable, factorVariable }); 132 var statisticsSymbols = new GroupSymbol(VectorStatisticsName, new List<ISymbol> { mean, sd, sum, length, min, max, variance, skewness, kurtosis});132 var statisticsSymbols = new GroupSymbol(VectorStatisticsName, new List<ISymbol> { mean, sd, sum, length, min, max, variance, skewness, kurtosis }); 133 133 var distancesSymbols = new GroupSymbol(VectorDistancesName, new List<ISymbol> { euclideanDistance, covariance }); 134 134 var aggregationSymbols = new GroupSymbol(VectorAggregationName, new List<ISymbol> { statisticsSymbols, distancesSymbols }); … … 217 217 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<double>(x)); 218 218 varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<double>(x)); 219 varSymbol.VariableDataType = typeof(double); 219 220 } 220 221 } … … 223 224 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<DoubleVector>(x)); 224 225 varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<DoubleVector>(x)); 226 varSymbol.VariableDataType = typeof(DoubleVector); 225 227 } 226 228 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
r17602 r17604 46 46 Exception 47 47 } 48 49 #region Aggregation Symbols 50 private static Type[] AggregationSymbols = new[] { 51 typeof(Sum), typeof(Mean), typeof(Length), typeof(StandardDeviation), typeof(Variance), 52 typeof(EuclideanDistance), typeof(Covariance) 53 }; 54 #endregion 48 55 49 56 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; … … 254 261 } 255 262 256 public virtual IEnumerable<EvaluationResult> EvaluateNode(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) { 257 //lock (syncRoot) { 258 // EvaluatedSolutions++; // increment the evaluated solutions counter 259 //} 260 261 var startNode = new StartSymbol().CreateTreeNode(); 262 startNode.AddSubtree(node); 263 var programNode = new ProgramRootSymbol().CreateTreeNode(); 264 programNode.AddSubtree(startNode); 265 var tree = new SymbolicExpressionTree(programNode); 266 267 var state = PrepareInterpreterState(tree, dataset); 268 269 foreach (var rowEnum in rows) { 270 int row = rowEnum; 271 var result = Evaluate(dataset, ref row, state); 272 yield return result; 273 state.Reset(); 274 } 263 public virtual Type GetNodeType(ISymbolicExpressionTreeNode node) { 264 if (node.DataType != null) 265 return node.DataType; 266 267 if (AggregationSymbols.Contains(node.Symbol.GetType())) 268 return typeof(double); 269 270 var argumentTypes = node.Subtrees.Select(GetNodeType); 271 if (argumentTypes.Any(t => t == typeof(DoubleVector))) 272 return typeof(DoubleVector); 273 274 return typeof(double); 275 275 } 276 276 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs
r17180 r17604 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 37 38 get { return constantValue; } 38 39 set { constantValue = value; } 40 } 41 42 public override Type DataType { 43 get { return typeof(double); } 39 44 } 40 45 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs
r17180 r17604 44 44 get { return variableName; } 45 45 set { variableName = value; } 46 } 47 48 public override Type DataType { 49 get { return typeof(double); } 46 50 } 47 51 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs
r17180 r17604 142 142 get { return maximumArity; } 143 143 } 144 145 [Storable] 146 private Type variableDataType; 147 public Type VariableDataType { 148 get { return variableDataType; } 149 set { 150 if (variableDataType == value) return; 151 variableDataType = value; 152 OnChanged(EventArgs.Empty); 153 } 154 } 144 155 #endregion 145 156 … … 166 177 multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma; 167 178 variableChangeProbability = original.variableChangeProbability; 179 variableDataType = original.variableDataType; 168 180 } 169 181 protected VariableBase(string name, string description) -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNodeBase.cs
r17180 r17604 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 42 43 get { return variableName; } 43 44 set { variableName = value; } 45 } 46 47 public override Type DataType { 48 get { return Symbol.VariableDataType; } 44 49 } 45 50
Note: See TracChangeset
for help on using the changeset viewer.