Changeset 14717 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs
- Timestamp:
- 03/06/17 16:40:33 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs
r14554 r14717 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Common; … … 51 52 : base(original, cloner) { 52 53 variableName = original.variableName; 53 if 54 if(original.weights != null) { 54 55 this.weights = new double[original.Weights.Length]; 55 56 Array.Copy(original.Weights, weights, weights.Length); … … 74 75 75 76 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 76 if 77 if(random.NextDouble() < 0.2) { 77 78 VariableName = Symbol.VariableNames.SampleRandom(random); 78 if 79 if(weights.Length != Symbol.GetVariableValues(VariableName).Count()) { 79 80 // if the length of the weight array does not match => re-initialize weights 80 81 weights = … … 87 88 var idx = random.Next(weights.Length); 88 89 // 50% additive & 50% multiplicative 89 if 90 if(random.NextDouble() < 0.5) { 90 91 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, 91 92 Symbol.WeightManipulatorSigma); … … 103 104 104 105 public double GetValue(string cat) { 105 // TODO: perf 106 var s = Symbol; 107 int idx = 0; 108 foreach (var val in s.GetVariableValues(VariableName)) { 109 if (cat == val) return weights[idx]; 110 idx++; 111 } 112 throw new ArgumentOutOfRangeException("Found unknown value " + cat + " for variable " + VariableName); 106 return weights[Symbol.GetIndexForValue(VariableName, cat)]; 113 107 } 114 108
Note: See TracChangeset
for help on using the changeset viewer.