Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/DataAnalysisGrammar.cs @ 17753

Last change on this file since 17753 was 17413, checked in by mkommend, 5 years ago

#3052: Added DatanAnalyisGrammar for automatic configuration of variable symbols.

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Linq;
24using HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
29
30  [StorableType("B91038EA-338E-40BB-99D2-738B96C66D81")]
31  public abstract class DataAnalysisGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
32    [StorableConstructor]
33    protected DataAnalysisGrammar(StorableConstructorFlag _) : base(_) { }
34    protected DataAnalysisGrammar(DataAnalysisGrammar original, Cloner cloner) : base(original, cloner) { }
35    protected DataAnalysisGrammar(string name, string description) : base(name, description) { }
36
37    public void ConfigureVariableSymbols(IDataAnalysisProblemData problemData) {
38      var dataset = problemData.Dataset;
39      foreach (var varSymbol in Symbols.OfType<VariableBase>()) {
40        if (!varSymbol.Fixed) {
41          varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<double>(x));
42          varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<double>(x));
43        }
44      }
45      foreach (var factorSymbol in Symbols.OfType<BinaryFactorVariable>()) {
46        if (!factorSymbol.Fixed) {
47          factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<string>(x));
48          factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<string>(x));
49          factorSymbol.VariableValues = factorSymbol.VariableNames
50            .ToDictionary(varName => varName, varName => dataset.GetStringValues(varName).Distinct().ToList());
51        }
52      }
53      foreach (var factorSymbol in Symbols.OfType<FactorVariable>()) {
54        if (!factorSymbol.Fixed) {
55          factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<string>(x));
56          factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<string>(x));
57          factorSymbol.VariableValues = factorSymbol.VariableNames
58            .ToDictionary(varName => varName,
59            varName => dataset.GetStringValues(varName).Distinct()
60            .Select((n, i) => Tuple.Create(n, i))
61            .ToDictionary(tup => tup.Item1, tup => tup.Item2));
62        }
63      }
64    }
65
66
67  }
68}
Note: See TracBrowser for help on using the repository browser.