Changeset 14266 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
- Timestamp:
- 08/29/16 10:29:10 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r14251 r14266 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics.Contracts; 24 25 using System.Linq; 25 26 using AutoDiff; … … 322 323 var factorVarNode = node as BinaryFactorVariableTreeNode; 323 324 // factor variable values are only 0 or 1 and set in x accordingly 324 var par = new AutoDiff.Variable(); 325 parameters.Add(par); 326 variableNames.Add(varNode.VariableName); 327 categoricalVariableValues.Add(factorVarNode != null ? factorVarNode.VariableValue : string.Empty); 325 var varValue = factorVarNode != null ? factorVarNode.VariableValue : string.Empty; 326 var par = FindOrCreateParameter(varNode.VariableName, varValue, parameters, variableNames, categoricalVariableValues); 328 327 329 328 if (updateVariableWeights) { … … 340 339 var products = new List<Term>(); 341 340 foreach (var variableValue in factorVarNode.Symbol.GetVariableValues(factorVarNode.VariableName)) { 342 var par = new AutoDiff.Variable(); 343 parameters.Add(par); 344 variableNames.Add(factorVarNode.VariableName); 345 categoricalVariableValues.Add(variableValue); 341 var par = FindOrCreateParameter(factorVarNode.VariableName, variableValue, parameters, variableNames, categoricalVariableValues); 346 342 347 343 var wVar = new AutoDiff.Variable(); … … 516 512 term = null; 517 513 return false; 514 } 515 516 // for each factor variable value we need a parameter which represents a binary indicator for that variable & value combination 517 // each binary indicator is only necessary once. So we only create a parameter if this combination is not yet available 518 private static Term FindOrCreateParameter(string varName, string varValue, 519 List<AutoDiff.Variable> parameters, List<string> variableNames, List<string> variableValues) { 520 Contract.Assert(variableNames.Count == variableValues.Count); 521 int idx = -1; 522 for (int i = 0; i < variableNames.Count; i++) { 523 if (variableNames[i] == varName && variableValues[i] == varValue) { 524 idx = i; 525 break; 526 } 527 } 528 529 AutoDiff.Variable par = null; 530 if (idx == -1) { 531 // not found -> create new parameter and entries in names and values lists 532 par = new AutoDiff.Variable(); 533 parameters.Add(par); 534 variableNames.Add(varName); 535 variableValues.Add(varValue); 536 } else { 537 par = parameters[idx]; 538 } 539 return par; 518 540 } 519 541
Note: See TracChangeset
for help on using the changeset viewer.