Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9293


Ignore:
Timestamp:
03/07/13 14:53:43 (11 years ago)
Author:
bburlacu
Message:

#1772: Added new similarity measures and moved them to separate class SymbolicDataAnalysisExpressionTreeSimilarity.cs.

Location:
branches/HeuristicLab.EvolutionaryTracking
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj

    r9246 r9293  
    5151    <DebugType>pdbonly</DebugType>
    5252    <Optimize>true</Optimize>
    53     <OutputPath>..\..\..\..\Trunk\sources\bin\</OutputPath>
     53    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    5454    <DefineConstants>TRACE</DefineConstants>
    5555    <ErrorReport>prompt</ErrorReport>
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Plugin.cs

    r9246 r9293  
    2323
    2424namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    25   [Plugin("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","Provides operators and related classes for the symbolic expression tree encoding.", "3.4.3.9237")]
     25  [Plugin("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","Provides operators and related classes for the symbolic expression tree encoding.", "3.4.3.9246")]
    2626  [PluginFile("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Analysis", "3.3")]
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r9241 r9293  
    5050    <DebugType>pdbonly</DebugType>
    5151    <Optimize>true</Optimize>
    52     <OutputPath>..\..\..\..\Trunk\sources\bin\</OutputPath>
     52    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    5353    <DefineConstants>TRACE</DefineConstants>
    5454    <ErrorReport>prompt</ErrorReport>
     
    6666  </PropertyGroup>
    6767  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    68     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     68    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    6969    <DefineConstants>TRACE</DefineConstants>
    7070    <Optimize>true</Optimize>
     
    8484  </PropertyGroup>
    8585  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    86     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     86    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    8787    <DefineConstants>TRACE</DefineConstants>
    8888    <Optimize>true</Optimize>
     
    200200    <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" />
    201201    <Compile Include="SymbolicDataAnalysisExpressionTreeMatching.cs" />
     202    <Compile Include="SymbolicDataAnalysisExpressionTreeSimilarity.cs" />
    202203    <Compile Include="SymbolicDataAnalysisModel.cs">
    203204      <SubType>Code</SubType>
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeMatching.cs

    r9249 r9293  
    161161
    162162public static class SymbolicExpressionTreeMatching {
    163   public static bool IsSimilarTo(this ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
    164     return t1.Root.IsSimilarTo(t2.Root, comparer);
    165   }
    166   public static bool IsSimilarTo(this ISymbolicExpressionTreeNode t1, ISymbolicExpressionTreeNode t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
    167     return Match(t1, t2, comparer) == Math.Min(t1.GetLength(), t2.GetLength());
    168   }
    169163  public static bool ContainsFragment(this ISymbolicExpressionTreeNode root, IFragment fragment, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
    170164    return FindMatches(root, fragment.Root, comparer).Any();
     
    179173    // below, we use ">=" for Match(n, fragment, comp) >= fragmentLength because in case of relaxed conditions,
    180174    // we can have multiple matches of the same node
     175
    181176    return root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, fragment, comp) == fragmentLength);
    182177  }
     
    206201  }
    207202}
     203
     204public class MaximalCommonSubsequenceCalculator {
     205  private ISymbolicExpressionTreeNode[] x;
     206  private ISymbolicExpressionTreeNode[] y;
     207  private List<ISymbolicExpressionTreeNode> maxCommonSubseq;
     208  private double[,] matrix;
     209
     210  public SymbolicExpressionTreeNodeSimilarityComparer comparer;
     211
     212  public List<ISymbolicExpressionTreeNode> Calculate(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
     213    if (comparer == null) throw new Exception("Comparer cannot be null.");
     214
     215    x = n1.IterateNodesPrefix().ToArray();
     216    y = n2.IterateNodesPrefix().ToArray();
     217
     218    if (maxCommonSubseq == null) maxCommonSubseq = new List<ISymbolicExpressionTreeNode>();
     219    else maxCommonSubseq.Clear();
     220
     221    int n = x.Length;
     222    int m = y.Length;
     223
     224    matrix = new double[n + 1, m + 1];
     225
     226    for (int i = 0; i <= n; ++i) {
     227      for (int j = 0; j <= m; ++j) {
     228        if (i == 0 || j == 0) {
     229          matrix[i, j] = 0;
     230        } else if (comparer.Equals(x[i - 1], y[j - 1])) {
     231          matrix[i, j] = matrix[i - 1, j - 1] + 1;
     232        } else {
     233          matrix[i, j] = Math.Max(matrix[i - 1, j], matrix[i, j - 1]);
     234        }
     235      }
     236    }
     237    recon(n, m);
     238    return new List<ISymbolicExpressionTreeNode>(maxCommonSubseq);
     239  }
     240
     241  private void recon(int i, int j) {
     242    if (i == 0 || j == 0) return;
     243    if (comparer.Equals(x[i - 1], y[j - 1])) {
     244      recon(i - 1, j - 1);
     245      maxCommonSubseq.Add(x[i - 1]);
     246    } else if (matrix[i - 1, j] > matrix[i, j - 1]) {
     247      recon(i - 1, j);
     248    } else recon(i, j - 1);
     249  }
     250}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Tracking.sln

    r8557 r9293  
    11
    2 Microsoft Visual Studio Solution File, Format Version 11.00
    3 # Visual Studio 2010
     2Microsoft Visual Studio Solution File, Format Version 12.00
     3# Visual Studio 2012
    44Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4", "HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj", "{06D4A186-9319-48A0-BADE-A2058D462EEA}"
    55EndProject
     
    2020EndProject
    2121Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Symbolic-3.4", "HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj", "{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}"
     22EndProject
     23Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Optimization.Views-3.3", "HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj", "{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}"
    2224EndProject
    2325Global
     
    7880    {1F75CEA3-464F-4A6F-B2F0-04B9841EBC16}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
    7981    {1F75CEA3-464F-4A6F-B2F0-04B9841EBC16}.Release|Mixed Platforms.Build.0 = Release|Any CPU
    80     {1F75CEA3-464F-4A6F-B2F0-04B9841EBC16}.Release|x64.ActiveCfg = Release|Any CPU
     82    {1F75CEA3-464F-4A6F-B2F0-04B9841EBC16}.Release|x64.ActiveCfg = Release|x64
     83    {1F75CEA3-464F-4A6F-B2F0-04B9841EBC16}.Release|x64.Build.0 = Release|x64
    8184    {1F75CEA3-464F-4A6F-B2F0-04B9841EBC16}.Release|x86.ActiveCfg = Release|Any CPU
    8285    {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     
    9093    {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
    9194    {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Release|Mixed Platforms.Build.0 = Release|Any CPU
    92     {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Release|x64.ActiveCfg = Release|Any CPU
     95    {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Release|x64.ActiveCfg = Release|x64
     96    {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Release|x64.Build.0 = Release|x64
    9397    {318DFE8C-CA23-4F1B-A4AC-62B425060241}.Release|x86.ActiveCfg = Release|Any CPU
    9498    {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     
    108112    {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|x86.ActiveCfg = Release|x86
    109113    {3D28463F-EC96-4D82-AFEE-38BE91A0CA00}.Release|x86.Build.0 = Release|x86
     114    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     115    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
     116    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
     117    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|Mixed Platforms.Build.0 = Debug|x86
     118    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|x64.ActiveCfg = Debug|x64
     119    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|x64.Build.0 = Debug|x64
     120    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|x86.ActiveCfg = Debug|x86
     121    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Debug|x86.Build.0 = Debug|x86
     122    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
     123    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|Any CPU.Build.0 = Release|Any CPU
     124    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|Mixed Platforms.ActiveCfg = Release|x86
     125    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|Mixed Platforms.Build.0 = Release|x86
     126    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|x64.ActiveCfg = Release|x64
     127    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|x64.Build.0 = Release|x64
     128    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|x86.ActiveCfg = Release|x86
     129    {662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}.Release|x86.Build.0 = Release|x86
    110130  EndGlobalSection
    111131  GlobalSection(SolutionProperties) = preSolution
    112132    HideSolutionNode = FALSE
    113133  EndGlobalSection
     134  GlobalSection(Performance) = preSolution
     135    HasPerformanceSessions = true
     136  EndGlobalSection
    114137EndGlobal
Note: See TracChangeset for help on using the changeset viewer.