Methods
defineConfig
Defines the hyperparameters for perceptron.
Example
// Enable random shuffling of examples!
myPerceptron.defineConfig( { shuffleData: true } );
// -> { shuffleData: true, maxIterations: 9, featureExtractor: null }
Parameters
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config | object | table below details the properties of An empty config object restores the default configuration. Properties
|
Returns
A copy of configuration defined.
- Type
- object
exportJSON
Exports the learning as a JSON, which may be saved as a text file for
later use via importJSON()
.
Example
// Assuming that learn() method has been already succesful.
myPerceptron.exportJSON();
// -> JSON string.
Throws
Error if export is attempted without learning.
Returns
Learning in JSON format.
- Type
- string
importJSON
Imports an existing JSON learning for prediction purpose only; it cannot be used for further learning.
Example
// Assuming that `json` already has a valid JSON string.
myPerceptron.importJSON( json );
Parameters
Name | Type | Description |
---|---|---|
json | JSON | containing learnings in as exported by |
Throws
Error if json
is invalid.
Returns
Always true.
- Type
- boolean
learn
Learns from the examples. The hyperparameters, defined via defineConfig
,
control learning process.
Example
myPerceptron.learn( examples );
Parameters
Name | Type | Description |
---|---|---|
examples | Array.<array> | each example is a 2-element array. The
first element describes example's features and the second one defines
its class label. Both of these are expressed in form of an object. The
features object contains name/numeric-value pairs for every feature, whereas the
class label contains single name/string-value pair as |
Throws
Error if all examples
belong to only one class OR if attempted
after importJSON()
.
Returns
Number of examples passed.
- Type
- number
predict
Predicts the label for the input features
. If it is unable to predict then
it returns a value unknown
.
Example
myPerceptron.predict( features );
Parameters
Name | Type | Description |
---|---|---|
features | object | object that contains name/value pairs for every feature. |
Throws
Returns
Predicted class label for the input features
.
- Type
- string
reset
It completely resets the perceptron by re-initializing all the learning related variables but does not touch the existing configuration.
Since it does not reset the existing configuration, user must define it again prior to learning if required.
Example
myPerceptron.reset();
// -> true
Returns
Always true.
- Type
- boolean