{"id":14967272,"url":"https://github.com/jczic/micromlp","last_synced_at":"2025-06-24T01:02:31.074Z","repository":{"id":121870780,"uuid":"145059327","full_name":"jczic/MicroMLP","owner":"jczic","description":"A micro neural network multilayer perceptron for MicroPython (used on ESP32 and Pycom modules)","archived":false,"fork":false,"pushed_at":"2020-12-23T10:15:13.000Z","size":214,"stargazers_count":188,"open_issues_count":4,"forks_count":26,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-02T22:35:27.903Z","etag":null,"topics":["ai","ann","artificial-intelligence","deep-learning","deeplearning","esp32","hc2","lopy","machine-learning","micropython","mlp","multilayer-perceptron","neural-network","neurons","predictive-modeling","pycom","q-learning","qlearning","wipy"],"latest_commit_sha":null,"homepage":"https://micromlp.hc2.fr","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jczic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-17T02:00:19.000Z","updated_at":"2025-04-01T08:19:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"c7818cfe-436a-4644-b18d-f441928341be","html_url":"https://github.com/jczic/MicroMLP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jczic/MicroMLP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroMLP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroMLP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroMLP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroMLP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jczic","download_url":"https://codeload.github.com/jczic/MicroMLP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jczic%2FMicroMLP/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261583784,"owners_count":23180669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ann","artificial-intelligence","deep-learning","deeplearning","esp32","hc2","lopy","machine-learning","micropython","mlp","multilayer-perceptron","neural-network","neurons","predictive-modeling","pycom","q-learning","qlearning","wipy"],"created_at":"2024-09-24T13:37:46.336Z","updated_at":"2025-06-24T01:02:31.035Z","avatar_url":"https://github.com/jczic.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## MicroMLP is a micro artificial neural network multilayer perceptron (principally used on ESP32 and [Pycom](http://www.pycom.io) modules)\n\n![HC²](hc2.png \"HC²\")\n\n#### Very easy to integrate and very light with one file only :\n- `\"microMLP.py\"`\n\n#### MicroMLP features :\n- Modifiable multilayer and connections structure\n- Integrated bias on neurons\n- Plasticity of the connections included\n- Activation functions by layer\n- Parameters Alpha, Eta and Gain\n- Managing set of examples and learning\n- QLearning functions to use reinforcement learning\n- Save and load all structure to/from json file\n- Various activation functions :\n  - Heaviside binary step\n  - Logistic (sigmoid or soft step)\n  - Hyperbolic tangent\n  - SoftPlus rectifier\n  - ReLU (rectified linear unit)\n  - Gaussian function\n\n#### Use deep learning for :\n- Signal processing (speech processing, identification, filtering)\n- Image processing (compression, recognition, patterns)\n- Control (diagnosis, quality control, robotics)\n- Optimization (planning, traffic regulation, finance)\n- Simulation (black box simulation)\n- Classification (DNA analysis)\n- Approximation (unknown function, complex function)\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"hc2-deep-learning.png\"\u003e\n\u003c/p\u003e\n\n### Using *MicroMLP* static functions :\n\n| Name | Function |\n| - | - |\n| Create | `mlp = MicroMLP.Create(neuronsByLayers, activationFuncName, layersAutoConnectFunction=None, useBiasValue=1.0)` |\n| LoadFromFile | `mlp = MicroMLP.LoadFromFile(filename)` |\n\n### Using *MicroMLP* speedly creation of a neural network :\n```python\nfrom microMLP import MicroMLP\nmlp = MicroMLP.Create([3, 10, 2], \"Sigmoid\", MicroMLP.LayersFullConnect)\n```\n\n### Using *MicroMLP* main class :\n\n| Name | Function |\n| - | - |\n| Constructor | `mlp = MicroMLP()` |\n| GetLayer | `layer = mlp.GetLayer(layerIndex)` |\n| GetLayerIndex | `idx = mlp.GetLayerIndex(layer)` |\n| RemoveLayer | `mlp.RemoveLayer(layer)` |\n| GetInputLayer | `inputLayer = mlp.GetInputLayer()` |\n| GetOutputLayer | `outputLayer = mlp.GetOutputLayer()` |\n| Learn | `ok = mlp.Learn(inputVectorNNValues, targetVectorNNValues)` |\n| Test | `ok = mlp.Test(inputVectorNNValues, targetVectorNNValues)` |\n| Predict | `outputVectorNNValues = mlp.Predict(inputVectorNNValues)` |\n| QLearningLearnForChosenAction | `ok = mlp.QLearningLearnForChosenAction(stateVectorNNValues, rewardNNValue, pastStateVectorNNValues, chosenActionIndex, terminalState=True, discountFactorNNValue=None)` |\n| QLearningPredictBestActionIndex | `bestActionIndex = mlp.QLearningPredictBestActionIndex(stateVectorNNValues)` |\n| SaveToFile | `ok = mlp.SaveToFile(filename)` |\n| AddExample | `ok = mlp.AddExample(inputVectorNNValues, targetVectorNNValues)` |\n| ClearExamples | `mlp.ClearExamples()` |\n| LearnExamples | `learnCount = mlp.LearnExamples(maxSeconds=30, maxCount=None, stopWhenLearned=True, printMAEAverage=True)` |\n\n| Property | Example | Read/Write |\n| - | - | - |\n| Layers | `mlp.Layers` | get |\n| LayersCount | `mlp.LayersCount` | get |\n| IsNetworkComplete | `mlp.IsNetworkComplete` | get |\n| MSE | `mlp.MSE` | get |\n| MAE | `mlp.MAE` | get |\n| MSEPercent | `mlp.MSEPercent` | get |\n| MAEPercent | `mlp.MAEPercent` | get |\n| ExamplesCount | `mlp.ExamplesCount` | get |\n\n### Using *MicroMLP* to learn the XOr problem (with hyperbolic tangent) :\n```python\nfrom microMLP import MicroMLP\n\nmlp = MicroMLP.Create( neuronsByLayers           = [2, 2, 1],\n                       activationFuncName        = MicroMLP.ACTFUNC_TANH,\n                       layersAutoConnectFunction = MicroMLP.LayersFullConnect )\n\nnnFalse  = MicroMLP.NNValue.FromBool(False)\nnnTrue   = MicroMLP.NNValue.FromBool(True)\n\nmlp.AddExample( [nnFalse, nnFalse], [nnFalse] )\nmlp.AddExample( [nnFalse, nnTrue ], [nnTrue ] )\nmlp.AddExample( [nnTrue , nnTrue ], [nnFalse] )\nmlp.AddExample( [nnTrue , nnFalse], [nnTrue ] )\n\nlearnCount = mlp.LearnExamples()\n\nprint( \"LEARNED :\" )\nprint( \"  - False xor False = %s\" % mlp.Predict([nnFalse, nnFalse])[0].AsBool )\nprint( \"  - False xor True  = %s\" % mlp.Predict([nnFalse, nnTrue] )[0].AsBool )\nprint( \"  - True  xor True  = %s\" % mlp.Predict([nnTrue , nnTrue] )[0].AsBool )\nprint( \"  - True  xor False = %s\" % mlp.Predict([nnTrue , nnFalse])[0].AsBool )\n\nif mlp.SaveToFile(\"mlp.json\") :\n\tprint( \"MicroMLP structure saved!\" )\n```\n\n| Variable | Description | Default |\n| - | - | - |\n| `mlp.Eta` | Weighting of the error correction | 0.30 |\n| `mlp.Alpha` | Strength of connections plasticity | 0.75 |\n| `mlp.Gain` | Network learning gain | 0.99 |\n| `mlp.CorrectLearnedMAE` | Threshold of self-learning error | 0.02 |\n\n| Graphe | Activation function name | Const | Detail |\n| - | - | - | - |\n| ![HC²](graphe_heaviside.png \"Heaviside binary step\") | `\"Heaviside\"` | MicroMLP.ACTFUNC_HEAVISIDE | Heaviside binary step |\n| ![HC²](graphe_sigmoid.png \"Logistic (sigmoid or soft step)\") | `\"Sigmoid\"` | MicroMLP.ACTFUNC_SIGMOID | Logistic (sigmoid or soft step) |\n| ![HC²](graphe_tanh.png \"Hyperbolic tangent\") | `\"TanH\"` | MicroMLP.ACTFUNC_TANH | Hyperbolic tangent |\n| ![HC²](graphe_softplus.png \"SoftPlus rectifier\") | `\"SoftPlus\"` | MicroMLP.ACTFUNC_SOFTPLUS | SoftPlus rectifier |\n| ![HC²](graphe_relu.png \"Rectified linear unit\") | `\"ReLU\"` | MicroMLP.ACTFUNC_RELU | Rectified linear unit |\n| ![HC²](graphe_gaussian.png \"Gaussian function\") | `\"Gaussian\"` | MicroMLP.ACTFUNC_GAUSSIAN | Gaussian function |\n\n| Layers auto-connect function | Detail |\n| - | - |\n| `MicroMLP.LayersFullConnect` | Network fully connected |\n\n### Using *MicroMLP.Layer* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `layer = MicroMLP.Layer(parentMicroMLP, activationFuncName=None, neuronsCount=0)` |\n| GetLayerIndex | `idx = layer.GetLayerIndex()` |\n| GetNeuron | `neuron = layer.GetNeuron(neuronIndex)` |\n| GetNeuronIndex | `idx = layer.GetNeuronIndex(neuron)` |\n| AddNeuron | `layer.AddNeuron(neuron)` |\n| RemoveNeuron | `layer.RemoveNeuron(neuron)` |\n| GetMeanSquareError | `mse = layer.GetMeanSquareError()` |\n| GetMeanAbsoluteError | `mae = layer.GetMeanAbsoluteError()` |\n| GetMeanSquareErrorAsPercent | `mseP = layer.GetMeanSquareErrorAsPercent()` |\n| GetMeanAbsoluteErrorAsPercent | `maeP = layer.GetMeanAbsoluteErrorAsPercent()` |\n| Remove | `layer.Remove()` |\n\n| Property | Example | Read/Write |\n| - | - | - |\n| ParentMicroMLP | `layer.ParentMicroMLP` | get |\n| ActivationFuncName | `layer.ActivationFuncName` | get |\n| Neurons | `layer.Neurons` | get |\n| NeuronsCount | `layer.NeuronsCount` | get |\n\n### Using *MicroMLP.InputLayer(Layer)* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `inputLayer = MicroMLP.InputLayer(parentMicroMLP, neuronsCount=0)` |\n| SetInputVectorNNValues | `ok = inputLayer.SetInputVectorNNValues(inputVectorNNValues)` |\n\n### Using *MicroMLP.OutputLayer(Layer)* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `outputLayer = MicroMLP.OutputLayer(parentMicroMLP, activationFuncName, neuronsCount=0)` |\n| GetOutputVectorNNValues | `outputVectorNNValues = outputLayer.GetOutputVectorNNValues()` |\n| ComputeTargetLayerError | `ok = outputLayer.ComputeTargetLayerError(targetVectorNNValues)` |\n\n### Using *MicroMLP.Neuron* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `neuron = MicroMLP.Neuron(parentLayer)` |\n| GetNeuronIndex | `idx = neuron.GetNeuronIndex()` |\n| GetInputConnections | `connections = neuron.GetInputConnections()` |\n| GetOutputConnections | `connections = neuron.GetOutputConnections()` |\n| AddInputConnection | `neuron.AddInputConnection(connection)` |\n| AddOutputConnection | `neuron.AddOutputConnection(connection)` |\n| RemoveInputConnection | `neuron.RemoveInputConnection(connection)` |\n| RemoveOutputConnection | `neuron.RemoveOutputConnection(connection)` |\n| SetBias | `neuron.SetBias(bias)` |\n| GetBias | `neuron.GetBias()` |\n| SetOutputNNValue | `neuron.SetOutputNNValue(nnvalue)` |\n| ComputeValue | `neuron.ComputeValue()` |\n| ComputeError | `neuron.ComputeError(targetNNValue=None)` |\n| Remove | `neuron.Remove()` |\n\n| Property | Example | Read/Write |\n| - | - | - |\n| ParentLayer | `neuron.ParentLayer` | get |\n| ComputedOutput | `neuron.ComputedOutput` | get |\n| ComputedDeltaError | `neuron.ComputedDeltaError` | get |\n| ComputedSignalError | `neuron.ComputedSignalError` | get |\n\n### Using *MicroMLP.Connection* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `connection = MicroMLP.Connection(neuronSrc, neuronDst, weight=None)` |\n| UpdateWeight | `connection.UpdateWeight(eta, alpha)` |\n| Remove | `connection.Remove()` |\n\n| Property | Example | Read/Write |\n| - | - | - |\n| NeuronSrc | `connection.NeuronSrc` | get |\n| NeuronDst | `connection.NeuronDst` | get |\n| Weight | `connection.Weight` | get |\n\n### Using *MicroMLP.Bias* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `bias = MicroMLP.Bias(neuronDst, value=1.0, weight=None)` |\n| UpdateWeight | `bias.UpdateWeight(eta, alpha)` |\n| Remove | `bias.Remove()` |\n\n| Property | Example | Read/Write |\n| - | - | - |\n| NeuronDst | `bias.NeuronDst` | get |\n| Value | `bias.Value` | get |\n| Weight | `bias.Weight` | get |\n\n### Using *MicroMLP.NNValue* static functions :\n\n| Name | Function |\n| - | - |\n| FromPercent | `nnvalue = MicroMLP.NNValue.FromPercent(value)` |\n| NewPercent | `nnvalue = MicroMLP.NNValue.NewPercent()` |\n| FromByte | `nnvalue = MicroMLP.NNValue.FromByte(value)` |\n| NewByte | `nnvalue = MicroMLP.NNValue.NewByte()` |\n| FromBool | `nnvalue = MicroMLP.NNValue.FromBool(value)` |\n| NewBool | `nnvalue = MicroMLP.NNValue.NewBool()` |\n| FromAnalogSignal | `nnvalue = MicroMLP.NNValue.FromAnalogSignal(value)` |\n| NewAnalogSignal | `nnvalue = MicroMLP.NNValue.NewAnalogSignal()` |\n\n### Using *MicroMLP.NNValue* class :\n\n| Name | Function |\n| - | - |\n| Constructor | `nnvalue = MicroMLP.NNValue(minValue, maxValue, value)` |\n\n| Property | Example | Read/Write |\n| - | - | - |\n| AsFloat | `nnvalue.AsFloat = 639.513` | get / set |\n| AsInt | `nnvalue.AsInt = 12345` | get / set |\n| AsPercent | `nnvalue.AsPercent = 65` | get / set |\n| AsByte | `nnvalue.AsByte = b'\\x75'` | get / set |\n| AsBool | `nnvalue.AsBool = True` | get / set |\n| AsAnalogSignal | `nnvalue.AsAnalogSignal = 0.39472` | get / set |\n\n\n\n### By JC`zic for [HC²](https://www.hc2.fr) ;')\n\n*Keep it simple, stupid* :+1:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjczic%2Fmicromlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjczic%2Fmicromlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjczic%2Fmicromlp/lists"}