{"id":27483353,"url":"https://github.com/hectorpulido/imitation-learning-in-unity","last_synced_at":"2025-04-16T15:46:13.869Z","repository":{"id":111766770,"uuid":"140051885","full_name":"HectorPulido/Imitation-learning-in-unity","owner":"HectorPulido","description":"What if we record all the information in a game, and we record the player actions, then we train a neural network with that data? Thats what this is!","archived":false,"fork":false,"pushed_at":"2018-07-30T07:03:44.000Z","size":98485,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-10T21:39:49.409Z","etag":null,"topics":["ai","gamedev","imitation-learning","machine-learning","neural-network","unity","videogame-bot"],"latest_commit_sha":null,"homepage":"https://youtu.be/nwqnGh2FiUo","language":"C#","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/HectorPulido.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-07-07T04:14:49.000Z","updated_at":"2022-06-30T12:32:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0a508f2-bd6c-4f60-b321-cb7dbbe895b7","html_url":"https://github.com/HectorPulido/Imitation-learning-in-unity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HectorPulido%2FImitation-learning-in-unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HectorPulido%2FImitation-learning-in-unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HectorPulido%2FImitation-learning-in-unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HectorPulido%2FImitation-learning-in-unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HectorPulido","download_url":"https://codeload.github.com/HectorPulido/Imitation-learning-in-unity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249256510,"owners_count":21238988,"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","gamedev","imitation-learning","machine-learning","neural-network","unity","videogame-bot"],"created_at":"2025-04-16T15:46:13.327Z","updated_at":"2025-04-16T15:46:13.849Z","avatar_url":"https://github.com/HectorPulido.png","language":"C#","funding_links":["https://www.patreon.com/HectorPulido"],"categories":[],"sub_categories":[],"readme":"# IMITATION LEARNING IN UNITY\nWhat if we record all the information in a game, and we record the player actions, then we train a neural network with that data? Thats what this is! \u003cb\u003eThis is a implementation of [Vectorized neural network](https://github.com/HectorPulido/Vectorized-multilayer-neural-network) \u003c/b\u003ein unity, an open source project that uses neural networks and backpropagation in C#, and train it via stochastic gradient descend using as examples human meditions  \u003cbr/\u003e\n\n### This project is still under development and is highly experimental\n\n## HOW IT WORKS\n[![Banner](http://img.youtube.com/vi/nwqnGh2FiUo/0.jpg)](https://www.youtube.com/watch?v=nwqnGh2FiUo) \u003cbr/\u003e\n\nArtificial neural networks are a group of algorithm that can imitate almost any existing function, just like an universal stimator, it's a hierarchical matrix multiplication function that can imitate even the human behaviour.\n\nWith the human monitor script, the keys that human presses and the sensors of the bot are keeped to be used as a dataset for the Neural net script and it's signals are interpreted by the brain to make a human - like behaviour \n\n## TO DO\n- More examples\n\n## WHY (MOTIVATION)\n[![Banner](http://img.youtube.com/vi/HRYYxJd9qiA/0.jpg)](https://www.youtube.com/watch?v=HRYYxJd9qiA) \u003cbr/\u003e\nThis tutorial was made for \u003cb\u003eHector Pulido\u003c/b\u003e for his youtube channel \u003cbr/\u003e\nhttps://www.youtube.com/c/HectorAndresPulidoPalmar \u003cbr/\u003e\nAnd his Twitch Channel\u003cbr/\u003e\nhttps://www.twitch.tv/hector_pulido_\u003cbr/\u003e\n\n## HOW TO USE\nOpen it on unity 2018 or greater (sorry about that \u003e-\u003c ), and play around with the project.\n\n### How make it works\nThe asset contais 2 important part, the first one is the \u003cb\u003eneural network part\u003c/b\u003e, this piece is inside the brain component, what usually is used in a \u003cb\u003eBotHandler\u003c/b\u003e, that component manage the training process and the prediction process, the other important part is the \u003cb\u003ehuman monitor\u003c/b\u003e, this script must be inherited to save the correct meditions, both brain and human monitor contains tools to save and deploy the data. The basic workflow is to use an bot handler that manage a brain, and a human monitor that train the brain\n\n### BOT HANDLER\nThe neural network is the base of this project, it's imposible to the bot to learn without this, the brain contais the neural network and the hyperparameters\n```csharp\n\nusing NeuralReplicantBot.PerceptronHandler;\nusing LinearAlgebra;\npublic class LogicDoor : BotHandler //\u003c- inherit from BotHandler\n{\n\tprotected override void Awake() //\u003c- you can override the Awake\n\t{\n\t\tbase.Awake(); // \u003c- but remember to call the base Awake\n\t\n\t\tFoo();\t\t\n\t}\n\t\n\tvoid Foo()\n\t{\n\t\tif(isTraining) // Training variable is pretty useful to deploy\n\t\t{\n\t\t\tbrain.Learn(x, y); //\u003c-- You can train, but also you can do it in the HumanMonitor.\n\t\t}\n\t}\n\t\n\tvoid GetOutput()\n\t{\n\t\tprint(brain.GetOutput(x));\n\t}\n}\n\n```\n### HUMAN MONITOR \nThe bot is imitating the human, for this is important to register all important actions from the player before the training the class that do that is the HumanMonitor.\n```csharp\nusing NeuralReplicantBot.PerceptronHandler;\n\npublic class ExampleMonitor : HumanMonitor //\u003c- its super important to inherit from HumanMonitor\n{\n\tprotected override void Medition(ref Medition m)\n\t{          \n\t\t//It's important to add information to the medition object m\n\t\t//This part of the code is runned many times \n\t\t\n\t\tm.outputs.AddRange(y); // Adding y array to the output count\n\t\tm.inputs.AddRange(x); // Adding x array to the output count\n\t}\n\n\tprotected override void MeditionEnd(Medition m)\n\t{\n\t\t// This part of the code is runned once, when the medition count is over\n\t\t// so is important to decide what to do with the information \n\t\t// eg. train the neural network\n\t\t\n\t\tbrain.Learn(input, output);      //\u003c- this is a good place to train the brain      \n\t\t\n\t\tFoo(); //\u003c- you can set BotHandler's property isTraining as false\n\t}\n}\n```\n\n### When you finish to train...\n![Load and save](/Images/Load%20and%20save.JPG) \u003cbr/\u003e\nNow you can load a neural network whenever you want via drag and drop a .nn file, that file is also compatible with Evolutionary Neural Networks on Unity For bots, the same feature is available for the HumanMonitor (and it's childs) as an .med file, to save a .nn or .med, just press the button create, that will generate a EMPTY file, that file can ve overwritten after the training\n\n## EXAMPLES\n\n### LOGIC DOOR \nThis is a super simple script to understand how the brain works, the neural network learns how to make some logic doors, this example does not contains a human monitor\n\n### SELF DRIVING CAR\n![Example](/Images/ExampleImage.gif) \u003cbr/\u003e\nAt this moment there is only one complex example in the project, a self driving car with a lot of raycast as inputs and Horizontal and Vertical axis as output\n\n## OTHER WORKS \n### Evolutionary Neural Networks on Unity For bots\nThis is a asset that train a neural networks using genetic algorithm in unity to make a bot that can play a game or just interact with the envoriment \u003cbr/\u003e\nhttps://github.com/HectorPulido/Evolutionary-Neural-Networks-on-unity-for-bots\n### More Genetic algorithms on Unity\nThose are three Genetics Algorithm using unity, The First one is a simple algorithm that Looks for the minimun of a function, The Second one is a solution for the Travelling Salesman Problem, The Third one is a Automata machine \u003cbr/\u003e\nhttps://github.com/HectorPulido/Three-Genetics-Algorithm-Using-Unity\n### Vectorized Multilayer Neural Network from scratch\nThis is a simple MultiLayer perceptron made with Simple Linear Algebra for C# , is a neural network based on This Algorithm but generalized. This neural network can calcule logic doors like Xor Xnor And Or via Stochastic gradient descent backpropagation with Sigmoid as Activation function, but can be used to more complex problems. \u003cbr/\u003e\nhttps://github.com/HectorPulido/Vectorized-multilayer-neural-network\n\n## LICENCE\nThis project contains a copy of:\n* Unity Standar assets\n* Simple linear algebra https://github.com/HectorPulido/Simple_Linear_Algebra\n\nEverything else is MIT licensed\n\n## Patreon\nPlease consider Support on Patreon\u003cbr/\u003e\n![Please consider support on patreon](/Images/Patreon.png)\u003cbr/\u003e\nhttps://www.patreon.com/HectorPulido\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhectorpulido%2Fimitation-learning-in-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhectorpulido%2Fimitation-learning-in-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhectorpulido%2Fimitation-learning-in-unity/lists"}