#region License Information
/* HeuristicLab
* Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Linq;
using HEAL.Attic;
using HeuristicLab.Common;
using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
[StorableType("B91038EA-338E-40BB-99D2-738B96C66D81")]
public abstract class DataAnalysisGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
[StorableConstructor]
protected DataAnalysisGrammar(StorableConstructorFlag _) : base(_) { }
protected DataAnalysisGrammar(DataAnalysisGrammar original, Cloner cloner) : base(original, cloner) { }
protected DataAnalysisGrammar(string name, string description) : base(name, description) { }
public void ConfigureVariableSymbols(IDataAnalysisProblemData problemData) {
var dataset = problemData.Dataset;
foreach (var varSymbol in Symbols.OfType()) {
if (!varSymbol.Fixed) {
varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType(x));
varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType(x));
}
}
foreach (var factorSymbol in Symbols.OfType()) {
if (!factorSymbol.Fixed) {
factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType(x));
factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType(x));
factorSymbol.VariableValues = factorSymbol.VariableNames
.ToDictionary(varName => varName, varName => dataset.GetStringValues(varName).Distinct().ToList());
}
}
foreach (var factorSymbol in Symbols.OfType()) {
if (!factorSymbol.Fixed) {
factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType(x));
factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType(x));
factorSymbol.VariableValues = factorSymbol.VariableNames
.ToDictionary(varName => varName,
varName => dataset.GetStringValues(varName).Distinct()
.Select((n, i) => Tuple.Create(n, i))
.ToDictionary(tup => tup.Item1, tup => tup.Item2));
}
}
}
}
}