Changeset 15906 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers
- Timestamp:
- 04/16/18 08:35:59 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSchemaFrequencyAnalyzer.cs
r15351 r15906 43 43 private const string ExecuteInParallelParameterName = "ExecuteInParallel"; 44 44 private const string MaximumDegreeOfParallelismParameterName = "MaximumDegreeOfParallelism"; 45 private const string SchemaDefinitionParameterName = "SchemaDefinition"; 45 46 46 47 private static readonly Dictionary<string, string> ShortNames = new Dictionary<string, string> { 47 { "Addition", "+" },48 { "Subtraction", "-" },49 { "Multiplication", "*" },50 { "Division", "/" },51 { "Exponential", "exp" },52 { "Logarithm", "log" }53 };48 { "Addition", "+" }, 49 { "Subtraction", "-" }, 50 { "Multiplication", "*" }, 51 { "Division", "/" }, 52 { "Exponential", "exp" }, 53 { "Logarithm", "log" } 54 }; 54 55 55 56 [Storable] … … 63 64 private QueryMatch qm; 64 65 66 67 public IConstrainedValueParameter<StringValue> SchemaDefinitionParameter { 68 get { return (IConstrainedValueParameter<StringValue>)Parameters[SchemaDefinitionParameterName]; } 69 } 65 70 public IFixedValueParameter<BoolValue> ExecuteInParallelParameter { 66 71 get { return (IFixedValueParameter<BoolValue>)Parameters[ExecuteInParallelParameterName]; } … … 122 127 Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName)); 123 128 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName)); 129 130 var schemaDefinitions = new ItemSet<StringValue>(new[] { 131 new StringValue("="), 132 new StringValue("#"), 133 new StringValue("=,#") 134 }); 135 var schemaDefinitionParameter = new ConstrainedValueParameter<StringValue>(SchemaDefinitionParameterName, schemaDefinitions); 136 schemaDefinitionParameter.Value = schemaDefinitions.First(); 137 Parameters.Add(schemaDefinitionParameter); 124 138 } 125 139 … … 185 199 } 186 200 187 var schemas = SchemaCreator.GenerateCombinedSchemas(vertices, MinimumSchemaLength, 0, StrictSchemaMatching).ToList(); 201 List<ISymbolicExpressionTree> schemas; 202 var def = SchemaDefinitionParameter.Value.Value; 203 switch (def) { 204 case "=": 205 schemas = SchemaCreator.GenerateAnyNodeSchemas(vertices, MinimumSchemaLength, 0, StrictSchemaMatching).ToList(); 206 break; 207 case "#": 208 schemas = SchemaCreator.GenerateAnySubtreeSchemas(vertices, MinimumSchemaLength, 0, StrictSchemaMatching).ToList(); 209 break; 210 case "=,#": 211 schemas = SchemaCreator.GenerateCombinedSchemas(vertices, MinimumSchemaLength, 0, StrictSchemaMatching).ToList(); 212 break; 213 default: 214 return base.Apply(); 215 } 188 216 var schemaStrings = schemas.Select(x => x.Root.GetSubtree(0).GetSubtree(0).FormatToString(StrictSchemaMatching)).ToList(); 189 int[][] matchingIndices; 217 int[][] matchingIndices = new int[schemas.Count][]; 218 219 var tNodes = trees.Select(x => QueryMatch.InitializePostOrder(x.Root.GetSubtree(0).GetSubtree(0))).ToList(); 190 220 if (ExecuteInParallel) { 191 matchingIndices = new int[schemas.Count][];192 221 Parallel.For(0, schemas.Count, new ParallelOptions { MaxDegreeOfParallelism = MaximumDegreeOfParallelism }, i => { 193 222 var schema = schemas[i]; 194 matchingIndices[i] = Enumerable.Range(0, trees.Count).Where(v => qm.Match(trees[v], schema)).ToArray(); 223 var sNodes = QueryMatch.InitializePostOrder(schema.Root.GetSubtree(0).GetSubtree(0)); 224 matchingIndices[i] = Enumerable.Range(0, trees.Count).Where(idx => qm.Match(tNodes[idx], sNodes)).ToArray(); 195 225 }); 196 226 } else { 197 matchingIndices = schemas.Select(x => Enumerable.Range(0, trees.Count).Where(v => qm.Match(trees[v], x)).ToArray()).ToArray(); 227 for (int i = 0; i < schemas.Count; ++i) { 228 var schema = schemas[i]; 229 var sNodes = QueryMatch.InitializePostOrder(schema.Root.GetSubtree(0).GetSubtree(0)); 230 matchingIndices[i] = Enumerable.Range(0, trees.Count).Where(idx => qm.Match(tNodes[idx], sNodes)).ToArray(); 231 } 198 232 } 199 233 … … 203 237 if (ExecuteInParallel) { 204 238 var locker = new object(); 205 Parallel.For(0, schemas.Count, new ParallelOptions { MaxDegreeOfParallelism = MaximumDegreeOfParallelism }, i => { 239 Parallel.For(0, schemas.Count, new ParallelOptions { 240 MaxDegreeOfParallelism = MaximumDegreeOfParallelism 241 }, i => { 206 242 var indices = matchingIndices[i]; 207 243 if (indices.Length > 1) {
Note: See TracChangeset
for help on using the changeset viewer.