... | ... | @@ -2,31 +2,56 @@ |
|
|
|
|
|
An implementation of Large Margin Nearest Neighbors (LMNN), a distance learning technique. Given a labeled dataset, this learns a transformation of the data that improves k-nearest-neighbor performance. This can be useful as a preprocessing step.
|
|
|
|
|
|
```prolog
|
|
|
:- use_module('path/to/.../src/methods/adaboost/adaboost.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],
|
|
|
lmnn(amsgrad, TrainData, 3, [0,1,0,1], 1, 0.5, 0.01, 50, 100000, 0.000001, 0, 0, 50, 1, 0, DistanceList, _).
|
|
|
```
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
* [lmnn/20](/PrologMethods/Transformation/lmnn#lmnn20)
|
|
|
* [lmnn/17](/PrologMethods/Transformation/lmnn#lmnn17)
|
|
|
|
|
|
---
|
|
|
|
|
|
[links/resources](/PrologMethods/Transformation/lmnn#connected-linksresources)
|
|
|
|
|
|
## **_lmnn/20_**
|
|
|
## **_lmnn/17_**
|
|
|
|
|
|
Is a single predicate that initiates the lmnn model with all the given params and then performs Large Margin Nearest Neighbors metric learning on the reference data.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
lmnn( +string,
|
|
|
%% predicate definition
|
|
|
lmnn(Optimizer, DataList, DataRows, LabelsList, K, Regularization, StepSize, Passes, MaxIterations, Tolerance, Center, Shuffle, BatchSize, Range, Rank, DistanceList, ZCols) :-
|
|
|
K > 0,
|
|
|
Regularization >= 0.0,
|
|
|
StepSize >= 0.0,
|
|
|
Passes >= 0,
|
|
|
MaxIterations >= 0,
|
|
|
Tolerance >= 0.0,
|
|
|
BatchSize > 0,
|
|
|
Range > 0,
|
|
|
Rank >= 0,
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
|
|
|
convert_list_to_float_array(LabelsList, array(Ysize, Y)),
|
|
|
lmnnI(Optimizer, X, Xsize, Xrownum, Y, Ysize, K, Regularization, StepSize, Passes, MaxIterations, Tolerance, Center, Shuffle, BatchSize, Range, Rank, Z, ZCols, ZRows),
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, DistanceList).
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
foreign(lmnn, c, lmnnI( +string,
|
|
|
+pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
+float32, +float32, +integer, +integer, +float32,
|
|
|
+integer, +integer,
|
|
|
+integer, +integer, +integer,
|
|
|
-pointer(float_array), -integer, -integer)
|
|
|
-pointer(float_array), -integer, -integer)).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| optimizer | +string | Optimizer to use; "amsgrad", "bbsgd", "sgd", or "lbfgs". | amsgrad |
|
... | ... | @@ -51,8 +76,8 @@ lmnn( +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::lmnn_C++\_documentation**](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1lmnn_1_1LMNN.html)
|
|
|
* [**MLpack::lmnn_Python_documentation**](https://www.mlpack.org/doc/stable/python_documentation.html#lmnn)
|
|
|
* [**MLpack::lmnn_C++\_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/classmlpack_1_1lmnn_1_1LMNN.html)
|
|
|
* [**MLpack::lmnn_Python_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/python_documentation.html#lmnn)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
... | ... | |