Changeset 2285 for trunk/tools


Ignore:
Timestamp:
08/13/09 17:28:07 (13 years ago)
Author:
gkronber
Message:

Worked on #722 (IModel should provide a Predict() method to get predicted values for an input vector).
At the same time removed parameter PunishmentFactor from GP algorithms (this parameter is internal to TreeEvaluators now).

Location:
trunk/tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/CedmaDatabaseMerger/CedmaDatabaseMerger.csproj

    r2277 r2285  
    3030    <ErrorReport>prompt</ErrorReport>
    3131    <WarningLevel>4</WarningLevel>
     32  </PropertyGroup>
     33  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     34    <DebugSymbols>true</DebugSymbols>
     35    <OutputPath>bin\x86\Debug\</OutputPath>
     36    <DefineConstants>DEBUG;TRACE</DefineConstants>
     37    <DebugType>full</DebugType>
     38    <PlatformTarget>x86</PlatformTarget>
     39    <ErrorReport>prompt</ErrorReport>
     40  </PropertyGroup>
     41  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     42    <OutputPath>bin\x86\Release\</OutputPath>
     43    <DefineConstants>TRACE</DefineConstants>
     44    <Optimize>true</Optimize>
     45    <DebugType>pdbonly</DebugType>
     46    <PlatformTarget>x86</PlatformTarget>
     47    <ErrorReport>prompt</ErrorReport>
    3248  </PropertyGroup>
    3349  <ItemGroup>
  • trunk/tools/CedmaDatabaseMerger/MergerForm.cs

    r2277 r2285  
    4949        importButton.Enabled = false;
    5050        BackgroundWorker worker = new BackgroundWorker();
     51        worker.WorkerReportsProgress = true;
    5152        worker.DoWork += CreateDoWorkDelegate(worker, importFileName);
    5253        worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
     
    7071        DatabaseService sourceDatabase = new DatabaseService("Data Source=" + importFileName);
    7172
     73        sourceDatabase.Connect();
    7274        var models = sourceDatabase.GetAllModels();
     75        var sourceDataset = sourceDatabase.GetDataset();
    7376        int importCount = 0;
    7477        foreach (HeuristicLab.Modeling.Database.IModel m in models) {
    75           HeuristicLab.Modeling.Model model = new HeuristicLab.Modeling.Model();
     78
     79          HeuristicLab.Modeling.IAnalyzerModel model = new AnalyzerModel();
     80          model.Predictor = (HeuristicLab.Modeling.IPredictor)PersistenceManager.RestoreFromGZip(sourceDatabase.GetModelData(m));
    7681          model.TargetVariable = m.TargetVariable.Name;
    77           model.Data = (IItem)PersistenceManager.RestoreFromGZip(sourceDatabase.GetModelData(m));
    78           model.Dataset = sourceDatabase.GetDataset();
     82          model.Dataset = sourceDataset;
    7983          model.TrainingSamplesStart = m.TrainingSamplesStart;
    8084          model.TrainingSamplesEnd = m.TrainingSamplesEnd;
     
    8387          model.TestSamplesStart = m.TestSamplesStart;
    8488          model.TestSamplesEnd = m.TestSamplesEnd;
     89          model.Predictor.Predict(sourceDataset, 10, 20);
    8590          //get all double properties to save as modelResult
    8691          IEnumerable<PropertyInfo> modelResultInfos = model.GetType().GetProperties().Where(
     
    8893          var modelResults = sourceDatabase.GetModelResults(m);
    8994          foreach (IModelResult result in modelResults) {
    90             PropertyInfo matchingPropInfo = modelResultInfos.First(x=>x.Name == result.Result.Name);
    91             if(matchingPropInfo!=null) matchingPropInfo.SetValue(model, result.Value, null);
     95            PropertyInfo matchingPropInfo = modelResultInfos.First(x => x.Name == result.Result.Name);
     96            if (matchingPropInfo != null) matchingPropInfo.SetValue(model, result.Value, null);
    9297          }
    9398          var inputVariableResults = sourceDatabase.GetInputVariableResults(m);
    9499          foreach (IInputVariableResult result in inputVariableResults) {
    95             model.AddInputVariables(result.Variable.Name);
     100            model.AddInputVariable(result.Variable.Name);
    96101            if (result.Result.Name == "VariableEvaluationImpact") {
    97102              model.SetVariableEvaluationImpact(result.Variable.Name, result.Value);
     
    100105            } else throw new FormatException();
    101106          }
    102          
     107
    103108          destiationDatabase.Persist(model, m.Algorithm.Name, m.Algorithm.Description);
    104109          worker.ReportProgress((++importCount * 100) / models.Count());
    105110        }
     111        sourceDatabase.Disconnect();
    106112      };
    107113    }
  • trunk/tools/CedmaImporter/Importer.cs

    r2277 r2285  
    99using HeuristicLab.GP.StructureIdentification;
    1010using System.Diagnostics;
     11using HeuristicLab.Modeling;
    1112
    1213namespace CedmaImporter {
     
    6263        ImportAllModels(dirName, reader, database);
    6364      }
     65      database.Disconnect();
    6466    }
    6567
     
    9092        string algoName = modelData[ALGORITHM_COLUMN].Trim();
    9193        try {
    92           HeuristicLab.Modeling.Model model = new HeuristicLab.Modeling.Model();
     94          HeuristicLab.Modeling.IAnalyzerModel model = new AnalyzerModel();
    9395          model.TargetVariable = targetVariableName;
    9496          model.Dataset = problem.Dataset;
     
    100102          model.TestSamplesEnd = problem.TestSamplesEnd;
    101103
    102 
    103           model.Data = ParseModel(dirName, modelData[FILENAME_COLUMN].Trim(), algoName);
    104 
    105104          SetModelResults(model, modelData);
    106105          SetInputVariableResults(model, modelData);
    107106
     107          model.Predictor = CreatePredictor(targetVariableName, dirName, modelData[FILENAME_COLUMN].Trim(), algoName);
    108108          database.Persist(model, algoName, null);
    109109        }
     
    113113    }
    114114
    115     private void SetInputVariableResults(HeuristicLab.Modeling.Model model, string[] modelData) {
     115    private void SetInputVariableResults(HeuristicLab.Modeling.IAnalyzerModel model, string[] modelData) {
    116116      for (int i = VARIABLE_IMPACTS; i < modelData.Length; i++) {
    117117        if (!string.IsNullOrEmpty(modelData[i])) {
    118           model.AddInputVariables(inputVariables[i]);
     118          model.AddInputVariable(inputVariables[i]);
    119119          if (results[i] == EVALUATION_IMPACT) {
    120120            model.SetVariableEvaluationImpact(inputVariables[i], double.Parse(modelData[i]));
     
    126126    }
    127127
    128     private void SetModelResults(HeuristicLab.Modeling.Model model, string[] modelData) {
     128    private void SetModelResults(HeuristicLab.Modeling.IAnalyzerModel model, string[] modelData) {
    129129      model.TrainingMeanSquaredError = double.Parse(modelData[TRAINING_MSE]);
    130130      model.ValidationMeanSquaredError = double.Parse(modelData[VALIDATION_MSE]);
     
    148148    }
    149149
    150     private HeuristicLab.Core.IItem ParseModel(string dirName, string modelFileName, string algoName) {
     150    private HeuristicLab.Modeling.IPredictor CreatePredictor(string targetVariable, string dirName, string modelFileName, string algoName) {
    151151      foreach (char c in Path.GetInvalidFileNameChars()) {
    152152        modelFileName = modelFileName.Replace(c, '_');
    153153      }
    154154      if (algoName == "SupportVectorRegression") {
    155         HeuristicLab.Data.SVMModel model = new HeuristicLab.Data.SVMModel();
     155        HeuristicLab.SupportVectorMachines.SVMModel model = new HeuristicLab.SupportVectorMachines.SVMModel();
    156156        model.Model = SVM.Model.Read(Path.Combine(dirName, modelFileName) + ".svm.model.txt");
    157157        model.RangeTransform = SVM.RangeTransform.Read(Path.Combine(dirName, modelFileName) + ".svm.transform.txt");
    158         return model;
     158        return new HeuristicLab.SupportVectorMachines.Predictor(model, targetVariable);
    159159      } else {
    160160        SymbolicExpressionImporter sexpImporter = new SymbolicExpressionImporter();
     
    163163          model.FunctionTree = sexpImporter.Import(reader);
    164164        }
    165         return model;
     165        return new HeuristicLab.GP.StructureIdentification.Predictor(new HL2TreeEvaluator(), model);
    166166      }
    167167    }
  • trunk/tools/Tools.sln

    r2277 r2285  
    5050    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    5151    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
    52     {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Debug|x86.ActiveCfg = Debug|Any CPU
     52    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Debug|x86.ActiveCfg = Debug|x86
     53    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Debug|x86.Build.0 = Debug|x86
    5354    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
    5455    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Release|Any CPU.Build.0 = Release|Any CPU
    5556    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Release|x86.ActiveCfg = Release|Any CPU
     57    {D1D66C9C-5B65-4348-B8B5-528A513695E4}.Release|x86.Build.0 = Release|Any CPU
    5658  EndGlobalSection
    5759  GlobalSection(SolutionProperties) = preSolution
Note: See TracChangeset for help on using the changeset viewer.