Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16408


Ignore:
Timestamp:
12/19/18 14:56:54 (5 years ago)
Author:
msemenki
Message:

#2942: Add for KNN-Regression/Classification ability to utilize data points with zero distance to the query point. Alteration in the way weights are assigned to neighboring points (to except division-by-zero).

Location:
branches/2942_KNNRegressionClassification
Files:
3 added
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj

    r15783 r16408  
    4343    <DebugType>full</DebugType>
    4444    <Optimize>false</Optimize>
    45     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     45    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    4646    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4747    <ErrorReport>prompt</ErrorReport>
     
    5353    <DebugType>pdbonly</DebugType>
    5454    <Optimize>true</Optimize>
    55     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     55    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    5656    <DefineConstants>TRACE</DefineConstants>
    5757    <ErrorReport>prompt</ErrorReport>
     
    6464  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    6565    <DebugSymbols>true</DebugSymbols>
    66     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     66    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    6767    <DefineConstants>DEBUG;TRACE</DefineConstants>
    6868    <DebugType>full</DebugType>
     
    7373  </PropertyGroup>
    7474  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    75     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     75    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    7676    <DefineConstants>TRACE</DefineConstants>
    7777    <DocumentationFile>
     
    8686  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    8787    <DebugSymbols>true</DebugSymbols>
    88     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     88    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    8989    <DefineConstants>DEBUG;TRACE</DefineConstants>
    9090    <DebugType>full</DebugType>
     
    9595  </PropertyGroup>
    9696  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    97     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     97    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    9898    <DefineConstants>TRACE</DefineConstants>
    9999    <DocumentationFile>
     
    109109    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    110110      <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath>
     111      <Private>False</Private>
     112    </Reference>
     113    <Reference Include="HeuristicLab.Algorithms.GradientDescent-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     114      <SpecificVersion>False</SpecificVersion>
     115      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Algorithms.GradientDescent-3.3.dll</HintPath>
     116      <Private>False</Private>
     117    </Reference>
     118    <Reference Include="HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     119      <SpecificVersion>False</SpecificVersion>
     120      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.dll</HintPath>
     121      <Private>False</Private>
     122    </Reference>
     123    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     124      <SpecificVersion>False</SpecificVersion>
     125      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     126      <Private>False</Private>
     127    </Reference>
     128    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     129      <SpecificVersion>False</SpecificVersion>
     130      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     131      <Private>False</Private>
     132    </Reference>
     133    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     134      <SpecificVersion>False</SpecificVersion>
     135      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Common-3.3.dll</HintPath>
     136      <Private>False</Private>
     137    </Reference>
     138    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     139      <SpecificVersion>False</SpecificVersion>
     140      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
     141      <Private>False</Private>
     142    </Reference>
     143    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     144      <SpecificVersion>False</SpecificVersion>
     145      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath>
     146      <Private>False</Private>
     147    </Reference>
     148    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     149      <SpecificVersion>False</SpecificVersion>
     150      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath>
     151      <Private>False</Private>
     152    </Reference>
     153    <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     154      <SpecificVersion>False</SpecificVersion>
     155      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Encodings.RealVectorEncoding-3.3.dll</HintPath>
     156      <Private>False</Private>
     157    </Reference>
     158    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     159      <SpecificVersion>False</SpecificVersion>
     160      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
     161      <Private>False</Private>
     162    </Reference>
     163    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     164      <SpecificVersion>False</SpecificVersion>
     165      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     166      <Private>False</Private>
     167    </Reference>
     168    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     169      <SpecificVersion>False</SpecificVersion>
     170      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
     171      <Private>False</Private>
     172    </Reference>
     173    <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     174      <SpecificVersion>False</SpecificVersion>
     175      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
     176      <Private>False</Private>
     177    </Reference>
     178    <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     179      <SpecificVersion>False</SpecificVersion>
     180      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     181      <Private>False</Private>
     182    </Reference>
     183    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     184      <SpecificVersion>False</SpecificVersion>
     185      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     186      <Private>False</Private>
     187    </Reference>
     188    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     189      <SpecificVersion>False</SpecificVersion>
     190      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
     191    </Reference>
     192    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     193      <SpecificVersion>False</SpecificVersion>
     194      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath>
     195      <Private>False</Private>
     196    </Reference>
     197    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     198      <SpecificVersion>False</SpecificVersion>
     199      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.dll</HintPath>
     200      <Private>False</Private>
     201    </Reference>
     202    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     203      <SpecificVersion>False</SpecificVersion>
     204      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll</HintPath>
     205      <Private>False</Private>
     206    </Reference>
     207    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     208      <SpecificVersion>False</SpecificVersion>
     209      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.dll</HintPath>
     210      <Private>False</Private>
     211    </Reference>
     212    <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     213      <SpecificVersion>False</SpecificVersion>
     214      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
     215      <Private>False</Private>
     216    </Reference>
     217    <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     218      <SpecificVersion>False</SpecificVersion>
     219      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Random-3.3.dll</HintPath>
     220      <Private>False</Private>
     221    </Reference>
     222    <Reference Include="HeuristicLab.Selection-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     223      <SpecificVersion>False</SpecificVersion>
     224      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Selection-3.3.dll</HintPath>
    111225      <Private>False</Private>
    112226    </Reference>
     
    331445  </ItemGroup>
    332446  <ItemGroup>
    333     <ProjectReference Include="..\..\HeuristicLab.Algorithms.GradientDescent\3.3\HeuristicLab.Algorithms.GradientDescent-3.3.csproj">
    334       <Project>{1256B945-EEA9-4BE4-9880-76B5B113F089}</Project>
    335       <Name>HeuristicLab.Algorithms.GradientDescent-3.3</Name>
    336       <Private>False</Private>
    337     </ProjectReference>
    338     <ProjectReference Include="..\..\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm\3.3\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.csproj">
    339       <Project>{F409DD9E-1E9C-4EB1-AA3A-9F6E987C6E58}</Project>
    340       <Name>HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3</Name>
    341     </ProjectReference>
    342     <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
    343       <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
    344       <Name>HeuristicLab.Analysis-3.3</Name>
    345       <Private>False</Private>
    346     </ProjectReference>
    347     <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    348       <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    349       <Name>HeuristicLab.Collections-3.3</Name>
    350       <Private>False</Private>
    351     </ProjectReference>
    352     <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
    353       <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
    354       <Name>HeuristicLab.Common.Resources-3.3</Name>
    355       <Private>False</Private>
    356     </ProjectReference>
    357     <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    358       <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
    359       <Name>HeuristicLab.Common-3.3</Name>
    360       <Private>False</Private>
    361     </ProjectReference>
    362     <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    363       <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
    364       <Name>HeuristicLab.Core-3.3</Name>
    365       <Private>False</Private>
    366     </ProjectReference>
    367     <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
    368       <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
    369       <Name>HeuristicLab.Data-3.3</Name>
    370       <Private>False</Private>
    371     </ProjectReference>
    372     <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj">
    373       <Project>{BB6D334A-4BB6-4674-9883-31A6EBB32CAB}</Project>
    374       <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name>
    375       <Private>False</Private>
    376     </ProjectReference>
    377     <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
    378       <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
    379       <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
    380       <Private>False</Private>
    381     </ProjectReference>
    382     <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
    383       <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
    384       <Name>HeuristicLab.Operators-3.3</Name>
    385       <Private>False</Private>
    386     </ProjectReference>
    387     <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    388       <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
    389       <Name>HeuristicLab.Optimization-3.3</Name>
    390       <Private>False</Private>
    391     </ProjectReference>
    392     <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
    393       <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
    394       <Name>HeuristicLab.Parameters-3.3</Name>
    395       <Private>False</Private>
    396     </ProjectReference>
    397     <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
    398       <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
    399       <Name>HeuristicLab.Persistence-3.3</Name>
    400       <Private>False</Private>
    401     </ProjectReference>
    402     <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    403       <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    404       <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    405       <Private>False</Private>
    406     </ProjectReference>
    407     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj">
    408       <Project>{05BAE4E1-A9FA-4644-AA77-42558720159E}</Project>
    409       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4</Name>
    410       <Private>False</Private>
    411     </ProjectReference>
    412     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj">
    413       <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project>
    414       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name>
    415       <Private>False</Private>
    416     </ProjectReference>
    417     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj">
    418       <Project>{07486E68-1517-4B9D-A58D-A38E99AE71AB}</Project>
    419       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4</Name>
    420     </ProjectReference>
    421     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
    422       <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
    423       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
    424       <Private>False</Private>
    425     </ProjectReference>
    426     <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
    427       <Project>{DF87C13E-A889-46FF-8153-66DCAA8C5674}</Project>
    428       <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name>
    429       <Private>False</Private>
    430     </ProjectReference>
    431     <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">
    432       <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
    433       <Name>HeuristicLab.Problems.Instances-3.3</Name>
    434       <Private>False</Private>
    435     </ProjectReference>
    436     <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
    437       <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
    438       <Name>HeuristicLab.Random-3.3</Name>
    439       <Private>False</Private>
    440     </ProjectReference>
    441     <ProjectReference Include="..\..\HeuristicLab.Selection\3.3\HeuristicLab.Selection-3.3.csproj">
    442       <Project>{2C36CD4F-E5F5-43A4-801A-201EA895FE17}</Project>
    443       <Name>HeuristicLab.Selection-3.3</Name>
    444     </ProjectReference>
    445   </ItemGroup>
    446   <ItemGroup>
    447447    <None Include="HeuristicLab.snk" />
    448448    <None Include="Plugin.cs.frame" />
  • branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs

    r15869 r16408  
    6565
    6666      var ds = ReduceDataset(dataset, rows);
    67       nnModel = new NearestNeighbourModel(ds, Enumerable.Range(0, ds.Rows), k, ds.VariableNames.Last(), ds.VariableNames.Take(transformationMatrix.GetLength(1)), classValues: classValues);
     67      nnModel = new NearestNeighbourModel(ds, Enumerable.Range(0, ds.Rows), k, false,  ds.VariableNames.Last(), ds.VariableNames.Take(transformationMatrix.GetLength(1)), classValues: classValues);
    6868    }
    6969
  • branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs

    r15583 r16408  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    33 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    4242    private const string NearestNeighbourClassificationModelResultName = "Nearest neighbour classification solution";
    4343    private const string WeightsParameterName = "Weights";
    44 
     44    private const string SelfMatchParameterName = "SelfMatch";
    4545
    4646    #region parameter properties
    4747    public IFixedValueParameter<IntValue> KParameter {
    4848      get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; }
     49    }
     50    public IFixedValueParameter<BoolValue> SelfMatchParameter {
     51      get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; }
    4952    }
    5053    public IValueParameter<DoubleArray> WeightsParameter {
     
    5356    #endregion
    5457    #region properties
     58    public bool SelfMatch {
     59      get { return SelfMatchParameter.Value.Value; }
     60      set { SelfMatchParameter.Value.Value = value; }
     61    }
    5562    public int K {
    5663      get { return KParameter.Value.Value; }
     
    7380    public NearestNeighbourClassification()
    7481      : base() {
     82      Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false)));
    7583      Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3)));
    7684      Parameters.Add(new OptionalValueParameter<DoubleArray>(WeightsParameterName, "Optional: use weights to specify individual scaling values for all features. If not set the weights are calculated automatically (each feature is scaled to unit variance)"));
     
    95103      double[] weights = null;
    96104      if (Weights != null) weights = Weights.CloneAsArray();
    97       var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, weights);
     105      var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, SelfMatch, weights);
    98106      Results.Add(new Result(NearestNeighbourClassificationModelResultName, "The nearest neighbour classification solution.", solution));
    99107    }
    100108
    101     public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k, double[] weights = null) {
     109    public static IClassificationSolution CreateNearestNeighbourClassificationSolution(IClassificationProblemData problemData, int k, bool selfMatch = false, double[] weights = null) {
    102110      var problemDataClone = (IClassificationProblemData)problemData.Clone();
    103       return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, weights), problemDataClone);
     111      return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, selfMatch, weights), problemDataClone);
    104112    }
    105113
    106     public static INearestNeighbourModel Train(IClassificationProblemData problemData, int k, double[] weights = null) {
     114    public static INearestNeighbourModel Train(IClassificationProblemData problemData, int k, bool selfMatch = false, double[] weights = null) {
    107115      return new NearestNeighbourModel(problemData.Dataset,
    108116        problemData.TrainingIndices,
    109117        k,
     118        selfMatch,
    110119        problemData.TargetVariable,
    111120        problemData.AllowedInputVariables,
  • branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs

    r16243 r16408  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    33 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    3737
    3838    private readonly object kdTreeLockObject = new object();
     39
    3940    private alglib.nearestneighbor.kdtree kdTree;
    4041    public alglib.nearestneighbor.kdtree KDTree {
     
    6061    [Storable]
    6162    private int k;
     63    [Storable]
     64    private bool selfMatch;
    6265    [Storable(DefaultValue = null)]
    6366    private double[] weights; // not set for old versions loaded from disk
     
    97100      kdTree.x = (double[])original.kdTree.x.Clone();
    98101      kdTree.xy = (double[,])original.kdTree.xy.Clone();
    99 
     102      selfMatch = original.selfMatch;
    100103      k = original.k;
    101104      isCompatibilityLoaded = original.IsCompatibilityLoaded;
     
    110113        this.classValues = (double[])original.classValues.Clone();
    111114    }
    112     public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, string targetVariable, IEnumerable<string> allowedInputVariables, IEnumerable<double> weights = null, double[] classValues = null)
     115    public NearestNeighbourModel(IDataset dataset, IEnumerable<int> rows, int k, bool selfMatch, string targetVariable, IEnumerable<string> allowedInputVariables, IEnumerable<double> weights = null, double[] classValues = null)
    113116      : base(targetVariable) {
    114117      Name = ItemName;
    115118      Description = ItemDescription;
     119      this.selfMatch = selfMatch;
    116120      this.k = k;
    117121      this.allowedInputVariables = allowedInputVariables.ToArray();
     
    132136            .Select(name => {
    133137              var pop = dataset.GetDoubleValues(name, rows).StandardDeviationPop();
    134               return  pop.IsAlmost(0) ? 1.0 : 1.0/pop;
     138              return pop.IsAlmost(0) ? 1.0 : 1.0 / pop;
    135139            })
    136140            .Concat(new double[] { 1.0 }) // no scaling for target variable
     
    201205        int numNeighbours;
    202206        lock (kdTreeLockObject) { // gkronber: the following calls change the kdTree data structure
    203           numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false);
     207          numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, selfMatch);
    204208          alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists);
    205209          alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours);
    206210        }
    207 
     211        if (selfMatch) {
     212          double minDist = dists[0] + 1;
     213          for (int i = 0; i < numNeighbours; i++) {
     214            if ((minDist > dists[i]) && (dists[i] != 0)) {
     215              minDist = dists[i];
     216            }
     217          }
     218          minDist /= 100.0;
     219          for (int i = 0; i < numNeighbours; i++) {
     220            if (dists[i] == 0) {
     221              dists[i] = minDist;
     222            }
     223          }
     224        }
    208225        double distanceWeightedValue = 0.0;
    209226        double distsSum = 0.0;
     
    238255        lock (kdTreeLockObject) {
    239256          // gkronber: the following calls change the kdTree data structure
    240           numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, false);
     257          numNeighbours = alglib.nearestneighbor.kdtreequeryknn(kdTree, x, k, selfMatch);
    241258          alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists);
    242259          alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours);
  • branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs

    r15583 r16408  
    4141    private const string NearestNeighbourRegressionModelResultName = "Nearest neighbour regression solution";
    4242    private const string WeightsParameterName = "Weights";
     43    private const string SelfMatchParameterName = "SelfMatch";
    4344
    4445    #region parameter properties
     
    4647      get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; }
    4748    }
    48 
     49    public IFixedValueParameter<BoolValue> SelfMatchParameter {
     50      get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; }
     51    }
    4952    public IValueParameter<DoubleArray> WeightsParameter {
    5053      get { return (IValueParameter<DoubleArray>)Parameters[WeightsParameterName]; }
     
    5962      }
    6063    }
    61 
     64    public bool SelfMatch {
     65      get { return SelfMatchParameter.Value.Value; }
     66      set { SelfMatchParameter.Value.Value = value; }
     67    }
    6268    public DoubleArray Weights {
    6369      get { return WeightsParameter.Value; }
     
    7581      Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3)));
    7682      Parameters.Add(new OptionalValueParameter<DoubleArray>(WeightsParameterName, "Optional: use weights to specify individual scaling values for all features. If not set the weights are calculated automatically (each feature is scaled to unit variance)"));
     83      Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false)));
    7784      Problem = new RegressionProblem();
    7885    }
     
    96103      double[] weights = null;
    97104      if (Weights != null) weights = Weights.CloneAsArray();
    98       var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, weights);
     105      var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, SelfMatch, weights);
    99106      Results.Add(new Result(NearestNeighbourRegressionModelResultName, "The nearest neighbour regression solution.", solution));
    100107    }
    101108
    102     public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k, double[] weights = null) {
     109    public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k, bool selfMatch = false, double[] weights = null) {
    103110      var clonedProblemData = (IRegressionProblemData)problemData.Clone();
    104       return new NearestNeighbourRegressionSolution(Train(problemData, k, weights), clonedProblemData);
     111      return new NearestNeighbourRegressionSolution(Train(problemData, k, selfMatch, weights), clonedProblemData);
    105112    }
    106113
    107     public static INearestNeighbourModel Train(IRegressionProblemData problemData, int k, double[] weights = null) {
     114    public static INearestNeighbourModel Train(IRegressionProblemData problemData, int k, bool selfMatch = false, double[] weights = null) {
    108115      return new NearestNeighbourModel(problemData.Dataset,
    109116        problemData.TrainingIndices,
    110117        k,
     118        selfMatch,
    111119        problemData.TargetVariable,
    112120        problemData.AllowedInputVariables,
Note: See TracChangeset for help on using the changeset viewer.