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 382fa391c..285b9dc16 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 @@ -26,6 +26,8 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) { let sessionParameters let dynamicIndicators + let machineLearningLibraryModuleObject + return thisObject function initialize() { @@ -103,7 +105,6 @@ exports.newSuperalgosBotModulesLearningSystem = function (processIndex) { */ let machineLearningLibrary = learningSystem.machineLearningLibrary - let machineLearningLibraryModuleObject if (machineLearningLibrary === undefined) { // TODO diff --git a/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js b/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js index 71efe0110..9d1e4d324 100644 --- a/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js +++ b/Projects/Superalgos/UI/Function-Libraries/LearningSessionFunctions.js @@ -63,7 +63,7 @@ function newSuperalgosFunctionLibraryLearningSessionFunctions() { let lightingPath = '' + 'Learning System->' + 'TensorFlow Library->' + - 'Execution Environmnet->Supervised Learning->Unsupervised Learning->Self Learning->Reinforcement Learning->' + + 'Execution Environment->Supervised Learning->Unsupervised Learning->Self Learning->Reinforcement Learning->' + 'WebGL Backend->NodeJS Backend->WASM Backend->CPU Backend->' + 'Environment Flags->Debug Mode->Production Mode->' + 'Supervised Learning->Unsupervised Learning->Self Learning->Reinforcement Learning->' + 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 4e3b01ec1..c92020693 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 @@ -22,6 +22,8 @@ exports.newTensorFlowBotModulesTensorFlowLibrary = function (processIndex) { let exchange let market + let tensorFlowBackend + return thisObject function initialize(callbackFunction) { @@ -29,7 +31,64 @@ exports.newTensorFlowBotModulesTensorFlowLibrary = function (processIndex) { learningEngine = TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).SIMULATION_STATE.learningEngine sessionParameters = TS.projects.superalgos.globals.processConstants.CONSTANTS_BY_PROCESS_INDEX_MAP.get(processIndex).SESSION_NODE.learningParameters + + setupBackend() + setupEnvironmentFlags() + callbackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) + + function setupBackend() { + /* + Setup the default backend. + */ + tensorFlowBackend = require("@tensorflow/tfjs-node") + + if ( + learningSystem.machineLearningLibrary.executionEnvironment !== undefined && + learningSystem.machineLearningLibrary.executionEnvironment.backend !== undefined + ) { + /* + Replace the backend for the one defined at the UI. + */ + switch (learningSystem.machineLearningLibrary.executionEnvironment.backend.config.codeName) { + case 'node': { + // This is already the default. + break + } + case 'webgl': { + tensorFlowBackend = require("@tensorflow/tfjs-backend-webgl") + break + } + case 'wasm': { + tensorFlowBackend = require("@tensorflow/tfjs-backend-wasm") + break + } + case 'cpu': { + tensorFlowBackend = require("@tensorflow/tfjs-backend-cpu") + break + } + } + } + } + + function setupEnvironmentFlags() { + if ( + learningSystem.machineLearningLibrary.executionEnvironment !== undefined && + learningSystem.machineLearningLibrary.executionEnvironment.environmentFlags !== undefined && + learningSystem.machineLearningLibrary.executionEnvironment.environmentFlags.mode + ) { + switch (learningSystem.machineLearningLibrary.executionEnvironment.environmentFlags.mode.type) { + case 'Debug Mode': { + tensorFlowBackend.enableDebugMode() + break + } + case 'Debug Mode': { + tensorFlowBackend.enableProdMode() + break + } + } + } + } } function finalize() { @@ -53,7 +112,7 @@ exports.newTensorFlowBotModulesTensorFlowLibrary = function (processIndex) { } function mantain() { - + } function reset() {