... | @@ -2,11 +2,19 @@ |
... | @@ -2,11 +2,19 @@ |
|
|
|
|
|
An implementation of several strategies for principal components analysis (PCA), a common preprocessing step. Given a dataset and a desired new dimensionality, this can reduce the dimensionality of the data using the linear transformation determined by PCA.
|
|
An implementation of several strategies for principal components analysis (PCA), a common preprocessing step. Given a dataset and a desired new dimensionality, this can reduce the dimensionality of the data using the linear transformation determined by PCA.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
:- use_module('path/to/.../src/methods/pca/pca.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],
|
|
|
|
pca(0, randomized, TrainData, 3, TDataList, _, EigValList, EigVecList, _).
|
|
|
|
```
|
|
|
|
|
|
# Available Predicates
|
|
# Available Predicates
|
|
|
|
|
|
* [pca/13](/PrologMethods/Transformation/pca#pca13)
|
|
* [pca/9](/PrologMethods/Transformation/pca#pca9)
|
|
* [pcaDimReduction/10](/PrologMethods/Transformation/pca#pcadimreduction10)
|
|
* [pcaDimReduction/8](/PrologMethods/Transformation/pca#pcadimreduction8)
|
|
* [pcaVarianceDimReduction/10](/PrologMethods/Transformation/pca#pcavariancedimreduction10)
|
|
* [pcaVarianceDimReduction/8](/PrologMethods/Transformation/pca#pcavariancedimreduction8)
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
... | @@ -17,12 +25,21 @@ An implementation of several strategies for principal components analysis (PCA), |
... | @@ -17,12 +25,21 @@ An implementation of several strategies for principal components analysis (PCA), |
|
Apply Principal Component Analysis to the provided data set.
|
|
Apply Principal Component Analysis to the provided data set.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
pca( +integer, +string,
|
|
pca(ScaleData, DecompositionPolicy, DataList, DataRows, TransformedList, TDataCols, EigValList, EigVecList, ZCols) :-
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
pcaI(ScaleData, DecompositionPolicy, X, Xsize, Xrows, TData, TDataCols, TDataRows, Y, Ysize, Z, ZCols, ZRows),
|
|
|
|
convert_float_array_to_2d_list(TData, TDataCols, TDataRows, TransformedList),
|
|
|
|
convert_float_array_to_list(Y, Ysize, EigValList),
|
|
|
|
convert_float_array_to_2d_list(Z, ZCols, ZRows, EigVecList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(pca, c, pcaI( +integer,
|
|
|
|
+string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
-pointer(float_array), -integer, -integer,
|
|
-pointer(float_array), -integer, -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer,
|
|
-pointer(float_array), -integer, -integer).
|
|
-pointer(float_array), -integer, -integer)).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -45,12 +62,20 @@ Use PCA for dimensionality reduction on the given dataset. |
... | @@ -45,12 +62,20 @@ Use PCA for dimensionality reduction on the given dataset. |
|
This will save the newDimension largest principal components of the data and remove the rest. The parameter returned is the amount of variance of the data that is retained; this is a value between 0 and 1. For instance, a value of 0.9 indicates that 90% of the variance present in the data was retained.
|
|
This will save the newDimension largest principal components of the data and remove the rest. The parameter returned is the amount of variance of the data that is retained; this is a value between 0 and 1. For instance, a value of 0.9 indicates that 90% of the variance present in the data was retained.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
pcaDimReduction( +integer, +string,
|
|
pcaDimReduction(ScaleData, DecompositionPolicy, DataList, DataRows, NewDim, TransformedList, TDataCols, Variance) :-
|
|
|
|
NewDim > 0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
pcaDimReductionI(ScaleData, DecompositionPolicy, X, Xsize, Xrows, NewDim, TData, TDataCols, TDataRows, Variance),
|
|
|
|
convert_float_array_to_2d_list(TData, TDataCols, TDataRows, TransformedList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(pcaDimReduction, c, pcaDimReductionI( +integer,
|
|
|
|
+string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+integer,
|
|
+integer,
|
|
-pointer(float_array), -integer, -integer,
|
|
-pointer(float_array), -integer, -integer,
|
|
[-float32]).
|
|
[-float32])).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -75,12 +100,21 @@ This will save as many dimensions as necessary to retain at least the given amou |
... | @@ -75,12 +100,21 @@ This will save as many dimensions as necessary to retain at least the given amou |
|
The method returns the actual amount of variance retained, which will always be greater than or equal to the varRetained parameter.
|
|
The method returns the actual amount of variance retained, which will always be greater than or equal to the varRetained parameter.
|
|
|
|
|
|
```prolog
|
|
```prolog
|
|
%% part of the predicate definition
|
|
%% predicate definition
|
|
pcaVarianceDimReduction( +integer, +string,
|
|
pcaVarianceDimReduction(ScaleData, DecompositionPolicy, DataList, DataRows, VarRetained, TransformedList, TDataCols, Variance) :-
|
|
|
|
VarRetained >= 0.0,
|
|
|
|
VarRetained =< 1.0,
|
|
|
|
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrows, X)),
|
|
|
|
pcaVarianceDimReductionI(ScaleData, DecompositionPolicy, X, Xsize, Xrows, VarRetained, TData, TDataCols, TDataRows, Variance),
|
|
|
|
convert_float_array_to_2d_list(TData, TDataCols, TDataRows, TransformedList).
|
|
|
|
|
|
|
|
%% foreign c++ predicate definition
|
|
|
|
foreign(pcaVarianceDimReduction, c, pcaVarianceDimReductionI( +integer,
|
|
|
|
+string,
|
|
+pointer(float_array), +integer, +integer,
|
|
+pointer(float_array), +integer, +integer,
|
|
+float32,
|
|
+float32,
|
|
-pointer(float_array), -integer, -integer,
|
|
-pointer(float_array), -integer, -integer,
|
|
[-float32]).
|
|
[-float32])).
|
|
```
|
|
```
|
|
|
|
|
|
### Parameters
|
|
### Parameters
|
... | @@ -100,8 +134,8 @@ pcaVarianceDimReduction( +integer, +string, |
... | @@ -100,8 +134,8 @@ pcaVarianceDimReduction( +integer, +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.
|
|
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::pca_C++\_documentation**](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1pca_1_1PCA.html)
|
|
* [**MLpack::pca_C++\_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/doxygen/classmlpack_1_1pca_1_1PCA.html)
|
|
* [**MLpack::pca_Python_documentation**](https://www.mlpack.org/doc/stable/python_documentation.html#pca)
|
|
* [**MLpack::pca_Python_documentation**](https://www.mlpack.org/doc/mlpack-3.4.2/python_documentation.html#pca)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
added some of the links from the python documentation
|
|
|
|
|
... | | ... | |