|
|
# Neighborhood Components Analysis (NCA)
|
|
|
|
|
|
An implementation of neighborhood components analysis, a distance learning technique that can be used for preprocessing. Given a labeled dataset, this uses NCA, which seeks to improve the k-nearest-neighbor classification, and returns the learned distance metric
|
|
|
An implementation of neighborhood components analysis, a distance learning technique that can be used for preprocessing. Given a labeled dataset, this uses NCA, which seeks to improve the k-nearest-neighbor classification, and returns the learned distance metric.
|
|
|
|
|
|
```prolog
|
|
|
:- use_module('path/to/.../src/methods/nca/nca.pl').
|
|
|
|
|
|
%% usage example
|
|
|
TrainData = [5.1,3.5,1.4, 4.9,3.0,1.4, 4.7,3.2,1.3, 4.6,3.1,1.5],
|
|
|
nca(sgd, 0.01, 500000, 0.00001, 1, 5, 0.0001, 0.9, 50, 0.000000001, 100000000, 50, TrainData, 3, [0,1,0,1], DistancesList, _).
|
|
|
```
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
* [nca/20](/PrologMethods/Transformation/nca#nca20)
|
|
|
* [nca/17](/PrologMethods/Transformation/nca#nca17)
|
|
|
|
|
|
---
|
|
|
|
|
|
[links/resources](/PrologMethods/Transformation/nca#connected-linksresources)
|
|
|
|
|
|
## **_nca/20_**
|
|
|
## **_nca/17_**
|
|
|
|
|
|
Initialize the nca model and the selected optimizer.
|
|
|
|
|
|
Then perform nca on the given data and return the learned distance.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
nca( +string,
|
|
|
%% predicate definition
|
|
|
nca(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStep, BatchSize,
|
|
|
DataList, DataRows, PredictionList, DistanceList, ZCols) :-
|
|
|
StepSize > 0,
|
|
|
MaxIterations >= 0,
|
|
|
Tolerance >= 0,
|
|
|
NumBasis > 0,
|
|
|
ArmijoConstant > 0,
|
|
|
Wolfe > 0,
|
|
|
MaxLine > 0,
|
|
|
MinStep > 0,
|
|
|
MaxStep > 0,
|
|
|
MaxStep >= MinStep,
|
|
|
BatchSize > 0,
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
convert_list_to_float_array(PredictionList, array(Ysize, Y)),
|
|
|
ncaI(OptimizerType, StepSize, MaxIterations, Tolerance, Shuffle, NumBasis, ArmijoConstant, Wolfe, MaxLine, MinStep, MaxStep, BatchSize,
|
|
|
X, Xsize, Xrows, Y, Ysize, Z, ZCols, ZRows),
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, DistanceList).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(nca, c, ncaI( +string,
|
|
|
+float32, +integer, +float32,
|
|
|
+integer,
|
|
|
+integer, +float32, +float32, +integer, +float32, +float32, +integer,
|
|
|
+pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
-pointer(float_array), -integer, -integer)
|
|
|
-pointer(float_array), -integer, -integer)).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
... | ... | @@ -52,8 +80,8 @@ nca( +string, |
|
|
|
|
|
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
|
|
|
|
|
|
* [**MLpack::nca_C++\_documentation**](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1nca_1_1NCA.html)
|
|
|
* [**MLpack::nca_Python_documentation**](https://www.mlpack.org/doc/stable/python_documentation.html#nca)
|
|
|
* [**MLpack::nca_C++\_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/classmlpack_1_1nca_1_1NCA.html)
|
|
|
* [**MLpack::nca_Python_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/python_documentation.html#nca)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
... | ... | |