Changeset 1906
- Timestamp:
- 05/27/09 13:22:41 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/AlgorithmBase.cs
r1873 r1906 70 70 } 71 71 72 public virtual IModel Model { 73 get { 74 if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result."); 75 IScope bestModelScope = engine.GlobalScope.GetVariableValue<IScope>("BestValidationSolution", false); 76 return CreateGPModel(bestModelScope); 77 } 78 } 79 72 80 public virtual int Elites { 73 81 get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; } … … 405 413 } 406 414 415 protected internal virtual Model CreateGPModel(IScope bestModelScope) { 416 Model model = new Model(); 417 Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true); 418 model.Data = bestModelScope.GetVariableValue<IFunctionTree>("FunctionTree", false); 419 model.Dataset = ds; 420 model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data); 421 model.TrainingMeanSquaredError = bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data; 422 model.ValidationMeanSquaredError = bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data; 423 return model; 424 } 425 407 426 public override object Clone(IDictionary<Guid, object> clonedObjects) { 408 427 AlgorithmBase clone = (AlgorithmBase)base.Clone(clonedObjects); -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs
r1890 r1906 312 312 } 313 313 314 protected internal override Model CreateGPModel(IScope bestModelScope) { 315 Model model = base.CreateGPModel(bestModelScope); 316 model.TestMeanSquaredError = bestModelScope.GetVariableValue<DoubleData>("TestQuality", false).Data; 317 return model; 318 } 319 314 320 public virtual IEditor CreateEditor() { 315 321 return new StandardGpEditor(this); -
trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj
r1888 r1906 83 83 <ItemGroup> 84 84 <Compile Include="ClassificationProblemInjector.cs" /> 85 <Compile Include="Model.cs" /> 86 <Compile Include="IModel.cs" /> 85 87 <Compile Include="SimpleEvaluatorBase.cs" /> 86 88 <Compile Include="ITimeSeriesAlgorithm.cs" /> -
trunk/sources/HeuristicLab.Modeling/3.2/IAlgorithm.cs
r1857 r1906 31 31 IOperator ProblemInjector { get; set; } 32 32 IEngine Engine { get; } 33 34 IModel Model { get; } 33 35 } 34 36 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj
r1869 r1906 82 82 <ItemGroup> 83 83 <Compile Include="SupportVectorRegression.cs" /> 84 <Compile Include="SVMRangeTransform.cs" />85 84 <Compile Include="SVMModel.cs" /> 86 85 <Compile Include="HeuristicLabSupportVectorMachinesPlugin.cs" /> -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMModel.cs
r1837 r1906 29 29 30 30 namespace HeuristicLab.Data { 31 public class SVMModel : ObjectData { 31 public class SVMModel : ItemBase { 32 private SVM.Model model; 32 33 /// <summary> 33 34 /// Gets or sets the SVM model. 34 35 /// </summary> 35 /// <remarks>Uses property <see cref="ObjectData.Data"/> of base class <see cref="ObjectData"></see>. 36 /// No own data storage present.</remarks> 37 public new SVM.Model Data { 38 get { return (SVM.Model)base.Data; } 39 set { base.Data = value; } 36 public SVM.Model Model { 37 get { return model; } 38 set { model = value; } 39 } 40 41 42 /// <summary> 43 /// Gets or sets the range transformation for the model. 44 /// </summary> 45 private SVM.RangeTransform rangeTransform; 46 public SVM.RangeTransform RangeTransform { 47 get { return rangeTransform; } 48 set { rangeTransform = value; } 40 49 } 41 50 … … 49 58 clonedObjects.Add(Guid, clone); 50 59 // beware we are only using a shallow copy here! (gkronber) 51 clone.Data = Data; 60 clone.Model = Model; 61 clone.RangeTransform = RangeTransform; 52 62 return clone; 53 63 } … … 64 74 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 65 75 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 66 XmlNode data = document.CreateElement("Data"); 67 76 XmlNode model = document.CreateElement("Model"); 68 77 using (MemoryStream stream = new MemoryStream()) { 69 SVM.Model.Write(stream, Data);78 SVM.Model.Write(stream, Model); 70 79 stream.Seek(0, System.IO.SeekOrigin.Begin); 71 80 StreamReader reader = new StreamReader(stream); 72 data.InnerText = reader.ReadToEnd();73 node.AppendChild( data);81 model.InnerText = reader.ReadToEnd(); 82 node.AppendChild(model); 74 83 } 84 85 XmlNode rangeTransform = document.CreateElement("RangeTransform"); 86 using (MemoryStream stream = new MemoryStream()) { 87 SVM.RangeTransform.Write(stream, RangeTransform); 88 stream.Seek(0, System.IO.SeekOrigin.Begin); 89 StreamReader reader = new StreamReader(stream); 90 rangeTransform.InnerText = reader.ReadToEnd(); 91 node.AppendChild(rangeTransform); 92 } 93 75 94 return node; 76 95 } … … 84 103 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 85 104 base.Populate(node, restoredObjects); 86 XmlNode data = node.SelectSingleNode("Data"); 87 using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(data.InnerText))) { 88 Data = SVM.Model.Read(stream); 105 XmlNode model = node.SelectSingleNode("Model"); 106 using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(model.InnerText))) { 107 Model = SVM.Model.Read(stream); 108 } 109 XmlNode rangeTransform = node.SelectSingleNode("RangeTransform"); 110 using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(rangeTransform.InnerText))) { 111 RangeTransform = SVM.RangeTransform.Read(stream); 89 112 } 90 113 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs
r1851 r1906 53 53 AddVariableInfo(new VariableInfo("SVMGamma", "Gamma parameter in kernel function", typeof(DoubleData), VariableKind.In)); 54 54 AddVariableInfo(new VariableInfo("SVMModel", "Represent the model learned by the SVM", typeof(SVMModel), VariableKind.New | VariableKind.Out)); 55 55 // AddVariableInfo(new VariableInfo("SVMRangeTransform", "The applied transformation during the learning the model", typeof(SVMRangeTransform), VariableKind.New | VariableKind.Out)); 56 56 } 57 57 … … 92 92 //persist variables in scope 93 93 SVMModel modelData = new SVMModel(); 94 modelData.Data = model; 94 modelData.Model = model; 95 modelData.RangeTransform = rangeTransform; 95 96 scope.AddVariable(new Variable(scope.TranslateName("SVMModel"), modelData)); 96 SVMRangeTransform rangeTransformData = new SVMRangeTransform();97 rangeTransformData.Data = rangeTransform;98 scope.AddVariable(new Variable(scope.TranslateName("SVMRangeTransform"), rangeTransformData));97 //SVMRangeTransform rangeTransformData = new SVMRangeTransform(); 98 //rangeTransformData.Data = rangeTransform; 99 //scope.AddVariable(new Variable(scope.TranslateName("SVMRangeTransform"), rangeTransformData)); 99 100 return null; 100 101 } else { -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs
r1870 r1906 41 41 42 42 AddVariableInfo(new VariableInfo("SVMModel", "Represent the model learned by the SVM", typeof(SVMModel), VariableKind.In)); 43 AddVariableInfo(new VariableInfo("SVMRangeTransform", "The applied transformation during the learning the model", typeof(SVMRangeTransform), VariableKind.In));43 // AddVariableInfo(new VariableInfo("SVMRangeTransform", "The applied transformation during the learning the model", typeof(SVMRangeTransform), VariableKind.In)); 44 44 45 45 AddVariableInfo(new VariableInfo("Values", "Target vs predicted values", typeof(DoubleMatrixData), VariableKind.New | VariableKind.Out)); … … 54 54 int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data; 55 55 56 SVM .Model model = GetVariableValue<SVMModel>("SVMModel", scope, true).Data;57 SVM.RangeTransform rangeTransform = GetVariableValue<SVMRangeTransform>("SVMRangeTransform", scope, true).Data;56 SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true); 57 // SVM.RangeTransform rangeTransform = GetVariableValue<SVMRangeTransform>("SVMRangeTransform", scope, true).Data; 58 58 59 59 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end); 60 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, rangeTransform);60 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, modelData.RangeTransform); 61 61 62 62 double[,] values = new double[end-start, 2]; 63 63 for (int i = 0; i < end - start; i++) { 64 values[i,0] = SVM.Prediction.Predict(model , scaledProblem.X[i]);64 values[i,0] = SVM.Prediction.Predict(modelData.Model, scaledProblem.X[i]); 65 65 values[i,1] = dataset.Samples[(start + i) * dataset.Columns + targetVariable]; 66 66 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs
r1889 r1906 58 58 } 59 59 60 public IModel Model { 61 get { 62 if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result."); 63 IScope bestModelScope = engine.GlobalScope.GetVariableValue<IScope>("BestValidationSolution", false); 64 return CreateSVMModel(bestModelScope); 65 } 66 } 67 60 68 public DoubleArrayData NuList { 61 69 get { return GetVariableInjector().GetVariable("NuList").GetValue<DoubleArrayData>(); } … … 127 135 modelCreator.GetVariableInfo("SVMModel").ActualName = "Model"; 128 136 modelCreator.GetVariableInfo("SVMNu").ActualName = "Nu"; 129 modelCreator.GetVariableInfo("SVMRangeTransform").ActualName = "RangeTransform";130 137 modelCreator.GetVariableInfo("SVMType").ActualName = "Type"; 131 132 138 133 139 modelProcessor.AddSubOperator(modelCreator); … … 196 202 evaluator.Name = p + "SimpleEvaluator"; 197 203 evaluator.GetVariableInfo("SVMModel").ActualName = "Model"; 198 evaluator.GetVariableInfo("SVMRangeTransform").ActualName = "RangeTransform";199 204 evaluator.GetVariableInfo("SamplesStart").ActualName = p + "SamplesStart"; 200 205 evaluator.GetVariableInfo("SamplesEnd").ActualName = p + "SamplesEnd"; … … 277 282 } 278 283 284 protected internal virtual Model CreateSVMModel(IScope bestModelScope) { 285 Model model = new Model(); 286 model.Data = bestModelScope.GetVariableValue<SVMModel>("BestValidationModel", false); 287 return model; 288 } 289 279 290 private IOperator GetVariableInjector() { 280 291 return GetMainOperator().SubOperators[0];
Note: See TracChangeset
for help on using the changeset viewer.