Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/07/09 16:19:21 (15 years ago)
Author:
gkronber
Message:

Fixed bugs in text export/import of SVM models. #772.

Location:
trunk/sources/HeuristicLab.SupportVectorMachines/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/Predictor.cs

    r2416 r2418  
    159159      StreamWriter writer = new StreamWriter(s);
    160160      writer.Write("Targetvariable: "); writer.WriteLine(p.targetVariable);
    161       writer.Write("LowerPredictionLimit: "); writer.WriteLine(p.LowerPredictionLimit.ToString("r"));
    162       writer.Write("UpperPredictionLimit: "); writer.WriteLine(p.UpperPredictionLimit.ToString("r"));
     161      writer.Write("LowerPredictionLimit: "); writer.WriteLine(p.LowerPredictionLimit.ToString("r", CultureInfo.InvariantCulture.NumberFormat));
     162      writer.Write("UpperPredictionLimit: "); writer.WriteLine(p.UpperPredictionLimit.ToString("r", CultureInfo.InvariantCulture.NumberFormat));
    163163      writer.Write("MaxTimeOffset: "); writer.WriteLine(p.MaxTimeOffset.ToString());
    164164      writer.Write("MinTimeOffset: "); writer.WriteLine(p.MinTimeOffset.ToString());
     
    176176    }
    177177
    178     public static Predictor Import(Stream s) {
     178    public static Predictor Import(TextReader reader) {
    179179      Predictor p = new Predictor();
    180       StreamReader reader = new StreamReader(s);
    181180      string[] targetVariableLine = reader.ReadLine().Split(':');
    182181      string[] lowerPredictionLimitLine = reader.ReadLine().Split(':');
     
    187186
    188187      p.targetVariable = targetVariableLine[1].Trim();
    189       p.LowerPredictionLimit = double.Parse(lowerPredictionLimitLine[1]);
    190       p.UpperPredictionLimit = double.Parse(upperPredictionLimitLine[1]);
     188      p.LowerPredictionLimit = double.Parse(lowerPredictionLimitLine[1], CultureInfo.InvariantCulture.NumberFormat);
     189      p.UpperPredictionLimit = double.Parse(upperPredictionLimitLine[1], CultureInfo.InvariantCulture.NumberFormat);
    191190      p.maxTimeOffset = int.Parse(maxTimeOffsetLine[1]);
    192191      p.minTimeOffset = int.Parse(minTimeOffsetLine[1]);
     
    195194        p.variableNames[inputVariable.Trim()] = i++;
    196195      }
    197       p.svmModel = SVMModel.Import(s);
     196      p.svmModel = SVMModel.Import(reader);
    198197      return p;
    199198    }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMModel.cs

    r2415 r2418  
    120120      StreamWriter writer = new StreamWriter(s);
    121121      writer.WriteLine("RangeTransform:");
     122      writer.Flush();
    122123      using (MemoryStream memStream = new MemoryStream()) {
    123124        SVM.RangeTransform.Write(memStream, model.RangeTransform);
     
    126127      }
    127128      writer.WriteLine("Model:");
    128 
     129      writer.Flush();
    129130      using (MemoryStream memStream = new MemoryStream()) {
    130131        SVM.Model.Write(memStream, model.Model);
     
    135136    }
    136137
    137     public static SVMModel Import(Stream s) {
     138    public static SVMModel Import(TextReader reader) {
    138139      SVMModel model = new SVMModel();
    139       StreamReader reader = new StreamReader(s);
    140140      while (reader.ReadLine().Trim() != "RangeTransform:") ; // read until line "RangeTransform";
    141       model.RangeTransform = SVM.RangeTransform.Read(s);
    142 
     141      model.RangeTransform = SVM.RangeTransform.Read(reader);
    143142      // read until "Model:"
    144143      while (reader.ReadLine().Trim() != "Model:") ;
    145       model.Model = SVM.Model.Read(s);
     144      model.Model = SVM.Model.Read(reader);
    146145      return model;
    147146    }
Note: See TracChangeset for help on using the changeset viewer.