- Timestamp:
- 08/14/09 19:56:04 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/Predictor.cs
r2285 r2290 34 34 public class Predictor : ItemBase, IPredictor { 35 35 private SVMModel svmModel; 36 private Dictionary<string, int> variableNames = new Dictionary<string, int>(); 36 37 private string targetVariable; 37 38 38 39 public Predictor() : base() { } // for persistence 39 40 40 public Predictor(SVMModel model, string targetVariable )41 public Predictor(SVMModel model, string targetVariable, Dictionary<string, int> variableNames) 41 42 : base() { 42 43 this.svmModel = model; 43 44 this.targetVariable = targetVariable; 45 this.variableNames = variableNames; 44 46 } 45 47 … … 49 51 RangeTransform transform = svmModel.RangeTransform; 50 52 Model model = svmModel.Model; 53 // maps columns of the current input dataset to the columns that were originally used in training 54 Dictionary<int, int> newIndex = new Dictionary<int, int>(); 55 foreach (var pair in variableNames) { 56 newIndex[input.GetVariableIndex(pair.Key)] = pair.Value; 57 } 51 58 52 Problem p = SVMHelper.CreateSVMProblem(input, input.GetVariableIndex(targetVariable), start, end);59 Problem p = SVMHelper.CreateSVMProblem(input, input.GetVariableIndex(targetVariable), newIndex, start, end); 53 60 Problem scaledProblem = SVM.Scaling.Scale(p, transform); 54 61 … … 70 77 clone.svmModel = (SVMModel)Auxiliary.Clone(svmModel, clonedObjects); 71 78 clone.targetVariable = targetVariable; 79 clone.variableNames = new Dictionary<string, int>(variableNames); 72 80 return clone; 73 81 } … … 79 87 node.Attributes.Append(targetVarAttr); 80 88 node.AppendChild(PersistenceManager.Persist(svmModel, document, persistedObjects)); 89 XmlNode variablesNode = document.CreateElement("Variables"); 90 foreach (var pair in variableNames) { 91 XmlNode pairNode = document.CreateElement("Variable"); 92 XmlAttribute nameAttr = document.CreateAttribute("Name"); 93 XmlAttribute indexAttr = document.CreateAttribute("Index"); 94 nameAttr.Value = pair.Key; 95 indexAttr.Value = XmlConvert.ToString(pair.Value); 96 pairNode.Attributes.Append(nameAttr); 97 pairNode.Attributes.Append(indexAttr); 98 variablesNode.AppendChild(pairNode); 99 } 100 node.AppendChild(variablesNode); 81 101 return node; 82 102 } … … 86 106 targetVariable = node.Attributes["TargetVariable"].Value; 87 107 svmModel = (SVMModel)PersistenceManager.Restore(node.ChildNodes[0], restoredObjects); 108 109 variableNames = new Dictionary<string, int>(); 110 XmlNode variablesNode = node.ChildNodes[1]; 111 foreach (XmlNode pairNode in variablesNode.ChildNodes) { 112 variableNames[pairNode.Attributes["Name"].Value] = XmlConvert.ToInt32(pairNode.Attributes["Index"].Value); 113 } 88 114 } 89 115 }
Note: See TracChangeset
for help on using the changeset viewer.