Changeset 2415 for trunk/sources/HeuristicLab.SupportVectorMachines
- Timestamp:
- 10/07/09 11:58:21 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.SupportVectorMachines/3.2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/Predictor.cs
r2414 r2415 79 79 Problem p = SVMHelper.CreateSVMProblem(input, input.GetVariableIndex(targetVariable), newIndex, 80 80 start, end, minTimeOffset, maxTimeOffset); 81 Problem scaledProblem = SVM.Scaling.Scale(p, transform);81 Problem scaledProblem = transform.Scale(p); 82 82 83 83 int targetVariableIndex = input.GetVariableIndex(targetVariable); … … 155 155 } 156 156 } 157 158 public static void Export(Predictor p, Stream s) { 159 StreamWriter writer = new StreamWriter(s); 160 writer.Write("Targetvariable: "); writer.WriteLine(p.targetVariable); 161 writer.Write("LowerPredictionLimit: "); writer.WriteLine(p.LowerPredictionLimit.ToString()); 162 writer.Write("UpperPredictionLimit: "); writer.WriteLine(p.UpperPredictionLimit.ToString()); 163 writer.Write("MaxTimeOffset: "); writer.WriteLine(p.MaxTimeOffset.ToString()); 164 writer.Write("MinTimeOffset: "); writer.WriteLine(p.MinTimeOffset.ToString()); 165 writer.Write("InputVariables :"); 166 writer.Write(p.GetInputVariables().First()); 167 foreach (string variable in p.GetInputVariables().Skip(1)) { 168 writer.Write("; "); writer.Write(variable); 169 } 170 writer.WriteLine(); 171 writer.Flush(); 172 using (MemoryStream memStream = new MemoryStream()) { 173 SVMModel.Export(p.Model, memStream); 174 memStream.WriteTo(s); 175 } 176 } 177 178 public static Predictor Import(Stream s) { 179 Predictor p = new Predictor(); 180 StreamReader reader = new StreamReader(s); 181 string[] targetVariableLine = reader.ReadLine().Split(':'); 182 string[] lowerPredictionLimitLine = reader.ReadLine().Split(':'); 183 string[] upperPredictionLimitLine = reader.ReadLine().Split(':'); 184 string[] maxTimeOffsetLine = reader.ReadLine().Split(':'); 185 string[] minTimeOffsetLine = reader.ReadLine().Split(':'); 186 string[] inputVariableLine = reader.ReadLine().Split(':', ';'); 187 188 p.targetVariable = targetVariableLine[1].Trim(); 189 p.LowerPredictionLimit = double.Parse(lowerPredictionLimitLine[1]); 190 p.UpperPredictionLimit = double.Parse(upperPredictionLimitLine[1]); 191 p.maxTimeOffset = int.Parse(maxTimeOffsetLine[1]); 192 p.minTimeOffset = int.Parse(minTimeOffsetLine[1]); 193 int i = 1; 194 foreach (string inputVariable in inputVariableLine.Skip(1)) { 195 p.variableNames[inputVariable.Trim()] = i++; 196 } 197 p.svmModel = SVMModel.Import(s); 198 return p; 199 } 157 200 } 158 201 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/PredictorView.cs
r2413 r2415 29 29 using System.Windows.Forms; 30 30 using HeuristicLab.Core; 31 using System.IO; 31 32 32 33 namespace HeuristicLab.SupportVectorMachines { … … 50 51 } 51 52 52 protected override string GetModelString() { 53 StringBuilder builder = new StringBuilder(); 54 builder.Append("LowerPredictionLimit: ").AppendLine(predictor.LowerPredictionLimit.ToString()); 55 builder.Append("UpperPredictionLimit: ").AppendLine(predictor.UpperPredictionLimit.ToString()); 56 builder.Append("MaxTimeOffset: ").AppendLine(predictor.MaxTimeOffset.ToString()); 57 builder.Append("MinTimeOffset: ").AppendLine(predictor.MinTimeOffset.ToString()); 58 builder.Append("InputVariables :"); 59 builder.Append(predictor.GetInputVariables().First()); 60 foreach (string variable in predictor.GetInputVariables().Skip(1)) { 61 builder.Append("; ").Append(variable); 53 protected override void UpdateControls() { 54 base.UpdateControls(); 55 textBox.Text = GetModelString(); 56 } 57 58 private string GetModelString() { 59 if (predictor == null) return ""; 60 using (MemoryStream s = new MemoryStream()) { 61 Predictor.Export(predictor, s); 62 s.Flush(); 63 s.Seek(0, System.IO.SeekOrigin.Begin); 64 StreamReader reader = new StreamReader(s); 65 return reader.ReadToEnd(); 62 66 } 63 builder.AppendLine();64 builder.Append(base.GetModelString());65 return builder.ToString();66 67 } 67 68 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMModel.cs
r2322 r2415 116 116 } 117 117 } 118 119 public static void Export(SVMModel model, Stream s) { 120 StreamWriter writer = new StreamWriter(s); 121 writer.WriteLine("RangeTransform:"); 122 using (MemoryStream memStream = new MemoryStream()) { 123 SVM.RangeTransform.Write(memStream, model.RangeTransform); 124 memStream.Seek(0, SeekOrigin.Begin); 125 memStream.WriteTo(s); 126 } 127 writer.WriteLine("Model:"); 128 129 using (MemoryStream memStream = new MemoryStream()) { 130 SVM.Model.Write(memStream, model.Model); 131 memStream.Seek(0, SeekOrigin.Begin); 132 memStream.WriteTo(s); 133 } 134 s.Flush(); 135 } 136 137 public static SVMModel Import(Stream s) { 138 SVMModel model = new SVMModel(); 139 StreamReader reader = new StreamReader(s); 140 while (reader.ReadLine().Trim() != "RangeTransform:") ; // read until line "RangeTransform"; 141 model.RangeTransform = SVM.RangeTransform.Read(s); 142 143 // read until "Model:" 144 while (reader.ReadLine().Trim() != "Model:") ; 145 model.Model = SVM.Model.Read(s); 146 return model; 147 } 118 148 } 119 149 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMModelView.cs
r2413 r2415 49 49 kernelType.DataBindings.Add(new Binding("Text", model.Model.Parameter, "KernelType")); 50 50 gamma.DataBindings.Add(new Binding("Text", model.Model.Parameter, "Gamma")); 51 UpdateControls(); 51 52 } 52 53 … … 56 57 } 57 58 58 protected virtual string GetModelString() { 59 StringBuilder builder = new StringBuilder(); 60 builder.AppendLine("RangeTransform:"); 61 using (MemoryStream stream = new MemoryStream()) { 62 SVM.RangeTransform.Write(stream, model.RangeTransform); 63 stream.Seek(0, System.IO.SeekOrigin.Begin); 64 StreamReader reader = new StreamReader(stream); 65 builder.AppendLine(reader.ReadToEnd()); 59 private string GetModelString() { 60 using (MemoryStream s = new MemoryStream()) { 61 SVMModel.Export(model, s); 62 s.Flush(); 63 s.Seek(0, System.IO.SeekOrigin.Begin); 64 StreamReader reader = new StreamReader(s); 65 return reader.ReadToEnd(); 66 66 } 67 builder.AppendLine("Model:");68 using (MemoryStream stream = new MemoryStream()) {69 SVM.Model.Write(stream, model.Model);70 stream.Seek(0, System.IO.SeekOrigin.Begin);71 StreamReader reader = new StreamReader(stream);72 builder.AppendLine(reader.ReadToEnd());73 }74 return builder.ToString();75 67 } 76 68 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs
r2349 r2415 28 28 using HeuristicLab.DataAnalysis; 29 29 using System.Threading; 30 using SVM; 30 31 31 32 namespace HeuristicLab.SupportVectorMachines { … … 85 86 parameter.Nu = GetVariableValue<DoubleData>("SVMNu", scope, true).Data; 86 87 parameter.Gamma = GetVariableValue<DoubleData>("SVMGamma", scope, true).Data; 88 parameter.CacheSize = 500; 89 parameter.Probability = false; 87 90 88 91 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end, minTimeOffset, maxTimeOffset); 89 SVM.RangeTransform rangeTransform = SVM. Scaling.DetermineRange(problem);90 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, rangeTransform);92 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 93 SVM.Problem scaledProblem = rangeTransform.Scale(problem); 91 94 92 95 SVM.Model model = StartTraining(scaledProblem, parameter); -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs
r2357 r2415 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.DataAnalysis; 29 using SVM; 29 30 30 31 namespace HeuristicLab.SupportVectorMachines { … … 56 57 SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true); 57 58 SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end, minTimeOffset, maxTimeOffset); 58 SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, modelData.RangeTransform);59 SVM.Problem scaledProblem = modelData.RangeTransform.Scale(problem); 59 60 60 61 double[,] values = new double[scaledProblem.Count, 2];
Note: See TracChangeset
for help on using the changeset viewer.