PHP Classes

File: examples/case-studies/ai/neural/neural_workflow_composer/neural_workflow_composer.md

Recommend this page to a friend!
  Packages of Christos Drogidis   Ascoos OS   examples/case-studies/ai/neural/neural_workflow_composer/neural_workflow_composer.md   Download  
File: examples/case-studies/ai/neural/neural_workflow_composer/neural_workflow_composer.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change: Neural Workflow Composer
Neural Workflow Composer
Date: 6 months ago
Size: 2,809 bytes
 

Contents

Class file image Download

Neural Workflow Composer: Macro Execution via Neural Prediction

This case study demonstrates how Ascoos OS can intelligently execute macros based on system history using neural networks. The system learns from past performance metrics and predicts optimal macro actions.

Purpose

  • Train a neural network with historical system data
  • Predict whether a macro should be executed
  • Execute macros based on prediction score

Core Ascoos OS Classes

  • TNeuralNetworkHandler Neural network compilation, training, and prediction
  • TMacroHandler Macro definition and execution logic

File Structure

The implementation resides in a single PHP file: - neural_workflow_composer.php

It contains all logic: data preparation, model training, prediction, and macro execution.

Requirements

  1. PHP ? 8.2
  2. Installed Ascoos OS or AWES 26

Execution Flow

  1. Historical system data (CPU, RAM, Disk) is defined.
  2. A neural network is compiled with two layers: - Input: 3 ? Hidden: 4 (ReLU) - Hidden: 4 ? Output: 1 (Sigmoid)
  3. The model is trained with `fit()` using 1000 epochs and learning rate 0.01.
  4. The current system state is evaluated.
  5. If the prediction score > 0.5, a macro is executed.
  6. Otherwise, macro execution is skipped.

Code Example

$composer = new TNeuralNetworkHandler();
$composer->compile([
    ['input' => 3, 'output' => 4, 'activation' => 'relu'],
    ['input' => 4, 'output' => 1, 'activation' => 'sigmoid']
]);
$composer->fit($systemData, $actions, epochs: 1000, lr: 0.01);

$score = $composer->predictNetwork([$currentState])[0];

if ($score > 0.5) {
    $macroHandler = new TMacroHandler();
    $macroHandler->addMacro(fn() => print("Executing optimized macro"), [], delay: 0, priority: 1);
    $macroHandler->runNext();
} else {
    print("Macro skipped based on neural prediction\n");
}

Expected Output

If the prediction score is high:

Executing optimized macro

Otherwise:

Macro skipped based on neural prediction

Resources

Contribution

You can enhance the neural model, integrate additional system metrics, or extend macro logic. See CONTRIBUTING.md for guidelines.

License

This case study is covered under the Ascoos General License (AGL). See LICENSE.md.