Changeset 16408
- Timestamp:
- 12/19/18 14:56:54 (6 years ago)
- 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 43 43 <DebugType>full</DebugType> 44 44 <Optimize>false</Optimize> 45 <OutputPath> $(SolutionDir)\bin\</OutputPath>45 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 46 46 <DefineConstants>DEBUG;TRACE</DefineConstants> 47 47 <ErrorReport>prompt</ErrorReport> … … 53 53 <DebugType>pdbonly</DebugType> 54 54 <Optimize>true</Optimize> 55 <OutputPath> $(SolutionDir)\bin\</OutputPath>55 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 56 56 <DefineConstants>TRACE</DefineConstants> 57 57 <ErrorReport>prompt</ErrorReport> … … 64 64 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 65 65 <DebugSymbols>true</DebugSymbols> 66 <OutputPath> $(SolutionDir)\bin\</OutputPath>66 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 67 67 <DefineConstants>DEBUG;TRACE</DefineConstants> 68 68 <DebugType>full</DebugType> … … 73 73 </PropertyGroup> 74 74 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 75 <OutputPath> $(SolutionDir)\bin\</OutputPath>75 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 76 76 <DefineConstants>TRACE</DefineConstants> 77 77 <DocumentationFile> … … 86 86 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> 87 87 <DebugSymbols>true</DebugSymbols> 88 <OutputPath> $(SolutionDir)\bin\</OutputPath>88 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 89 89 <DefineConstants>DEBUG;TRACE</DefineConstants> 90 90 <DebugType>full</DebugType> … … 95 95 </PropertyGroup> 96 96 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 97 <OutputPath> $(SolutionDir)\bin\</OutputPath>97 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 98 98 <DefineConstants>TRACE</DefineConstants> 99 99 <DocumentationFile> … … 109 109 <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 110 110 <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> 111 225 <Private>False</Private> 112 226 </Reference> … … 331 445 </ItemGroup> 332 446 <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>447 447 <None Include="HeuristicLab.snk" /> 448 448 <None Include="Plugin.cs.frame" /> -
branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/NcaModel.cs
r15869 r16408 65 65 66 66 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); 68 68 } 69 69 -
branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
r15583 r16408 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 42 42 private const string NearestNeighbourClassificationModelResultName = "Nearest neighbour classification solution"; 43 43 private const string WeightsParameterName = "Weights"; 44 44 private const string SelfMatchParameterName = "SelfMatch"; 45 45 46 46 #region parameter properties 47 47 public IFixedValueParameter<IntValue> KParameter { 48 48 get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; } 49 } 50 public IFixedValueParameter<BoolValue> SelfMatchParameter { 51 get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; } 49 52 } 50 53 public IValueParameter<DoubleArray> WeightsParameter { … … 53 56 #endregion 54 57 #region properties 58 public bool SelfMatch { 59 get { return SelfMatchParameter.Value.Value; } 60 set { SelfMatchParameter.Value.Value = value; } 61 } 55 62 public int K { 56 63 get { return KParameter.Value.Value; } … … 73 80 public NearestNeighbourClassification() 74 81 : base() { 82 Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false))); 75 83 Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3))); 76 84 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)")); … … 95 103 double[] weights = null; 96 104 if (Weights != null) weights = Weights.CloneAsArray(); 97 var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, weights);105 var solution = CreateNearestNeighbourClassificationSolution(Problem.ProblemData, K, SelfMatch, weights); 98 106 Results.Add(new Result(NearestNeighbourClassificationModelResultName, "The nearest neighbour classification solution.", solution)); 99 107 } 100 108 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) { 102 110 var problemDataClone = (IClassificationProblemData)problemData.Clone(); 103 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, weights), problemDataClone);111 return new NearestNeighbourClassificationSolution(Train(problemDataClone, k, selfMatch, weights), problemDataClone); 104 112 } 105 113 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) { 107 115 return new NearestNeighbourModel(problemData.Dataset, 108 116 problemData.TrainingIndices, 109 117 k, 118 selfMatch, 110 119 problemData.TargetVariable, 111 120 problemData.AllowedInputVariables, -
branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r16243 r16408 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 37 37 38 38 private readonly object kdTreeLockObject = new object(); 39 39 40 private alglib.nearestneighbor.kdtree kdTree; 40 41 public alglib.nearestneighbor.kdtree KDTree { … … 60 61 [Storable] 61 62 private int k; 63 [Storable] 64 private bool selfMatch; 62 65 [Storable(DefaultValue = null)] 63 66 private double[] weights; // not set for old versions loaded from disk … … 97 100 kdTree.x = (double[])original.kdTree.x.Clone(); 98 101 kdTree.xy = (double[,])original.kdTree.xy.Clone(); 99 102 selfMatch = original.selfMatch; 100 103 k = original.k; 101 104 isCompatibilityLoaded = original.IsCompatibilityLoaded; … … 110 113 this.classValues = (double[])original.classValues.Clone(); 111 114 } 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) 113 116 : base(targetVariable) { 114 117 Name = ItemName; 115 118 Description = ItemDescription; 119 this.selfMatch = selfMatch; 116 120 this.k = k; 117 121 this.allowedInputVariables = allowedInputVariables.ToArray(); … … 132 136 .Select(name => { 133 137 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; 135 139 }) 136 140 .Concat(new double[] { 1.0 }) // no scaling for target variable … … 201 205 int numNeighbours; 202 206 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); 204 208 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 205 209 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); 206 210 } 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 } 208 225 double distanceWeightedValue = 0.0; 209 226 double distsSum = 0.0; … … 238 255 lock (kdTreeLockObject) { 239 256 // 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); 241 258 alglib.nearestneighbor.kdtreequeryresultsdistances(kdTree, ref dists); 242 259 alglib.nearestneighbor.kdtreequeryresultsxy(kdTree, ref neighbours); -
branches/2942_KNNRegressionClassification/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
r15583 r16408 41 41 private const string NearestNeighbourRegressionModelResultName = "Nearest neighbour regression solution"; 42 42 private const string WeightsParameterName = "Weights"; 43 private const string SelfMatchParameterName = "SelfMatch"; 43 44 44 45 #region parameter properties … … 46 47 get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; } 47 48 } 48 49 public IFixedValueParameter<BoolValue> SelfMatchParameter { 50 get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; } 51 } 49 52 public IValueParameter<DoubleArray> WeightsParameter { 50 53 get { return (IValueParameter<DoubleArray>)Parameters[WeightsParameterName]; } … … 59 62 } 60 63 } 61 64 public bool SelfMatch { 65 get { return SelfMatchParameter.Value.Value; } 66 set { SelfMatchParameter.Value.Value = value; } 67 } 62 68 public DoubleArray Weights { 63 69 get { return WeightsParameter.Value; } … … 75 81 Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3))); 76 82 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))); 77 84 Problem = new RegressionProblem(); 78 85 } … … 96 103 double[] weights = null; 97 104 if (Weights != null) weights = Weights.CloneAsArray(); 98 var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, weights);105 var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, SelfMatch, weights); 99 106 Results.Add(new Result(NearestNeighbourRegressionModelResultName, "The nearest neighbour regression solution.", solution)); 100 107 } 101 108 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) { 103 110 var clonedProblemData = (IRegressionProblemData)problemData.Clone(); 104 return new NearestNeighbourRegressionSolution(Train(problemData, k, weights), clonedProblemData);111 return new NearestNeighbourRegressionSolution(Train(problemData, k, selfMatch, weights), clonedProblemData); 105 112 } 106 113 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) { 108 115 return new NearestNeighbourModel(problemData.Dataset, 109 116 problemData.TrainingIndices, 110 117 k, 118 selfMatch, 111 119 problemData.TargetVariable, 112 120 problemData.AllowedInputVariables,
Note: See TracChangeset
for help on using the changeset viewer.