Rules FAQ Members List Search Register Login

 Raised This Month: \$106 Target: \$400 26%

Author Message
LuKks
Senior Member
Join Date: Dec 2012
Location: Argentina, Santa Fe
09-03-2018 , 23:11   Artificial intelligence (neural networks)
#1

As developers, we can create neural networks, there are many types of networks and incredible uses.

A neural network is basically a neurons set connected to each other and the form or complexity of connection will vary its type.

In AMXX it seems that there is no API to create a neural network, that is what we are going for. Also I replicated a version in JavaScript.

PHP Code:
``` #include <amxmodx> #include neural_simple public plugin_init() {     register_plugin("Neural network (simple layer); example", "1.0.0", "LuKks");     new neural[Neural];     neural = neural_create(2); //crea la red con 2 inputs (entradas)          //will be a random result at the beginning     server_print("2+2 -> %f", neural_think(neural, Float:{ 2.0, 2.0 }) * 100);     for(new i; i < 1000; i++) { //1.000 repetitions         //Float:{ input1, input2 }, output         //we teach him some basic sums         neural_learn(neural, Float:{ 1.0, 1.0 }, 0.02);         neural_learn(neural, Float:{ 1.0, 0.0 }, 0.01);         neural_learn(neural, Float:{ 0.0, 1.0 }, 0.01);         //a network has to know that 1 + 0 = 1         //and 0 + 1 = 1, since they are two different operations         //the results are in decimals, 0.04 means 4         neural_learn(neural, Float:{ 2.0, 2.0 }, 0.04);         //more examples = more precise learning         //internally, the network is managed with 0-1         /*neural_learn(neural, Float:{ 2.0, 1.0 }, 0.03);          neural_learn(neural, Float:{ 1.0, 2.0 }, 0.03);         neural_learn(neural, Float:{ 0.0, 2.0 }, 0.02);*/     }     //    1.000 | 50.000 (repetitions)          // 19.014957 | 18.999979     server_print("15+4 -> %f", neural_think(neural, Float:{ 15.0, 4.0 }) * 100);     //we handle the outputs in numbers like 0.04, then multiply by 100     // -3.950722 | -3.999993     server_print("-9+5 -> %f", neural_think(neural, Float:{ -9.0, 5.0 }) * 100);          // 79.519 | 79.999908     server_print("38+42 -> %f", neural_think(neural, Float:{ 38.0, 42.0 }) * 100);  }  ```
At first the network did not know how much it was 2 + 2 but after a little learning with some simple sums we teach the addition pattern, that way you can then handle sums that we do not teach you.
This exercise is very easy for the network because it does not present a difficult pattern.

You can invent a simple pattern and teach it to the network.

You can try to teach him something else, for example:
Spoiler

But first, what is a layer?
Spoiler

Remember what an NPC is? Non-Player Character
Spoiler

Let's see an example for the multi layer.
PHP Code:
``` #include <amxmodx> #include neural_multi public plugin_init() {     register_plugin("Neural network (multi layer); example", "1.0.0", "LuKks");     //layers     neural_layer(8, 2); //(neurons, inputs) -> hidden/input layer     neural_layer(8); //(neurons) -> hidden layer     //neural_layer(2); //(neurons) -> can add more hidden layers     neural_layer(1, -1); //(neurons, -1) -> output layer          //inside the include, at the beginning, there are maximums setted     //for example, 6 layers maximum, can modify it     for(new i, Float:mse; i < 5000; i++) { //5.000 limit iterations         mse += neural_learn(Float:{ 0.0, 0.0 }, Float:{ 0.0 }, 0.45);         mse += neural_learn(Float:{ 1.0, 0.0 }, Float:{ 1.0 }, 0.45);         mse += neural_learn(Float:{ 0.0, 1.0 }, Float:{ 1.0 }, 0.45);         mse += neural_learn(Float:{ 1.0, 1.0 }, Float:{ 0.0 }, 0.45);         mse /= 4; //simple average of the errors in each learning                  //0.45 is the learning rate         //don't really need to get the mse (medium square error)         //can teach him no matter the error         if(mse < 0.00025) { //stop learn when mean squared error reach this limit             server_print("mse threshold on iter %d", i);             break;         }         if(!(i % 1000)) {             server_print("iter %d, mse %f", i, mse);         }     }     //in theory, a simple network can't learn this pattern     //because technically it's not a linear problem     //a multilayer network can solve non linear patterns!     //OR is linear and XOR isn't -> https://vgy.me/dSbEu0.png     new Float:outputs[NEURAL_MAX_OUTPUTS];     outputs = neural_think(Float:{ 0.0, 0.0 });     server_print("0.0 [0.0] -> %f", outputs[0]); //0.014664     outputs = neural_think(Float:{ 1.0, 0.0 });     server_print("1-0 [1.0] -> %f", outputs[0]); //0.992533     //if have a lot outputs, you can ->     /*for(new i; i < layers[layers_id - 1][max_neurons]; i++) {         server_print("output %d -> %f", i, outputs[i]);     }*/     //also, can use     //neural_save("zombie-npc");     //neural_load("zombie-npc");     //after load, you can't create more layers (neural_layer) and nothing involved to config     //if have a neural created and you load a new neural, it will be overwritted, so you can do it }  ```
This is just a beginning, as I said before, there are many types of neural networks.
These two are the ones that I have used the most, for other types I have always helped myself from libraries or systems already done because for me it is not worth learning and re-creating so much functionality.
The current systems always served me as learning and to get greater reasoning.

A neural network claims to be equal to or better than a human.
A neural network will not distracted, doesn't rest, doesn't look the other way, etc.
A network has a margin of error (it's not probability, that is different).
How does the margin of error works? Well, you saw it right at the beginning with the simple network (and again with multi-layer).
Spoiler

Why is not there a neural network that simulates a human brain?
Spoiler

How do neural networks learn?
Spoiler

Same learning, different weights?
Spoiler

Why is it difficult to handle so many neurons?
Spoiler

As I said at the beginning, there are many types of networks. For example, a multi-layer perceptron neural network with back-propagation can handle patterns, image recognition and surely many other uses, probably for translation of languages ​​according to my memory.
Surely driving a car can also, is that there are so many types of networks that sometimes there is a better solution but it is understood.

Spoiler

Regarding the examples, you can always make a comment and ask me.
If it's a problem that you are having with a plugin maybe you should create a separate publication (send me a private message with the link to the post because I don't check the new ones, thank you) but if it is a specific question to the code or the topic, I think you could directly comment it so the rest see your question as well.

Note: I was not allowed to upload .js, so I called it neural_javascript.sma for the JavaScript one. I did it similar to amxx, I know that the js can be improved a lot but it was not the point.

Changelog
Spoiler
Attached Files
 neural_simple.inc (1.1 KB, 44 views) neural_multi.inc (7.7 KB, 53 views) Get Plugin or Get Source (neural_javascript.sma - 123 views - 3.3 KB)
SpawnerF
Member
Join Date: Apr 2017
Location: Morocco
 11-23-2018 , 13:59   Re: Artificial intelligence (neural networks) #2 Intresting subject, thank's. Last edited by SpawnerF; 11-23-2018 at 13:59.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
 11-23-2018 , 22:14   Re: Artificial intelligence (neural networks) #3 Cutting edge technology. You should create a plugin to demonstrate this. While it is interesting, it will get buried quickly since many will not know what to do with it. You got lucky and SpawnerF saved it. __________________ Last edited by Bugsy; 11-23-2018 at 22:18.
Celena Luna
Senior Member
Join Date: Aug 2013
Location: Okinawa, Japan
 11-26-2018 , 02:04   Re: Artificial intelligence (neural networks) #4 This is interesting but also quite compilcated. The game is too old now so the current active player is not as many so not many scripter would try to tackle on this imo. __________________ My plugin:Zombie Shelter [1%] [WIP] BOUNCER (Beta)[100%] [Done][Link in the video] Dual Beretta Gunslinger[100%][v2.0] Last edited by Celena Luna; 11-26-2018 at 02:05.
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
 11-26-2018 , 10:47   Re: Artificial intelligence (neural networks) #5 Interesting topic. I agree with Bugsy that you should create a demostration plugin or something useful to show it's potential and motivate devs to use it. __________________
JocAnis
Senior Member
Join Date: Jun 2010
 11-26-2018 , 18:01   Re: Artificial intelligence (neural networks) #6 i didnt undestand very well this one...any practical example (hopefully not for npc) is really welcomed __________________ KZ Public Autocup DR Timer (selling) - Top15 images
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
11-27-2018 , 05:24   Re: Artificial intelligence (neural networks)
#7

Quote:
 Originally Posted by JocAnis i didnt undestand very well this one...any practical example (hopefully not for npc) is really welcomed
Don't bother, it's a really advanced topic and requires a ton of math to fully understand.
__________________

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TF2Items         TFDodgeball         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

All times are GMT -4. The time now is 01:09.

 DMCA - Archive - Top