Changeset 14238
- Timestamp:
- 08/05/16 17:34:16 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 1 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/ModelCreation/NcaModelCreator.cs
r14237 r14238 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using HeuristicLab.Common; -
branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r14237 r14238 104 104 this.allowedInputVariables = allowedInputVariables.ToArray(); 105 105 106 // check input variables. Only double variables are allowed.107 var invalidInputs =108 allowedInputVariables.Where(name => !dataset.VariableHasType<double>(name));109 if (invalidInputs.Any())110 throw new NotSupportedException("Gradient tree boosting only supports real-valued variables. Unsupported inputs: " + string.Join(", ", invalidInputs));111 112 113 106 var inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, 114 107 allowedInputVariables.Concat(new string[] { targetVariable }), -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r14185 r14238 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics.Contracts; 24 25 using System.Linq; 25 26 using HeuristicLab.Algorithms.DataAnalysis; … … 46 47 if (!problemData.TrainingIndices.Any()) return null; // don't create an LR model if the problem does not have a training set (e.g. loaded into an existing model) 47 48 48 //clear checked inputVariables 49 foreach (var inputVariable in problemData.InputVariables.CheckedItems) { 50 problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false); 51 } 49 var usedDoubleVariables = 50 Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 51 .OfType<VariableTreeNode>() 52 .Select(node => node.VariableName) 53 .Concat( 54 Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 55 .OfType<VariableConditionTreeNode>() 56 .Select(node => node.VariableName) 57 ) 58 .Distinct(); 52 59 53 //check inputVariables used in the symbolic regression model 54 var usedVariables = 55 Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select( 56 node => node.VariableName).Distinct(); 57 foreach (var variable in usedVariables) { 58 problemData.InputVariables.SetItemCheckedState( 59 problemData.InputVariables.First(x => x.Value == variable), true); 60 } 60 var usedFactorVariables = 61 Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 62 .OfType<FactorVariableTreeNode>() 63 .Select(node => Tuple.Create(node.VariableName, node.VariableValue)) 64 .Distinct(); 61 65 62 var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError); 66 // create a new problem and dataset 67 var variableNames = 68 usedDoubleVariables 69 .Concat(usedFactorVariables.Select(t => t.Item1 + "=" + t.Item2)) 70 .Concat(new string[] { problemData.TargetVariable }) 71 .ToArray(); 72 var variableValues = 73 usedDoubleVariables.Select(name => problemData.Dataset.GetDoubleValues(name).ToList()) 74 .Concat( 75 // create binary variable 76 usedFactorVariables.Select(t => problemData.Dataset.GetReadOnlyStringValues(t.Item1).Select(val => val == t.Item2 ? 1.0 : 0.0).ToList()) 77 ) 78 .Concat(new[] { problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList() }); 79 80 var newDs = new Dataset(variableNames, variableValues); 81 var newProblemData = new RegressionProblemData(newDs, variableNames.Take(variableNames.Length - 1), variableNames.Last()); 82 newProblemData.TrainingPartition.Start = problemData.TrainingPartition.Start; 83 newProblemData.TrainingPartition.End = problemData.TrainingPartition.End; 84 newProblemData.TestPartition.Start = problemData.TestPartition.Start; 85 newProblemData.TestPartition.End = problemData.TestPartition.End; 86 87 var solution = LinearRegression.CreateLinearRegressionSolution(newProblemData, out rmse, out cvRmsError); 63 88 solution.Name = "Baseline (linear subset)"; 64 89 return solution; … … 68 93 protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 69 94 foreach (var sol in base.CreateBaselineSolutions()) yield return sol; 95 96 // does not support lagged variables 97 if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break; 98 70 99 yield return CreateLinearRegressionSolution(); 71 100 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberOfVariablesEvaluator.cs
r14185 r14238 66 66 if (decimalPlaces >= 0) 67 67 r2 = Math.Round(r2, decimalPlaces); 68 return new double[2] { r2, solution.IterateNodesPostfix().OfType< VariableTreeNode>().Count() }; // count the number of variables68 return new double[2] { r2, solution.IterateNodesPostfix().OfType<IVariableTreeNode>().Count() }; // count the number of variables 69 69 } 70 70 -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs
r14237 r14238 200 200 // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node 201 201 var node = currSelected.Content; 202 if (node is ConstantTreeNode || node is VariableTreeNode Base) return;202 if (node is ConstantTreeNode || node is VariableTreeNode) return; 203 203 // check if the currently selected node can accept the copied node as a child 204 204 // no need to check the grammar, an arity check will do just fine here -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.cs
r14185 r14238 35 35 [View("Variable View")] 36 36 [Content(typeof(Variable), true)] 37 [Content(typeof(FactorVariable), true)] 37 38 public partial class VariableView : SymbolView { 38 39 private CheckedItemCollectionView<StringValue> variableNamesView; 39 40 40 public new Variable Content {41 get { return (Variable )base.Content; }41 public new VariableBase Content { 42 get { return (VariableBase)base.Content; } 42 43 set { base.Content = value; } 43 44 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeInsertDialog.cs
r14185 r14238 55 55 constantValueLabel.Visible = true; 56 56 constantValueTextBox.Visible = true; 57 } else if (symbol is Variable ) {58 var variable = (Variable )symbol;57 } else if (symbol is VariableBase) { 58 var variable = (VariableBase)symbol; 59 59 foreach (var name in variable.VariableNames) variableNamesCombo.Items.Add(name); 60 60 variableNamesCombo.SelectedIndex = 0; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs
r14232 r14238 167 167 if (aggregateLaggedVariables) { 168 168 tree.Root.ForEachNodePrefix(node => { 169 if (node.Symbol is Variable) { 170 var varNode = node as VariableTreeNode; 171 IncReferenceCount(references, varNode.VariableName); 172 } else if (node.Symbol is VariableCondition) { 173 var varCondNode = node as VariableConditionTreeNode; 174 IncReferenceCount(references, varCondNode.VariableName); 175 } else if (node.Symbol is FactorVariable) { 169 if (node is IVariableTreeNode) { 176 170 var factorNode = node as FactorVariableTreeNode; 177 if ( aggregateFactorVariables) {178 IncReferenceCount(references, factorNode.VariableName );171 if (factorNode != null && !aggregateFactorVariables) { 172 IncReferenceCount(references, factorNode.VariableName + "=" + factorNode.VariableValue); 179 173 } else { 180 IncReferenceCount(references, factorNode.ToString()); 174 var varNode = node as IVariableTreeNode; 175 IncReferenceCount(references, varNode.VariableName); 181 176 } 182 177 } … … 189 184 190 185 private static void GetVariableReferences(Dictionary<string, int> references, ISymbolicExpressionTreeNode node, int currentLag, bool aggregateFactorVariables) { 191 if (node.Symbol is LaggedVariable) { 192 var laggedVarNode = node as LaggedVariableTreeNode; 193 IncReferenceCount(references, laggedVarNode.VariableName, currentLag + laggedVarNode.Lag); 194 } else if (node.Symbol is Variable) { 195 var varNode = node as VariableTreeNode; 196 IncReferenceCount(references, varNode.VariableName, currentLag); 197 } else if (node.Symbol is FactorVariable) { 198 var factorNode = node as FactorVariableTreeNode; 199 if (aggregateFactorVariables) { 200 IncReferenceCount(references, factorNode.VariableName, currentLag); 186 if (node is IVariableTreeNode) { 187 var laggedVarTreeNode = node as LaggedVariableTreeNode; 188 var factorVarTreeNode = node as FactorVariableTreeNode; 189 var varConditionTreeNode = node as VariableConditionTreeNode; 190 if (laggedVarTreeNode != null) { 191 IncReferenceCount(references, laggedVarTreeNode.VariableName, currentLag + laggedVarTreeNode.Lag); 192 } else if (factorVarTreeNode != null) { 193 if (aggregateFactorVariables) { 194 IncReferenceCount(references, factorVarTreeNode.VariableName, currentLag); 195 } else { 196 IncReferenceCount(references, factorVarTreeNode.VariableName + "=" + factorVarTreeNode.VariableValue, currentLag); 197 } 198 } else if (varConditionTreeNode != null) { 199 IncReferenceCount(references, varConditionTreeNode.VariableName, currentLag); 200 GetVariableReferences(references, node.GetSubtree(0), currentLag, aggregateFactorVariables); 201 GetVariableReferences(references, node.GetSubtree(1), currentLag, aggregateFactorVariables); 201 202 } else { 202 IncReferenceCount(references, factorNode.ToString(), currentLag); 203 } 204 } else if (node.Symbol is VariableCondition) { 205 var varCondNode = node as VariableConditionTreeNode; 206 IncReferenceCount(references, varCondNode.VariableName, currentLag); 207 GetVariableReferences(references, node.GetSubtree(0), currentLag, aggregateFactorVariables); 208 GetVariableReferences(references, node.GetSubtree(1), currentLag, aggregateFactorVariables); 203 var varNode = node as IVariableTreeNode; 204 IncReferenceCount(references, varNode.VariableName, currentLag); 205 } 209 206 } else if (node.Symbol is Integral) { 210 207 var laggedNode = node as LaggedTreeNode; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r14237 r14238 140 140 <Compile Include="Importer\Token.cs" /> 141 141 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 142 <Compile Include="Interfaces\IVariableSymbol.cs" /> 142 143 <Compile Include="Interpreter\SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs" /> 143 144 <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" /> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r14237 r14238 182 182 return node.Symbol is Variable; 183 183 } 184 184 private bool IsVariableBase(ISymbolicExpressionTreeNode node) { 185 return node.Symbol is VariableBase; 186 } 185 187 private bool IsConstant(ISymbolicExpressionTreeNode node) { 186 188 return node.Symbol is Constant; … … 203 205 /// <returns></returns> 204 206 public ISymbolicExpressionTreeNode GetSimplifiedTree(ISymbolicExpressionTreeNode original) { 205 if (IsConstant(original) || IsVariable (original)) {207 if (IsConstant(original) || IsVariableBase(original)) { 206 208 return (ISymbolicExpressionTreeNode)original.Clone(); 207 209 } else if (IsAddition(original)) { … … 718 720 } if (IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0)) { 719 721 return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a))); 720 } else if (IsVariable (a) && IsConstant(b)) {722 } else if (IsVariableBase(a) && IsConstant(b)) { 721 723 // merge constant values into variable weights 722 724 var constB = ((ConstantTreeNode)b).Value; 723 ((VariableTreeNode )a).Weight /= constB;725 ((VariableTreeNodeBase)a).Weight /= constB; 724 726 return a; 725 } else if (IsVariable (a) && IsVariable(b) && AreSameVariable(a, b)) {727 } else if (IsVariableBase(a) && IsVariableBase(b) && AreSameVariable(a, b)) { 726 728 // cancel variables 727 729 var aVar = a as VariableTreeNode; … … 835 837 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNodeBase>() 836 838 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 837 group node by node.VariableName + lag into g 839 let cat = (node is FactorVariableTreeNode) ? ((FactorVariableTreeNode)node).VariableValue : string.Empty 840 group node by node.VariableName + cat + lag into g 838 841 select g; 839 842 var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNodeBase)); … … 861 864 // $ * 1.0 => $ 862 865 return a; 863 } else if (IsConstant(b) && IsVariable (a)) {866 } else if (IsConstant(b) && IsVariableBase(a)) { 864 867 // multiply constants into variables weights 865 ((VariableTreeNode )a).Weight *= ((ConstantTreeNode)b).Value;868 ((VariableTreeNodeBase)a).Weight *= ((ConstantTreeNode)b).Value; 866 869 return a; 867 870 } else if (IsConstant(b) && IsAddition(a)) { … … 944 947 return aVar.VariableName == bVar.VariableName; 945 948 } 949 var aFactor = a as FactorVariableTreeNode; 950 var bFactor = b as FactorVariableTreeNode; 951 if (aFactor != null && bFactor != null) { 952 return aFactor.VariableName == bFactor.VariableName && 953 aFactor.VariableValue == bFactor.VariableValue; 954 } 955 946 956 return false; 947 957 } … … 951 961 var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees); 952 962 while (prod.Subtrees.Any()) prod.RemoveSubtree(0); 953 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode >()963 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNodeBase>() 954 964 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 955 965 group node by node.VariableName + lag into g 956 966 orderby g.Count() 957 967 select g; 958 var constantProduct = (from node in subtrees.OfType<VariableTreeNode >()968 var constantProduct = (from node in subtrees.OfType<VariableTreeNodeBase>() 959 969 select node.Weight) 960 970 .Concat(from node in subtrees.OfType<ConstantTreeNode>() … … 964 974 965 975 var unchangedSubtrees = from tree in subtrees 966 where !(tree is VariableTreeNode )976 where !(tree is VariableTreeNodeBase) 967 977 where !(tree is ConstantTreeNode) 968 978 select tree; … … 1000 1010 if (IsConstant(x)) { 1001 1011 ((ConstantTreeNode)x).Value *= -1; 1002 } else if (IsVariable (x)) {1003 var variableTree = (VariableTreeNode )x;1012 } else if (IsVariableBase(x)) { 1013 var variableTree = (VariableTreeNodeBase)x; 1004 1014 variableTree.Weight *= -1.0; 1005 1015 } else if (IsAddition(x)) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r14185 r14238 63 63 var variables = 64 64 SymbolicExpressionTree.IterateNodesPrefix() 65 .OfType< VariableTreeNode>()65 .OfType<IVariableTreeNode>() 66 66 .Select(x => x.VariableName) 67 67 .Distinct(); 68 var variableConditions = SymbolicExpressionTree.IterateNodesPrefix()69 .OfType<VariableConditionTreeNode>().Select(x => x.VariableName).Distinct();70 68 71 return variables. Union(variableConditions).OrderBy(x => x);69 return variables.OrderBy(x => x); 72 70 } 73 71 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r14232 r14238 213 213 grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value; 214 214 grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value; 215 foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable >()) {215 foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) { 216 216 if (!varSymbol.Fixed) { 217 217 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x)); … … 225 225 factorSymbol.VariableValues = factorSymbol.VariableNames 226 226 .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList()); 227 }228 }229 foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {230 if (!varSymbol.Fixed) {231 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x));232 varSymbol.VariableNames = problemData.AllowedInputVariables;233 227 } 234 228 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs
r14237 r14238 39 39 } 40 40 public Variable() : base("Variable", "Represents a variable value.") { } 41 public Variable(string name, string description) : base(name, description) { } 41 42 42 43 public override ISymbolicExpressionTreeNode CreateTreeNode() { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs
r14237 r14238 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableClass] 29 public abstract class VariableBase : Symbol {29 public abstract class VariableBase : Symbol, IVariableSymbol { 30 30 #region Properties 31 31 [Storable] -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs
r14185 r14238 30 30 [StorableClass] 31 31 [Item("Variable Condition", "Represents a condition that tests a given variable against a specified threshold.")] 32 public sealed class VariableCondition : Symbol {32 public sealed class VariableCondition : Symbol, IVariableSymbol { 33 33 #region properties 34 34 [Storable] -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs
r14185 r14238 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 30 30 [StorableClass] 31 public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode {31 public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode, IVariableTreeNode { 32 32 #region properties 33 33 public new VariableCondition Symbol { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNodeBase.cs
r14237 r14238 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableClass] 29 public abstract class VariableTreeNodeBase : SymbolicExpressionTreeTerminalNode {29 public abstract class VariableTreeNodeBase : SymbolicExpressionTreeTerminalNode, IVariableTreeNode { 30 30 public new VariableBase Symbol { 31 31 get { return (VariableBase)base.Symbol; } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
r13986 r14238 90 90 public static IEnumerable<Tuple<string, double>> CalculateImpacts(IRegressionSolution solution, 91 91 DataPartitionEnum data = DataPartitionEnum.Training, 92 ReplacementMethodEnum replacement = ReplacementMethodEnum.Median) {92 ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median) { 93 93 94 94 var problemData = solution.ProblemData; … … 126 126 var modifiableDataset = ((Dataset)dataset).ToModifiable(); 127 127 128 foreach (var inputVariable in problemData.AllowedInputVariables) { 129 var newEstimates = EvaluateModelWithReplacedVariable(solution.Model, inputVariable, modifiableDataset, rows, replacement); 128 // calculate impacts for double variables 129 foreach (var inputVariable in problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<double>)) { 130 var newEstimates = EvaluateModelWithReplacedVariable(solution.Model, inputVariable, modifiableDataset, rows, replacementMethod); 130 131 var newR2 = OnlinePearsonsRCalculator.Calculate(targetValues, newEstimates, out error); 131 132 if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during R² calculation with replaced inputs."); … … 134 135 var impact = originalR2 - newR2; 135 136 impacts[inputVariable] = impact; 137 } 138 // calculate impacts for factor variables 139 foreach (var inputVariable in problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<string>)) { 140 var smallestImpact = double.PositiveInfinity; 141 foreach (var repl in problemData.Dataset.GetStringValues(inputVariable, rows).Distinct()) { 142 var newEstimates = EvaluateModelWithReplacedVariable(solution.Model, inputVariable, modifiableDataset, rows, Enumerable.Repeat(repl, dataset.Rows)); 143 var newR2 = OnlinePearsonsRCalculator.Calculate(targetValues, newEstimates, out error); 144 if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during R² calculation with replaced inputs."); 145 146 newR2 = newR2 * newR2; 147 var impact = originalR2 - newR2; 148 if (impact < smallestImpact) smallestImpact = impact; 149 } 150 impacts[inputVariable] = smallestImpact; 136 151 } 137 152 return impacts.OrderByDescending(i => i.Value).Select(i => Tuple.Create(i.Key, i.Value)); … … 169 184 } 170 185 171 dataset.ReplaceVariable(variable, replacementValues); 186 return EvaluateModelWithReplacedVariable(model, variable, dataset, rows, replacementValues); 187 } 188 189 private static IEnumerable<double> EvaluateModelWithReplacedVariable(IRegressionModel model, string variable, ModifiableDataset dataset, IEnumerable<int> rows, IEnumerable<double> replacementValues) { 190 var originalValues = dataset.GetReadOnlyDoubleValues(variable).ToList(); 191 dataset.ReplaceVariable(variable, replacementValues.ToList()); 172 192 //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements 173 193 var estimates = model.GetEstimatedValues(dataset, rows).ToList(); … … 176 196 return estimates; 177 197 } 198 private static IEnumerable<double> EvaluateModelWithReplacedVariable(IRegressionModel model, string variable, ModifiableDataset dataset, IEnumerable<int> rows, IEnumerable<string> replacementValues) { 199 var originalValues = dataset.GetReadOnlyStringValues(variable).ToList(); 200 dataset.ReplaceVariable(variable, replacementValues.ToList()); 201 //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements 202 var estimates = model.GetEstimatedValues(dataset, rows).ToList(); 203 dataset.ReplaceVariable(variable, originalValues); 204 205 return estimates; 206 } 178 207 } 179 208 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r13761 r14238 77 77 public void ReplaceVariable(string variableName, IList values) { 78 78 if (!variableValues.ContainsKey(variableName)) 79 throw new ArgumentException(string.Format("Variable {0} is not present in the dataset." ), variableName);79 throw new ArgumentException(string.Format("Variable {0} is not present in the dataset.", variableName)); 80 80 if (values.Count != variableValues[variableName].Count) 81 81 throw new ArgumentException("The number of values must coincide with the number of dataset rows."); -
branches/symbreg-factors-2650/HeuristicLab.Problems.GrammaticalEvolution/3.4/SymbolicRegression/GESymbolicDataAnalysisProblem.cs
r14185 r14238 177 177 ApplyLinearScalingParameter.Hidden = true; 178 178 179 if(problemData.AllowedInputVariables.Any(name => !problemData.Dataset.VariableHasType<double>(name))) throw new NotSupportedException("Categorical variables are not supported"); 179 180 SymbolicExpressionTreeGrammar = new GESymbolicExpressionGrammar(problemData.AllowedInputVariables, problemData.AllowedInputVariables.Count() * 3); 180 181 SymbolicExpressionTreeInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
Note: See TracChangeset
for help on using the changeset viewer.