new nn()
Main class for the creation of machine learning models using Tensorflow.
- Source:
Methods
(static) convertToTensor(data) → {Object}
Converts data serving as input for either training or calculations into Tensorflow tensors.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Contains: 2d-JS array with inputs and outputs as [[inputs], [outputs]] |
- Source:
Returns:
Object with minmax of data as well as the arrays converted into tensors.
- Type
- Object
Example
hydro.analyze.nn.convertToTensor({data: [[inputs],[outputs]]})
(static) createModel(params) → {Object}
Neural network sequential model creator. Depends solely on the type of problem that the user is trying to solve and should be used accordingly.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: numinputs (data inputs), numneurons (total hidden layer neurons), numoutputs (neuron outputs) |
- Source:
Returns:
Model created based on the specifications.
- Type
- Object
Example
hydro.analyze.nn.createModel({params: {numinputs: 30, numneurons: 11, numoutputs:50})
(static) prediction(params, args, data) → {Object}
Given a trained model, uses it for calculating outputs based on raw data. The data is fed as input on the parameters and needs to be of the same size as the training data. The input data needs to be converted into a TS tensor (array) previous to be fed. The function also requires the minmax of the outputs.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: model (pretrained) |
args |
Object | Contains: outputMin (Minimum value of observation), outputMax (Maximum value of observation) |
data |
Object | Contains: 1d-JS array with inputs for model outcome as [inputs] |
- Source:
Returns:
Object with predictions as array. It also renders to screen.
- Type
- Object
Example
hydro.analyze.nn.prediction({params: {model: model}, args: {outputMin: 'someValue', outputMax: 'someValue'},
data: [inputs]})
(static) saveModel(params) → {Object}
Function for downloading a model that is already trained. It is saved in the user's download folder.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: model (pretrained), name (name for the model) |
- Source:
Returns:
saved model on local storage.
- Type
- Object
Example
hydro.analyze.nn.saveModel({params: {model: model, name: 'someName'}})
(static) trainModel(params, args, data) → {Object}
Trains the model given inputs and ouputs of training data. Generates weights for each expected outcome. The model can be saved in local storage using the save model function. The compilation is donw using loss function binary Cross entropy, ADAM optimizer and MSE for evaluation metric.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: model (from createModel function) |
args |
Object | Contains: epochs (1-1000), lr (learning rate between 0-0.2), batch (size depending on inputs/output ratio) |
data |
Object | Contains: 2d-JS array containing the normalized TF arrays for input and output as [[inputs], [outputs]] |
- Source:
Returns:
Trained model.
- Type
- Object
Example
hydro.analyze.nn.trainModel({params:{model: model}, args: {epochs: 'someNum', lr: 'someNum', batch: 'someNum'},
data: [[inputs, outputs]]})