From a4050f6c8dd6896a2efdcfd3c42fa5234c3ff805 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 19 Feb 2021 08:37:28 +0100 Subject: [PATCH] features and labels calculated --- .../Low-Frequency-Learning/LearningSystem.js | 4 +- .../Function-Libraries/DependenciesFilter.js | 2 +- .../LearningSessionFunctions.js | 3 +- Projects/TensorFlow/Schemas/AppSchema.json | 14 ++-- .../TensorFlowLibrary.js | 67 +++++++++++++++++-- 5 files changed, 74 insertions(+), 16 deletions(-) diff --git a/Projects/Superalgos/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js b/Projects/Superalgos/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js index 285b9dc16..219109115 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js +++ b/Projects/Superalgos/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningSystem.js @@ -280,7 +280,7 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) { } /* Here we check if there is a formula to be evaluated */ - if ((node.type === 'Formula' || node.type === 'Announcement Formula') && evaluating === 'Formulas') { + if ((node.type === 'Feature Formula' || node.type === 'Label Formula') && evaluating === 'Formulas') { if (node.code !== undefined) { /* We will eval this formula */ if (isDescendent === true) { @@ -405,7 +405,7 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) { return } else { if (value !== undefined) { - if (node.type === 'Formula' && isNaN(value)) { + if ((node.type === 'Feature Formula' || node.type === 'Label Formula') && isNaN(value)) { docs = { project: 'Superalgos', diff --git a/Projects/Superalgos/UI/Function-Libraries/DependenciesFilter.js b/Projects/Superalgos/UI/Function-Libraries/DependenciesFilter.js index 70d90bee2..ad868af02 100644 --- a/Projects/Superalgos/UI/Function-Libraries/DependenciesFilter.js +++ b/Projects/Superalgos/UI/Function-Libraries/DependenciesFilter.js @@ -43,7 +43,7 @@ function newSuperalgosFunctionLibraryDependenciesFilter() { return filters function recursiveFilter(node) { - if (node.type === 'Javascript Code' || node.type === 'Formula' || node.type === 'Feature Formula') { + if (node.type === 'Javascript Code' || node.type === 'Formula' || node.type === 'Feature Formula' || node.type === 'Data Formula') { filter(node.code) } diff --git a/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js b/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js index 86046f20e..51e5303e5 100644 --- a/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js +++ b/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js @@ -72,7 +72,8 @@ function newSuperalgosFunctionLibraryLearningSessionFunctions() { 'Layers API->Code API->' + 'Secuential Model->Functional Model->' + 'Input Layer->Secuential Layer->Output Layer->'+ - 'Input Shape->Batch Input Shape->Input Features->Feature->Feature Formula->' + + 'Input Shape->Batch Input Shape->Input Features->Data Feature->Feature Formula->' + + 'Output Labels->Data Label->Label Formula->' + 'Advanced Activation Layers->Basic Layers->Convolutional Layers->' + 'Conv 1D Layer->Conv 2D Layer->Conv 2D Transpose Layer->Conv 3D Layer->Cropping 2D Layer->Depthwise Convo 2D Layer->Separable Convo 2D Layer->Up Sampling 2D Layer->' + 'Activation Layer->Dense Layer->Dropout Layer->Embedding Layer->Flatten Layer->Permutable Layer->Rrepeat Vector Layer->Reshape Layer->Spatial Dropout 1D Layer->' + diff --git a/Projects/TensorFlow/Schemas/AppSchema.json b/Projects/TensorFlow/Schemas/AppSchema.json index 614006337..6539e5453 100644 --- a/Projects/TensorFlow/Schemas/AppSchema.json +++ b/Projects/TensorFlow/Schemas/AppSchema.json @@ -2915,9 +2915,9 @@ { "action": "Add UI Object", "disableIfPropertyIsDefined": true, - "propertyToCheckFor": "dataLabelFormula", - "label": "Add Data Label Formula", - "relatedUiObject": "Data Label Formula", + "propertyToCheckFor": "labelFormula", + "label": "Add Label Formula", + "relatedUiObject": "Label Formula", "actionFunction": "payload.executeAction" }, { @@ -2938,16 +2938,16 @@ "propertyNameAtParent": "dataLabels", "childrenNodesProperties": [ { - "name": "dataLabelFormula", + "name": "labelFormula", "type": "node", - "childType": "Data Label Formula", + "childType": "Label Formula", "autoAdd": true } ], "icon": "tensorflow" }, { - "type": "Data Label Formula", + "type": "Label Formula", "menuItems": [ { "action": "Edit", @@ -2977,7 +2977,7 @@ "attachingRules": { "compatibleTypes": "->Data Label->" }, - "propertyNameAtParent": "dataLabelFormula", + "propertyNameAtParent": "labelFormula", "childrenNodesProperties": [], "icon": "tensorflow" }, diff --git a/Projects/TensorFlow/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/TensorFlowLibrary.js b/Projects/TensorFlow/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/TensorFlowLibrary.js index 4e1cf3ac3..f2fc1392f 100644 --- a/Projects/TensorFlow/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/TensorFlowLibrary.js +++ b/Projects/TensorFlow/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/TensorFlowLibrary.js @@ -25,6 +25,9 @@ exports.newTensorFlowBotModulesTensorFlowLibrary = function (processIndex) { let tensorFlowBackend let tensorFlowAPI let tensorFlowModel + let tensorFlowData + let features = [] + let labels = [] return thisObject @@ -279,6 +282,14 @@ exports.newTensorFlowBotModulesTensorFlowLibrary = function (processIndex) { chart = undefined exchange = undefined market = undefined + + tensorFlowBackend = undefined + tensorFlowAPI = undefined + tensorFlowModel = undefined + tensorFlowData = undefined + + features = [] + labels = [] } function updateChart(pChart, pExchange, pMarket) { @@ -299,14 +310,60 @@ exports.newTensorFlowBotModulesTensorFlowLibrary = function (processIndex) { } function run(callbackFunction) { - /* - Do your magic here... - */ + + let layersModel = learningSystem.machineLearningLibrary.typeOfLearning.typeOfModel.model.api.layersModel /* - if all is good, return this... + Building the Features Tensor */ - callbackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) + if (layersModel.inputLayer === undefined) { + // TODO + } + if (layersModel.inputLayer.inputFeatures === undefined) { + // TODO + } + learningSystem.evalFormulas(layersModel.inputLayer.inputFeatures, layersModel.inputLayer.inputFeatures.type) + + for (let i = 0; i < layersModel.inputLayer.inputFeatures.dataFeatures.length; i++) { + let dataFeature = layersModel.inputLayer.inputFeatures.dataFeatures[i] + if (dataFeature.featureFormula === undefined) { continue } + let featureValue = learningSystem.formulas.get(dataFeature.featureFormula.id) + features.push(featureValue) + } + + /* + Building the Labels Tensor + */ + if (layersModel.outputLayer === undefined) { + // TODO + } + if (layersModel.outputLayer.outputLabels === undefined) { + // TODO + } + learningSystem.evalFormulas(layersModel.outputLayer.outputLabels, layersModel.outputLayer.outputLabels.type) + + for (let i = 0; i < layersModel.outputLayer.outputLabels.dataLabels.length; i++) { + let dataLabel = layersModel.outputLayer.outputLabels.dataLabels[i] + if (dataLabel.labelFormula === undefined) { continue } + let labelValue = learningSystem.formulas.get(dataLabel.labelFormula.id) + labels.push(labelValue) + } + + tensorFlowData = require("@tensorflow/tfjs-data") + + let dataset = tensorFlowData.array([features, labels]) + + tensorFlowModel.fitDataset(dataset, { epochs: 5 }).then(info => { + console.log('Accuracy', info.history.acc); + + /* + if all is good, return this... + */ + callbackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) + + }); + + /* if something is bad, return this...