Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2260


Ignore:
Timestamp:
08/08/09 10:15:33 (15 years ago)
Author:
gkronber
Message:

Worked on CEDMA importer. #719

Location:
trunk/tools
Files:
5 edited

Legend:

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

    r2259 r2260  
    3131    <WarningLevel>4</WarningLevel>
    3232  </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>
     48  </PropertyGroup>
    3349  <ItemGroup>
    34     <Reference Include="HeuristicLab.CEDMA.Server-3.3, Version=3.3.0.2238, Culture=neutral, processorArchitecture=x86">
     50    <Reference Include="HeuristicLab.CEDMA.Server-3.3, Version=3.3.0.2258, Culture=neutral, processorArchitecture=x86">
    3551      <SpecificVersion>False</SpecificVersion>
    3652      <HintPath>..\..\sources\HeuristicLab\bin\x86\Release\plugins\HeuristicLab.CEDMA.Server-3.3.dll</HintPath>
     
    7591      <SpecificVersion>False</SpecificVersion>
    7692      <HintPath>..\..\sources\HeuristicLab\bin\x86\Release\plugins\HeuristicLab.SupportVectorMachines-3.2.dll</HintPath>
     93    </Reference>
     94    <Reference Include="LibSVM, Version=2.84.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86">
     95      <SpecificVersion>False</SpecificVersion>
     96      <HintPath>..\..\sources\HeuristicLab\bin\x86\Release\plugins\LibSVM.dll</HintPath>
    7797    </Reference>
    7898    <Reference Include="System" />
  • trunk/tools/CedmaImporter/Importer.cs

    r2259 r2260  
    66using HeuristicLab.Modeling.Database;
    77using HeuristicLab.Modeling.Database.SQLServerCompact;
     8using HeuristicLab.GP;
     9using HeuristicLab.GP.Interfaces;
     10using HeuristicLab.GP.StructureIdentification;
     11using System.Diagnostics;
    812
    913namespace CedmaImporter {
     
    3337      using (StreamReader reader = File.OpenText(fileName)) {
    3438        ReadResultsAndInputVariables(reader);
    35         ImportAllModels(reader, database);
     39        ImportAllModels(dirName, reader, database);
    3640      }
    3741    }
     
    5660    }
    5761
    58     private void ImportAllModels(StreamReader reader, DatabaseService database) {
     62    private void ImportAllModels(string dirName, StreamReader reader, DatabaseService database) {
    5963      while (!reader.EndOfStream) {
    6064        string modelLine = reader.ReadLine();
    6165        string[] modelData = modelLine.Split(';');
    6266        int id = int.Parse(modelData[ID_COLUMN]);
    63         string fileName = modelData[FILENAME_COLUMN];
    64         string targetVariableName = modelData[TARGETVARIABLE_COLUMN];
    65         string algoName = modelData[ALGORITHM_COLUMN];
    66         Variable targetVariable = new Variable(targetVariableName);
     67        string targetVariableName = modelData[TARGETVARIABLE_COLUMN].Trim();
     68        string algoName = modelData[ALGORITHM_COLUMN].Trim();
     69        HeuristicLab.Core.IItem modelItem = ParseModel(dirName, modelData[FILENAME_COLUMN].Trim(), algoName);
     70        HeuristicLab.Modeling.Database.SQLServerCompact.Variable targetVariable = new HeuristicLab.Modeling.Database.SQLServerCompact.Variable(targetVariableName);
    6771        Algorithm algorithm = new Algorithm(algoName);
    6872        Model model = new Model(targetVariable, algorithm);
     
    8387        //foreach (InputVariableResult inputVariableResult in inputVariableResults)
    8488        //  database.Persist(inputVariableResult);
    85        
     89
    8690      }
    8791    }
     
    9195      return from i in Enumerable.Range(0, inputVariables.Count())
    9296             where inputVariables[i] != null && results[i] != null && double.TryParse(modelData[i], out temp)
    93              select new InputVariableResult(new InputVariable(model, new Variable(inputVariables[i])), results[i], double.Parse(modelData[i]));
     97             select new InputVariableResult(new InputVariable(model, new HeuristicLab.Modeling.Database.SQLServerCompact.Variable(inputVariables[i])), results[i], double.Parse(modelData[i]));
    9498    }
    9599
     
    99103             select new ModelResult(model, results[i], double.Parse(modelData[i]));
    100104    }
     105
     106    Dictionary<string, IFunction> knownFunctions = new Dictionary<string, IFunction>() {
     107    {"+", new Addition()},
     108    {"and", new And()},
     109    {"mean", new Average()},
     110    {"cos", new Cosinus()},
     111    {"/", new Division()},
     112    {"equ", new Equal()},
     113    {"exp", new Exponential()},
     114    {">", new GreaterThan()},
     115    {"if", new IfThenElse()},
     116    {"<", new LessThan()},
     117    {"log", new Logarithm()},
     118    {"*", new Multiplication()},
     119    {"not", new Not()},
     120    {"or", new Or()},
     121    {"expt", new Power()},
     122    {"sign", new Signum()},
     123    {"sin",new Sinus()},
     124    {"sqrt", new Sqrt()},
     125    {"-", new Subtraction()},
     126    {"tan", new Tangens()},
     127    {"xor", new Xor()}
     128    };
     129    Constant constant = new Constant();
     130    HeuristicLab.GP.StructureIdentification.Variable variable = new HeuristicLab.GP.StructureIdentification.Variable();
     131    Differential differential = new Differential();
     132
     133    private HeuristicLab.Core.IItem ParseModel(string dirName, string modelFileName, string algoName) {
     134      if (algoName == "SupportVectorRegression") {
     135        HeuristicLab.Data.SVMModel model = new HeuristicLab.Data.SVMModel();
     136        model.Model = SVM.Model.Read(Path.Combine(dirName, modelFileName) + ".svm.model.txt");
     137        model.RangeTransform = SVM.RangeTransform.Read(Path.Combine(dirName, modelFileName) + ".svm.transform.txt");
     138        return model;
     139      } else {
     140        GeneticProgrammingModel model = new GeneticProgrammingModel();
     141        IEnumerable<Token> tokens = GetTokenStream(File.OpenText(Path.Combine(dirName, modelFileName) + ".gp.txt"));
     142        model.FunctionTree = ParseSexp(new Queue<Token>(tokens));
     143        return model;
     144      }
     145    }
     146
     147    private IEnumerable<Token> GetTokenStream(StreamReader reader) {
     148      return from line in GetLineStream(reader)
     149             let strTokens = line.Split(new string[] { " ", "\t", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).AsEnumerable()
     150             from strToken in strTokens
     151             let t = Token.Parse(strToken)
     152             where t != null
     153             select t;
     154    }
     155
     156    private IEnumerable<string> GetLineStream(StreamReader reader) {
     157      while (!reader.EndOfStream) yield return reader.ReadLine().Replace("(", " ( ").Replace(")", " ) ");
     158      yield break;
     159    }
     160
     161    private HeuristicLab.GP.Interfaces.IFunctionTree ParseSexp(Queue<Token> tokens) {
     162      Expect(Token.LPAR, tokens);
     163
     164      if (tokens.Peek().Symbol == TokenSymbol.SYMB) {
     165        if (tokens.Peek().StringValue.Equals("variable")) {
     166          return ParseVariable(tokens);
     167        } else if (tokens.Peek().StringValue.Equals("differential")) {
     168          return ParseDifferential(tokens);
     169        } else {
     170          Token curToken = tokens.Dequeue();
     171          IFunctionTree tree = CreateTree(curToken);
     172          while (!tokens.Peek().Equals(Token.RPAR)) {
     173            tree.AddSubTree(ParseSexp(tokens));
     174          }
     175          Expect(Token.RPAR, tokens);
     176          return tree;
     177        }
     178      } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) {
     179        ConstantFunctionTree t = (ConstantFunctionTree)constant.GetTreeNode();
     180        t.Value = tokens.Dequeue().DoubleValue;
     181        return t;
     182      } else {
     183        throw new FormatException("Expected function or constant symbol");
     184      }
     185    }
     186
     187    private IFunctionTree ParseDifferential(Queue<Token> tokens) {
     188      Debug.Assert(tokens.Dequeue().StringValue == "differential");
     189      VariableFunctionTree t = (VariableFunctionTree)differential.GetTreeNode();
     190      t.Weight = tokens.Dequeue().DoubleValue;
     191      t.VariableName = tokens.Dequeue().StringValue;
     192      t.SampleOffset = (int)tokens.Dequeue().DoubleValue;
     193      Expect(Token.RPAR, tokens);
     194      return t;
     195    }
     196
     197    private IFunctionTree ParseVariable(Queue<Token> tokens) {
     198      Debug.Assert(tokens.Dequeue().StringValue == "variable");
     199      VariableFunctionTree t = (VariableFunctionTree)variable.GetTreeNode();
     200      t.Weight = tokens.Dequeue().DoubleValue;
     201      t.VariableName = tokens.Dequeue().StringValue;
     202      t.SampleOffset = (int)tokens.Dequeue().DoubleValue;
     203      Expect(Token.RPAR, tokens);
     204      return t;
     205    }
     206
     207    private IFunctionTree CreateTree(Token token) {
     208      if (token.Symbol != TokenSymbol.SYMB) throw new FormatException("Expected function symbol, but got: " + token.StringValue);
     209      return knownFunctions[token.StringValue].GetTreeNode();
     210    }
     211
     212    private void Expect(Token token, Queue<Token> tokens) {
     213      Token cur = tokens.Dequeue();
     214      if (!token.Equals(cur)) throw new FormatException("Expected: " + token.StringValue + ", but got found: " + cur.StringValue);
     215    }
     216
     217    private enum TokenSymbol { LPAR, RPAR, SYMB, NUMBER };
     218    private class Token {
     219      public static readonly Token LPAR = Token.Parse("(");
     220      public static readonly Token RPAR = Token.Parse(")");
     221
     222      public TokenSymbol Symbol { get; set; }
     223      public string StringValue { get; set; }
     224      public double DoubleValue { get; set; }
     225      public Token() { }
     226
     227      public override bool Equals(object obj) {
     228        Token other = (obj as Token);
     229        if (other == null) return false;
     230        if (other.Symbol != Symbol) return false;
     231        return other.StringValue == this.StringValue;
     232      }
     233
     234      public static Token Parse(string strToken) {
     235        strToken = strToken.Trim();
     236        Token t = new Token();
     237        t.StringValue = strToken.Trim();
     238        double temp;
     239        if (strToken == "") {
     240          t = null;
     241        } else if (strToken == "(") {
     242          t.Symbol = TokenSymbol.LPAR;
     243        } else if (strToken == ")") {
     244          t.Symbol = TokenSymbol.RPAR;
     245        } else if (double.TryParse(strToken, out temp)) {
     246          t.Symbol = TokenSymbol.NUMBER;
     247          t.DoubleValue = double.Parse(strToken);
     248        } else {
     249          t.Symbol = TokenSymbol.SYMB;
     250        }
     251        return t;
     252      }
     253    }
    101254  }
    102255}
  • trunk/tools/ConfigMerger/ConfigMerger.csproj

    r858 r2260  
    3434    <WarningLevel>4</WarningLevel>
    3535    <DocumentationFile>bin\Release\ConfigMerger.XML</DocumentationFile>
     36  </PropertyGroup>
     37  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     38    <DebugSymbols>true</DebugSymbols>
     39    <OutputPath>bin\x86\Debug\</OutputPath>
     40    <DefineConstants>DEBUG;TRACE</DefineConstants>
     41    <DebugType>full</DebugType>
     42    <PlatformTarget>x86</PlatformTarget>
     43    <ErrorReport>prompt</ErrorReport>
     44  </PropertyGroup>
     45  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     46    <OutputPath>bin\x86\Release\</OutputPath>
     47    <DefineConstants>TRACE</DefineConstants>
     48    <DocumentationFile>bin\Release\ConfigMerger.XML</DocumentationFile>
     49    <Optimize>true</Optimize>
     50    <DebugType>pdbonly</DebugType>
     51    <PlatformTarget>x86</PlatformTarget>
     52    <ErrorReport>prompt</ErrorReport>
    3653  </PropertyGroup>
    3754  <ItemGroup>
  • trunk/tools/Tools.sln

    r2259 r2260  
    1717  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    1818    Debug|Any CPU = Debug|Any CPU
     19    Debug|x86 = Debug|x86
    1920    Release|Any CPU = Release|Any CPU
     21    Release|x86 = Release|x86
    2022  EndGlobalSection
    2123  GlobalSection(ProjectConfigurationPlatforms) = postSolution
    2224    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    2325    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
     26    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Debug|x86.ActiveCfg = Debug|x86
     27    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Debug|x86.Build.0 = Debug|x86
    2428    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
    2529    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Release|Any CPU.Build.0 = Release|Any CPU
     30    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Release|x86.ActiveCfg = Release|Any CPU
     31    {E94C5E71-3F29-408D-BCDF-23E096CA84CA}.Release|x86.Build.0 = Release|Any CPU
    2632    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    2733    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Debug|Any CPU.Build.0 = Debug|Any CPU
     34    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Debug|x86.ActiveCfg = Debug|x86
     35    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Debug|x86.Build.0 = Debug|x86
    2836    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Release|Any CPU.ActiveCfg = Release|Any CPU
    2937    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Release|Any CPU.Build.0 = Release|Any CPU
     38    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Release|x86.ActiveCfg = Release|Any CPU
     39    {1E4B971A-83BA-4C39-BE19-D09B13CF7242}.Release|x86.Build.0 = Release|Any CPU
    3040    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    3141    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
     42    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Debug|x86.ActiveCfg = Debug|x86
     43    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Debug|x86.Build.0 = Debug|x86
    3244    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
    3345    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Release|Any CPU.Build.0 = Release|Any CPU
     46    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Release|x86.ActiveCfg = Release|Any CPU
     47    {F4818BCF-A57F-413C-8DEE-C0532C7F7C7F}.Release|x86.Build.0 = Release|Any CPU
    3448  EndGlobalSection
    3549  GlobalSection(SolutionProperties) = preSolution
  • trunk/tools/Wizards/Wizards.csproj

    r1546 r2260  
    3232    <ErrorReport>prompt</ErrorReport>
    3333    <WarningLevel>4</WarningLevel>
     34  </PropertyGroup>
     35  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     36    <DebugSymbols>true</DebugSymbols>
     37    <OutputPath>bin\x86\Debug\</OutputPath>
     38    <DefineConstants>DEBUG;TRACE</DefineConstants>
     39    <DebugType>full</DebugType>
     40    <PlatformTarget>x86</PlatformTarget>
     41    <ErrorReport>prompt</ErrorReport>
     42  </PropertyGroup>
     43  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     44    <OutputPath>bin\x86\Release\</OutputPath>
     45    <DefineConstants>TRACE</DefineConstants>
     46    <Optimize>true</Optimize>
     47    <DebugType>pdbonly</DebugType>
     48    <PlatformTarget>x86</PlatformTarget>
     49    <ErrorReport>prompt</ErrorReport>
    3450  </PropertyGroup>
    3551  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.