Changeset 2328 for trunk/sources/HeuristicLab.SupportVectorMachines/3.2
- Timestamp:
- 09/03/09 15:00:23 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.SupportVectorMachines/3.2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/HeuristicLab.SupportVectorMachines-3.2.csproj
r2319 r2328 83 83 </ItemGroup> 84 84 <ItemGroup> 85 <Compile Include="PredictorView.cs"> 86 <SubType>UserControl</SubType> 87 </Compile> 88 <Compile Include="PredictorView.Designer.cs"> 89 <DependentUpon>PredictorView.cs</DependentUpon> 90 </Compile> 85 91 <Compile Include="Predictor.cs" /> 86 92 <Compile Include="PredictorBuilder.cs" /> … … 154 160 </ItemGroup> 155 161 <ItemGroup> 162 <EmbeddedResource Include="PredictorView.resx"> 163 <DependentUpon>PredictorView.cs</DependentUpon> 164 </EmbeddedResource> 156 165 <EmbeddedResource Include="SVMModelView.resx"> 157 166 <DependentUpon>SVMModelView.cs</DependentUpon> -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/Predictor.cs
r2290 r2328 32 32 33 33 namespace HeuristicLab.SupportVectorMachines { 34 public class Predictor : ItemBase, IPredictor{34 public class Predictor : PredictorBase { 35 35 private SVMModel svmModel; 36 public SVMModel Model { 37 get { return svmModel; } 38 } 39 36 40 private Dictionary<string, int> variableNames = new Dictionary<string, int>(); 37 41 private string targetVariable; … … 46 50 } 47 51 48 public double[] Predict(Dataset input, int start, int end) {52 public override double[] Predict(Dataset input, int start, int end) { 49 53 if (start < 0 || end <= start) throw new ArgumentException("start must be larger than zero and strictly smaller than end"); 50 54 if (end > input.Rows) throw new ArgumentOutOfRangeException("number of rows in input is smaller then end"); … … 64 68 double[] result = new double[rows]; 65 69 for (int row = 0; row < rows; row++) { 66 result[row] = SVM.Prediction.Predict(model, scaledProblem.X[row]);70 result[row] = Math.Max(Math.Min(SVM.Prediction.Predict(model, scaledProblem.X[row]), UpperPredictionLimit), LowerPredictionLimit); 67 71 } 68 72 return result; … … 70 74 71 75 public override IView CreateView() { 72 return svmModel.CreateView();76 return new PredictorView(this); 73 77 } 74 78 -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/PredictorBuilder.cs
r2319 r2328 37 37 AddVariableInfo(new VariableInfo("TargetVariable", "The target variable", typeof(StringData), VariableKind.In)); 38 38 AddVariableInfo(new VariableInfo("InputVariables", "The input variable names", typeof(StringData), VariableKind.In)); 39 AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of the training set", typeof(IntData), VariableKind.In)); 40 AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of the training set", typeof(IntData), VariableKind.In)); 41 AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the range of predicted values", typeof(DoubleData), VariableKind.In)); 39 42 AddVariableInfo(new VariableInfo("Predictor", "The predictor can be used to generate estimated values", typeof(IPredictor), VariableKind.New)); 40 43 } … … 48 51 SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true); 49 52 int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data; 53 int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 54 int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 55 double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data; 56 50 57 string targetVariableName = ds.GetVariableName(targetVariable); 51 58 ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true); … … 53 60 for (int i = 0; i < ds.Columns; i++) variableNames[ds.GetVariableName(i)] = i; 54 61 55 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), new Predictor(model, targetVariableName, variableNames))); 62 double mean = ds.GetMean(targetVariable, start, end); 63 double range = ds.GetRange(targetVariable, start, end); 64 65 Predictor predictor = new Predictor(model, targetVariableName, variableNames); 66 predictor.LowerPredictionLimit = mean - punishmentFactor * range; 67 predictor.UpperPredictionLimit = mean + punishmentFactor * range; 68 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor)); 56 69 return null; 57 70 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMModelView.cs
r2322 r2328 33 33 public partial class SVMModelView : ViewBase { 34 34 private SVMModel model; 35 35 public SVMModelView() : base() { 36 InitializeComponent(); 37 } 36 38 public SVMModelView(SVMModel model) : base() { 37 39 InitializeComponent(); 38 40 this.model = model; 39 model.Changed += (sender, args) => UpdateControls();41 model.Changed += (sender, args) => Refresh(); 40 42 41 UpdateControls(); 42 } 43 44 protected override void UpdateControls() { 45 base.UpdateControls(); 46 numberOfSupportVectors.Text = model.Model.SupportVectorCount.ToString(); 47 rho.Text = model.Model.Rho[0].ToString(); 48 svmType.Text = model.Model.Parameter.SvmType.ToString(); 49 kernelType.Text = model.Model.Parameter.KernelType.ToString(); 50 gamma.Text = model.Model.Parameter.Gamma.ToString(); 43 numberOfSupportVectors.DataBindings.Add(new Binding("Text", model.Model, "SupportVectorCount")); 44 rho.DataBindings.Add(new Binding("Text", model.Model, "Rho")); 45 svmType.DataBindings.Add(new Binding("Text", model.Model.Parameter, "SvmType")); 46 kernelType.DataBindings.Add(new Binding("Text", model.Model.Parameter, "KernelType")); 47 gamma.DataBindings.Add(new Binding("Text", model.Model.Parameter, "Gamma")); 51 48 } 52 49 } -
trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs
r2319 r2328 394 394 injector.AddVariable(new HeuristicLab.Core.Variable("KernelType", new StringData("RBF"))); 395 395 injector.AddVariable(new HeuristicLab.Core.Variable("Type", new StringData("NU_SVR"))); 396 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0))); 396 397 397 398 return injector;
Note: See TracChangeset
for help on using the changeset viewer.