|
|
|
# Perceptron
|
|
|
|
|
|
|
|
An implementation of a perceptron -a single level neural network- for classification.
|
|
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
|
|
* [initModelNoTrain/3](/PrologMethods/Classification/perceptron#initmodelnotrain3)
|
|
|
|
* [initModelWithTrain/7](/PrologMethods/Classification/perceptron#initmodelwithtrain7)
|
|
|
|
* [biases/2](/PrologMethods/Classification/perceptron#biases2)
|
|
|
|
* [classify/5](/PrologMethods/Classification/perceptron#classify5)
|
|
|
|
* [train/8](/PrologMethods/Classification/perceptron#train8)
|
|
|
|
* [weights/3](/PrologMethods/Classification/perceptron#weights3)
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
[links/resources](/PrologMethods/Classification/perceptron#connected-linksresources)
|
|
|
|
|
|
|
|
## **_initModelNoTrain/3_**
|
|
|
|
|
|
|
|
Initilizes the perceptron model and its weight matrix but doesn't train it.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
initModelNoTrain(+integer, +integer, +integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| numClasses | +integer | | 0 |
|
|
|
|
| dimensionality | +integer | Number of classes in the data. | 0 |
|
|
|
|
| maxIterations | +integer | The maximum number of iterations the perceptron is to be run. | 1000 |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_initModelWithTrain/7_**
|
|
|
|
|
|
|
|
Initilizes the perceptron model and its weight matrix and trains it with the given data.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
initModelWithTrain( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
+integer, +integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | A matrix containing the training set. | - |
|
|
|
|
| labels | +vector | A vector containing labels for the training set. | - |
|
|
|
|
| numClasses | +integer | Number of classes in the data. | 0 |
|
|
|
|
| maxIterations | +integer | The maximum number of iterations the perceptron is to be run. | 1000 |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_biases/2_**
|
|
|
|
|
|
|
|
Get the biases.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
biases(-pointer(float_array), -integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| biases | -vector | Get the biases. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_classify/5_**
|
|
|
|
|
|
|
|
After training, use the weights matrix to classify test, and put the predicted classes in predictedLabels.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
classify( +pointer(float_array), +integer, +integer,
|
|
|
|
-pointer(float_array), -integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| test | +matrix | | - |
|
|
|
|
| predicLabels | -vector | The predicted labels for the test data. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_train/8_**
|
|
|
|
|
|
|
|
Train the perceptron on the given data for up to the maximum number of iterations. This training does not reset the model weights, so you can call train/8 on multiple datasets sequentially.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
train( +pointer(float_array), +integer, +integer,
|
|
|
|
+pointer(float_array), +integer,
|
|
|
|
+integer,
|
|
|
|
+pointer(float_array), +integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| data | +matrix | A matrix containing the training set. | - |
|
|
|
|
| labels | +vector | A vector containing labels for the training set. | - |
|
|
|
|
| numClasses | +integer | Number of classes in the data. | 0 |
|
|
|
|
| instanceWeights | +vector | Cost matrix. Stores the cost of mispredicting instances. This is useful for boosting. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## **_weights/3_**
|
|
|
|
|
|
|
|
Get the weight matrix.
|
|
|
|
|
|
|
|
```prolog
|
|
|
|
%% part of the predicate definition
|
|
|
|
weights(-pointer(float_array), -integer, -integer).
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
| Name | Type | Description | Default |
|
|
|
|
|------|------|-------------|---------|
|
|
|
|
| weights | -matrix | Get the weight matrix. | - |
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
# Connected Links/Resources
|
|
|
|
|
|
|
|
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::perceptron_C++\_documentation](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1perceptron_1_1Perceptron.html)
|
|
|
|
* [MLpack::perceptron_Python_documentation](https://www.mlpack.org/doc/stable/python_documentation.html#perceptron)
|
|
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
|
|
|
|
* adaboost
|
|
|
|
* [Perceptron on Wikipedia](https://en.wikipedia.org/wiki/Perceptron) |
|
|
|
\ No newline at end of file |