This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Creator's profile picture

Artificial Inteligence in ComputerCraft - NeuralNetworks

Started by Creator, 10 October 2015 - 02:12 PM
Creator #1
Posted 10 October 2015 - 04:12 PM
–AI–


A long time ago, I got interested in neural networks. Seeing the power they gave me , I tried coding one in Lua. In vain. It didn't work, so I gave it up. Some days ago I tried it again, and because I did not use the right approach, I failed. However, today my third attempt started. After working with pauses for 3-4 hours, it worked!

I can finally and proudly present you AI, a fully working neural network! This version has the ability to learn. Isn't that amazing. Some of the best suited uses would be recognizing handwriting, training it to emulate a XOR gate, finding the verb in a sentence, and other totally useful stuff.

You're dying to use it? Here are the different functions it provides you with:
SpoilerLoading it into memory:

os.loadAPI("AI")

Constructing a net:

AI.Net(topology)
@topology: a table that holds the topology of the network.

Example:

AI.Net({2,4,1})
This network will have 2 input neurons, 1 hidden layer with 4 neurons, and one output neuron.

Analyzing information:

myNet = AI.Net({2,4,1})
myNet.feedForward({1,0}) --this is the interesting line.
The argument given to feedForward is a table holding the information for the input layer. The number at index 1 will be provided to the first input neuron, the second to the second, and so on.

Training it:

myNet = AI.Net({2,4,1})
myNet.feedForward({1,0})
myNet.backProp({1}) --this is the interesting line.
This means that that the network will modify the weights in order to make the previously given input output the numbers you gave as an ardument now.

Getting the results:

myNet = AI.Net({2,4,1})
myNet.feedForward({1,0})
myNet.backProp({1})
myNet.getResults()--this is the interesting line.
This just returns a table with the results!

Serialize:

myNet = AI.Net({2,4,1})
myNet.feedForward({1,0})
myNet.backProp({1})
myNet.getResults()
serialized = myNet.serialize() --this is the interesting line.
Serialized is a table that can be written to a file.

Unserialize:


myNet = AI.Net({2,4,1})
myNet.feedForward({1,0})
myNet.backProp({1})
myNet.getResults()
serialized = myNet.serialize()
myNet = nil
myNet = AI.unserialize(serialized) -- this is the interesting line
myNet is a valid and fully working neural network.

Here is a GIF, even if there ain't much to see!

The GIF shows a XOR gate.

Download:

pastebin get GHHCma5U AI

An example program:

pastebin get LRKaMh54 NN

Ideas for improvements:
  • Add a way to save a neural network to a file.
Edited on 12 October 2015 - 07:01 PM
H4X0RZ #2
Posted 10 October 2015 - 04:44 PM
Awesome!
Creator #3
Posted 10 October 2015 - 04:58 PM
Thanks a lot!

An idea I have to improve AI would be to add a way to save the network to a file.
FUNCTION MAN! #4
Posted 10 October 2015 - 05:13 PM
Now make waifu2x for ComputerCraft!
Hm, that'd be rather useless. Make waifu2x IN computercraft!
Edited on 10 October 2015 - 03:13 PM
Creator #5
Posted 10 October 2015 - 05:19 PM
Now make waifu2x for ComputerCraft!
Hm, that'd be rather useless. Make waifu2x IN computercraft!

What is waifu2x?
FUNCTION MAN! #6
Posted 10 October 2015 - 05:26 PM
Can you google?
Edited on 10 October 2015 - 03:27 PM
Creator #7
Posted 10 October 2015 - 05:27 PM
You brought it up, so just tell me.
FUNCTION MAN! #8
Posted 10 October 2015 - 05:28 PM
https://github.com/nagadomi/waifu2x
Creator #9
Posted 10 October 2015 - 05:37 PM
So it allows you to upscale anime pictures?
FUNCTION MAN! #10
Posted 10 October 2015 - 05:41 PM
Yes, using deep convoluted neural networks. It's written in lua, too.
Creator #11
Posted 10 October 2015 - 05:46 PM
Yes, using deep convoluted neural networks. It's written in lua, too.
\

How many input neurons does it have? How many hidden layers?
FUNCTION MAN! #12
Posted 10 October 2015 - 05:52 PM
How should I know? Go study the source!
Creator #13
Posted 10 October 2015 - 06:04 PM
Another day, mate!
Exerro #14
Posted 10 October 2015 - 09:37 PM
This seems pretty awesome, I'm going to play around with it.

Just so you know:

pasetbin get GHHCma5U AI

pasetbin get LRKaMh54 NN
Not everyone has "pasetbin", you should probably give a pastebin download too :P/>.
Edited on 10 October 2015 - 07:37 PM
Imred Gemu #15
Posted 10 October 2015 - 09:54 PM
This seems pretty awesome, I'm going to play around with it.

Just so you know:

pasetbin get GHHCma5U AI

pasetbin get LRKaMh54 NN
Not everyone has "pasetbin", you should probably give a pastebin download too :P/>.
http://pastebin.com/
Exerro #16
Posted 10 October 2015 - 09:57 PM
-snip-
Not everyone has "pasetbin", you should probably give a pastebin download too :P/>.
http://pastebin.com/

I was referring to the typo.
Edited on 10 October 2015 - 07:57 PM
Creator #17
Posted 10 October 2015 - 10:15 PM
@Awesumben13, thanks for the heads-up. I can't believe this happened again. When I released FileX I had written pastebun.
DannySMc #18
Posted 10 October 2015 - 10:26 PM
This is pretty cool, as you work on this more it could become pretty be awesome! :D/>
Edited on 10 October 2015 - 08:27 PM
Creator #19
Posted 10 October 2015 - 10:46 PM
What do you think there is more to work on?
Imred Gemu #20
Posted 10 October 2015 - 11:53 PM
-snip-
Not everyone has "pasetbin", you should probably give a pastebin download too :P/>.
http://pastebin.com/

I was referring to the typo.
Ah, didn't catch that
クデル #21
Posted 11 October 2015 - 07:35 AM
I know a little bit about neural networks, and I love your work, but what does it "learn" from the input?
Creator #22
Posted 11 October 2015 - 09:49 AM
It learns from back propagation. You basically give it the expected result and it adjusts.
クデル #23
Posted 11 October 2015 - 09:55 AM
It learns from back propagation. You basically give it the expected result and it adjusts.

Adjusts, in hoping that it can anticipate the next result based on the two previously inputted numbers?
Creator #24
Posted 11 October 2015 - 09:57 AM
Yeah kinda.
クデル #25
Posted 11 October 2015 - 10:06 AM
Neat, good job! +1 :D/>
Creator #26
Posted 11 October 2015 - 10:42 AM
Thanks.

I now realize I should have let the dem in the gif run longer.
Edited on 11 October 2015 - 08:42 AM
Lupus590 #27
Posted 11 October 2015 - 03:43 PM
I'm trying to think of a MC application for this, perhaps task prioritisation in Hive? I know that neural networks are used for fussy data (something that doesn't exist in any game) so maybe there are none for MC? Turtle learning?
Creator #28
Posted 11 October 2015 - 03:45 PM
I have not thought about Hive. Maybe that'll will work. Could I help with the project in General?
Creeper9207 #29
Posted 11 October 2015 - 04:12 PM
I wonder how this could be used to make an assistant
Creator #30
Posted 11 October 2015 - 04:46 PM
Difficultly?

What kind of assistant?
H4X0RZ #31
Posted 11 October 2015 - 04:50 PM
Difficultly?

What kind of assistant?
I guess he's talking about something like Siri.
Lupus590 #32
Posted 11 October 2015 - 04:53 PM
I have not thought about Hive. Maybe that'll will work. Could I help with the project in General?
The project is at a stand still at the moment, I'm thinking of changing how collaborators add code. Jump into gitter and we'll talk more.
gollark8 #33
Posted 11 October 2015 - 04:55 PM
Having seen this, I'm wondering about using this to make a turtle find optimal strategies for mining, by having the neural network's numbers be used as turtle action codes, and having all the turtle's actions being back-propagated into the network after it finds ore.
Edited on 11 October 2015 - 02:55 PM
Creator #34
Posted 11 October 2015 - 05:15 PM
Omg, that is smart! I could help you implementing it.
gollark8 #35
Posted 11 October 2015 - 06:06 PM
How can I save the neural network state to a file? Textutils serialisation?

By the way, is there documentation available?
Creator #36
Posted 11 October 2015 - 06:14 PM
1. I will be writing code allowing you to save it to a file.

2. All the explanation needed is in the description. If you still do not understand something, just post it here and I will respond.

PS: This is my 1111th post. Yay.

Textutils is not possible since the network is not a table, but rather a class system, which has locals.
Edited on 11 October 2015 - 04:16 PM
gollark8 #37
Posted 11 October 2015 - 09:09 PM
The API is giving me horribly useless errors. "Mate you are coding like a girl" is no use whatsoever when you're trying to debug code.

Edit: {5,5,5} neural net, feed-forwarding random numbers from 1 to 10 in every cycle, math.ceil()-ing the result, and I'm constantly getting 1.
Edited on 11 October 2015 - 07:45 PM
Creator #38
Posted 11 October 2015 - 09:11 PM
The issue is that when you call the feedforward function, you have to give a table as an argument. That table should contain the same amount of numbers as the input layer has neurons.
Creator #39
Posted 11 October 2015 - 09:17 PM

myNet = AI.Net({2,4,1})
myNet.feedForward({1,0})

There are 2 elements in the table given as an argument to the second function like there are two input neurons.
gollark8 #40
Posted 11 October 2015 - 09:53 PM
The issue is that when you call the feedforward function, you have to give a table as an argument. That table should contain the same amount of numbers as the input layer has neurons.

myNet = AI.Net({2,4,1})
myNet.feedForward({1,0})

There are 2 elements in the table given as an argument to the second function like there are two input neurons.

In that case, it should give me that as an error, not what it gave me.
Creator #41
Posted 11 October 2015 - 09:55 PM
Don't be so serious. It's only a joke.
gollark8 #42
Posted 11 October 2015 - 10:19 PM
Don't be so serious. It's only a joke.
But how can I use an API if its errors are meaningless?
Creator #43
Posted 11 October 2015 - 10:22 PM
Fine, I'll change it tomorrow. Actually I won't. Haxor just said why.
Edited on 11 October 2015 - 08:32 PM
H4X0RZ #44
Posted 11 October 2015 - 10:30 PM
Don't be so serious. It's only a joke.
But how can I use an API if its errors are meaningless?

If you would've looked at the source, you would've seen that this error only occurs on one line, and only under really specific circumstances so it actually has a meaning. It's just not a "Oh, you need x instead of y when calling this function" but "Hey, here's a joke for you because I only appear when you mess x up, so I don't have to inform you about the details" kind of error message.


assert(#inputVals == #m_layers[1],"Mate, you are coding like a girl! Just joking, girls can code too... not like you!")
Creator #45
Posted 11 October 2015 - 10:32 PM
Exactly. There is only so much you can mess up without messing up Lua itself. Like an error because you indexed nil.
Lupus590 #46
Posted 11 October 2015 - 10:46 PM
Still useful error messages help a lot, by all means tag the joke on the end but make it so that I don't have to search the source for the line that flags the error and then try and decode what would cause that line. Just tell me what I did wrong and what I should be doing, then you can insult me and over half of the human race.

Actually your joke could be taken as sexist, you may want to be careful about that. On a related note: you may not want to insult your users, just saying.
Edited on 11 October 2015 - 08:51 PM
Creator #47
Posted 11 October 2015 - 11:03 PM
I do say that girls can code and that the only person who can't is you. However, I am sorry if I offended anyone. And will add what you did wrong.
Creator #48
Posted 12 October 2015 - 08:56 PM
New version 1.1:
- adds the ability to transform the Neural Network into a table.
- adds the ability to create a neural network from a table.

How to:

Serialize:

myNet = Net({2,4,1})
--train it
serialized = myNet.serialize()
Serialized is a table that can be written to a file.

Unserialize:

myNet = Unserialize(serialized)
myNet is a valid neural network.
gollark8 #49
Posted 12 October 2015 - 10:22 PM
New version 1.1:
- adds the ability to transform the Neural Network into a table.
- adds the ability to create a neural network from a table.

How to:

Serialize:

myNet = Net({2,4,1})
--train it
serialized = myNet.serialize()
Serialized is a table that can be written to a file.

Unserialize:

myNet = Unserialize(serialized)
myNet is a valid neural network.

But does it have error messages that don't make you dig through the source of the API in an attempt to find out what's wrong?
Edited on 12 October 2015 - 08:22 PM
Creator #50
Posted 13 October 2015 - 05:28 AM
New version 1.1:
- adds the ability to transform the Neural Network into a table.
- adds the ability to create a neural network from a table.

How to:

Serialize:

myNet = Net({2,4,1})
--train it
serialized = myNet.serialize()
Serialized is a table that can be written to a file.

Unserialize:

myNet = Unserialize(serialized)
myNet is a valid neural network.

But does it have error messages that don't make you dig through the source of the API in an attempt to find out what's wrong?

Just let it go with these error messages. I mean, should have been more precise about the only error message given to the user, but I hope you won't be posting this all the time.
Creator #51
Posted 13 October 2015 - 10:07 PM
I fixed a small issue with serialize and unserialize. However, I will be posting the new code tomorrow because of "it's 00:06 o'clock" reasons.
Creator #52
Posted 14 October 2015 - 11:06 PM
Hi guys I just want to give you a quick glimpse of the first official program that uses AI: TicTacToe!

pastebin:

pastebin get TFxkELib TTT

To the moderators: please do not create a new thread for the game. I will do it myself tomorow, I promise. Thank you for undersatnding me.
FUNCTION MAN! #53
Posted 15 October 2015 - 01:04 AM
It doesn't seem very adaptive. I've won like 20 times with the same combination: 1, 2, 3.
Creator #54
Posted 15 October 2015 - 05:37 AM
I know. That is an issue I am working on. However, it does learn.
Creator #55
Posted 15 October 2015 - 07:29 AM
Today, I will modify it so that it plays against a random player and learns automatically.
Waitdev_ #56
Posted 15 October 2015 - 10:44 AM
cleverbot anyone? please?

do it for etho?
Creator #57
Posted 15 October 2015 - 10:53 AM
Cleverbot? Do you know the size of the database you'd need? And the size of the neural network? And the computing power?
Andrew2060 #58
Posted 15 October 2015 - 12:27 PM
Hey,

Well I looked through your entire topic and many others regarding AI Programs.
I understand the entire concept of how these things function and work now too.
I really like yours though.

I was hoping to find a way to give a single computer full access of my defensive and offensive networks.
Without any manual input because it seems that my friends can't stop fiddling with my submarines PC's.

So I mean this is how I think mine would work, correct me if I'm wrong please.

1. Boot up and handshake with both offensive and defensive systems networks. (Ping-pong responses).
2. Record Data based on friendly/enemy missile interceptions, enemy launch counts, launch frequency etc.
3. Use equations and filters to narrow down the possible locations of enemy missile silos.
4. Assess which silo is more dangerous by judging their launch count and average missile type.
5. Possibly probe silo by firing test missile and await for its interception ( interception would be confirmation silo exists).
6. Continue analysing data even if a threat is imminent, (defense system will work on autopilot until bypassed byPC).
7. Create an effective database which can be used for target selection by the offensive system.
8. Create an effective database that can be used to prioritise defensive counter measures.
9. Maybe instruct personnel on options to take? Or make decisions on its own.

I mean I know what to do in this but I'm not the best with databases or well equations.

So basically crap tons of data are organised and analysed, then used to interpret threats.
Edited on 15 October 2015 - 10:28 AM
Creator #59
Posted 15 October 2015 - 12:46 PM
In order to treason the network you d need to provide possible input and provide the according output. When the real threat comes the network will be trained and it will work on it's own.
Andrew2060 #60
Posted 15 October 2015 - 01:04 PM
True or it could just sit and learn from actual threats until say autopilot is disabled, then it would learn and respond.
Creator #61
Posted 15 October 2015 - 02:34 PM
In order to learn it also needs the expected result.So letting it be trained on its own is not an excellent idea.
Creator #62
Posted 16 October 2015 - 05:44 AM
Someone voted they don't like the implementation. What don't you like and what could be changed in your opinion?
Andrew2060 #63
Posted 16 October 2015 - 09:18 PM
Someone voted they don't like the implementation. What don't you like and what could be changed in your opinion?

Probably some hater that wants to undermine you or is scared of mine craft computers killing him in his sleep.
I only see good applications in this as it saves people from doing any work seeing how lazy we are :P/>
Anyway wasn't me, I gave you a yes for both.
Creator #64
Posted 16 October 2015 - 09:54 PM
Someone voted they don't like the implementation. What don't you like and what could be changed in your opinion?

Probably some hater that wants to undermine you or is scared of mine craft computers killing him in his sleep.
I only see good applications in this as it saves people from doing any work seeing how lazy we are :P/>
Anyway wasn't me, I gave you a yes for both.

Well, actually I was not afraid of some hater. I was rather curious if someone found something that could have been improved.

Anyways, thanks for the support.
Creator #65
Posted 17 October 2015 - 05:53 PM
Integrated AI into OmniOS so if anyone wants to use AI and an OS at the same time, download OmniOS. By the way, OmniOS also provides useless stuff as multitasking, inter-thread messaging and a custom FS. Why all of this? So you can use AI in various instances at the same time!
justync7 #66
Posted 18 October 2015 - 06:13 AM
How would I create an AI which can learn to predict lua's psuedo math.random?

EDIT: No, Im not asking to be spoon-fed code, I just don't understand how this works and my current code just starts the output at 0.8 and slowly evens out to 1.0
Edited on 18 October 2015 - 04:18 AM
Bomb Bloke #67
Posted 18 October 2015 - 08:34 AM
I guess you'd need to feed in inputs representing the seed and the number of math.random() calls made using it, and an expected output of whatever value that combination would produce.
justync7 #68
Posted 18 October 2015 - 09:04 AM
I guess you'd need to feed in inputs representing the seed and the number of math.random() calls made using it, and an expected output of whatever value that combination would produce.
Tried this, theres no way to even get a number >1 from this api…
Creator #69
Posted 18 October 2015 - 09:32 AM
I guess you'd need to feed in inputs representing the seed and the number of math.random() calls made using it, and an expected output of whatever value that combination would produce.
Tried this, theres no way to even get a number >1 from this api…

You can use binary.

By the way, you would need to train it at least a thousand time to make the output increase with a unit.
Creator #70
Posted 24 October 2015 - 04:00 PM
By the way I have an idea how to make TicTacToe work. I let it play normally. At the ned, if it won, I validate the moves, if not I don't.
Bomb Bloke #71
Posted 25 October 2015 - 12:09 AM
As I mentioned in your Tic-Tac-Toe thread, you'd be better off writing an AI that already plays perfectly, and having your NeuralNetwork watch its moves until it can match it.

That way, you'll be able to "validate" every game - you also won't be feeding it "bad" data from games which it technically won, but should have lost (that is to say, cases where the opponent lets it win).
Creator #72
Posted 25 October 2015 - 12:11 AM
Ok, so it should learns form a perfect min-max bot?
Bomb Bloke #73
Posted 25 October 2015 - 12:16 AM
If that's how you want it to end up playing, most certainly.

The "perfect" AI should play a fair few games against an AI that plays randomly. The idea is that the Network should be taught the best move for every possible board layout - if you pit the perfect AI against itself, the Network will never learn how to win!

Fortunately, what's "possible" will be limited somewhat by the perfect AI forcing the other player into a corner within a few moves.
H4X0RZ #74
Posted 25 October 2015 - 01:01 PM
Btw, here is something interesting achieved with Neural Networks. (IMO)
http://soumith.ch/eyescream/
Do you think it would be possible to port that to CC? XD
Creator #75
Posted 25 October 2015 - 01:16 PM
If it can be done with a neural network, it can be done in CC.
Lupus590 #76
Posted 03 November 2015 - 09:35 PM
Does this neural network only accept and output numbers? Or can I use chars/strings too?
Edited on 03 November 2015 - 08:35 PM
Creator #77
Posted 03 November 2015 - 10:25 PM
The input can be Analoge, so you have to find a way to represent the string through a series of analogue signals. Or you transform it to binary, which would be more reasonable.
Rougeminner #78
Posted 09 November 2015 - 01:38 PM
Probably Incredibly stupid question warning!

Is this applicable to a turtle for AI Mining, sorry for the questions level of stupidity i am just now trying to get started in AI code and applications,

EDIT: NVMD didn't completely read entire forum page, someone already asked. i derped my bad
Edited on 09 November 2015 - 01:08 PM
Creator #79
Posted 09 November 2015 - 02:34 PM
Well, the question is "Is there a pattern and can it be learned?". If the answer is yes, then you can use AI, if not, as the case is with randomly generated ores, then no.
H4X0RZ #80
Posted 09 November 2015 - 11:06 PM
Well, the question is "Is there a pattern and can it be learned?". If the answer is yes, then you can use AI, if not, as the case is with randomly generated ores, then no.

Ores aren't too randomly spread. There are certain possibilities for n-sized clusters to appear n-times per chunk. You could look that stuff up in the MC source.
Rougeminner #81
Posted 10 November 2015 - 05:08 AM
well more or less what i was trying to do was a project to get myself used to this, it took me a while just to understand what the numbers represented in NN and i still don't fully get it :P/>
Creator #82
Posted 10 November 2015 - 05:13 AM
Which numbers exactly?
H4X0RZ #83
Posted 10 November 2015 - 07:12 AM
Which numbers exactly?
Here is a block distribution graph: http://hydra-media.cursecdn.com/minecraft.gamepedia.com/1/16/Block_layers_overworld_1.5.svg

And a quote from the MC forums:
(1:0),Stone,5229129
(1:1),Stone,278532
(1:3),Stone,269447
(1:5),Stone,293764
(3:0),Dirt,334311
(13:0),Gravel,88583
(14:0),Gold Ore,3611 (9.03 ore per chunk, +10%)
(15:0),Iron Ore,38577 (96.4 ore per chunk, +25%)
(16:0),Coal Ore,74691 (186.7 ore per chunk, +31%)
(21:0),Lapis Lazuli Ore,1490 (3.73 ore per chunk, +9%)
(56:0),Diamond Ore,1376 (3.44 ore per chunk, +10%)
(73:0),Redstone Ore,10567 (26.4 ore per chunk, +6.4%)
Edited on 11 November 2015 - 11:19 AM
Creator #84
Posted 10 November 2015 - 07:48 AM
Since there is a pattern, there also is a way to train it. I will explain it after school when I am on my PC.
Rougeminner #85
Posted 11 November 2015 - 06:03 AM
so i am trying to learn this stuff and i literally just started yesterday because i saw your thread and i have a few beginning questions, how to i teach it the appropriate outcome, second what do your numbers mean i think they represent probability but of what (if i am completely wrong please say so i will miserably fail over and over until i get it right though in the case of an AI it will take a life time :P/>) thanks in advance. Rougeminner



oops i didn't even see the conversation from my second post, i mean the numbers when you tell it the first input is 1400 and the second is 1000 it simply replies with a number <1 and i just can't figure that one out like i said i think its probability but of wut?
Edited on 11 November 2015 - 05:04 AM
クデル #86
Posted 11 November 2015 - 06:29 AM
You should include an expected result, for training purposes and a fitness level or something.
Bomb Bloke #87
Posted 11 November 2015 - 06:31 AM
To my limited understanding, you put a number in, it gives you a number out, and you also tell it what number you actually wanted out. The more times you tell it "this input should result in this output", the closer its output will actually get to your desired result, as it'll adjust itself a little each time you repeat the process.

The idea is that by teaching it a great variety of inputs and associated outputs, it should eventually catch on to whatever pattern it is you're following and start to produce the right outputs for inputs you haven't shown it before, without having to be shown the expected outputs at all. But there has to be a pattern to the numbers you're feeding in, as feeding garbage in will only get you garbage out.

(Think of it as being like teaching a person - show them how to hammer a red nail, then show them how to hammer a green nail, and odds are they'll have a pretty good idea what to do with blue nails before you tell them.)

For example, with something like TicTacToe, there are just two rules to follow ("make lines of three" and "don't let the opponent make lines of three") - but there are so few moves that're actually worth making that it's easier just to teach a network all the best moves (each one being simple) than it is to try and teach it those rules (which are relatively complex).

With something like waifu2x (an NN-based image upscaler), things get a bit more complex. There are TONS of patterns - certain alignments of pixels should result in certain other alignments of pixels, based on which other alignments of pixels are nearby, and so on. By saving (lots of!) high-res images in low-res and feeding the pairs in as the expected outputs and inputs respectively, a correctly setup network (someone's got to translate the numbers for it!) should eventually be able to produce decent looking high-res images from low-res ones without ever seeing the original high-res versions (dead handy if you didn't have the originals in the first place!).
Lyqyd #88
Posted 11 November 2015 - 08:02 AM
I think waifu2x is a great example of one of the two hardest problems in programming (and it's not the cache invalidation one).
Rougeminner #89
Posted 11 November 2015 - 08:39 AM
so, if i do
myNet.feedForward({1000,100})
myNet.backProp({.5})
it should learn that 1000,100's output should be five?
(its me thats learning not the AI)
Bomb Bloke #90
Posted 11 November 2015 - 08:44 AM
I think waifu2x is a great example of one of the two hardest problems in programming (and it's not the cache invalidation one).

Ah, it'll be the off-by-one error, then!
Creator #91
Posted 11 November 2015 - 09:53 AM
so, if i do
myNet.feedForward({1000,100})
myNet.backProp({.5})
it should learn that 1000,100's output should be five?
(its me thats learning not the AI)

The dlidea is that you give many examples so the AI can find a pattern and react accordingly.
Rougeminner #92
Posted 11 November 2015 - 11:38 AM
So what am i teaching it exactly? Like i said i am just starting and i am in the screw around with it phase of my learning method, so in english what pattern is it would it be something like 1000 and 100 = .5?
Creator #93
Posted 11 November 2015 - 12:11 PM
Let's say you want to teach it XOR.
The net has this configuration: 2 4 1
Then then in puts and outputs look like this
0 0 : 0
1 1 : 0
1 0 : 1
0 1 : 1

After passing these inputs a few hundred times, the network will learn.
H4X0RZ #94
Posted 11 November 2015 - 12:17 PM
So what am i teaching it exactly? Like i said i am just starting and i am in the screw around with it phase of my learning method, so in english what pattern is it would it be something like 1000 and 100 = .5?

//Kinda-Off-Topic
IIRC you asked what the stuff I posted meant (or how to utilize it).

In the quote you can see how many blocks of an ore are found in one chunk (±some percent). Using the chart you can see on which "layers" it's more probable to find a specific ore.

That *should* allow you to tell your "AI" 1. on which layer a specific Kind of ore can be found and 2. how many blocks of that ore appear.

Although this isn't too usable when mining for multiple ores at the same time, it should allow you to get one specific ore "fast". (Like skipping chunks you already farmed n-blocks.)
Edited on 11 November 2015 - 11:18 AM
LeDark Lua #95
Posted 11 November 2015 - 12:20 PM
Does this neural network only accept and output numbers? Or can I use chars/strings too?
Actually this should output 1/0 or true/false.
Edited on 11 November 2015 - 11:21 AM
Rougeminner #96
Posted 11 November 2015 - 12:32 PM
So by saying myNet.backProp({.5}) thats telling it the output thanks i think i finally got myself a small enough foundation to build of of once i really took a look at creators port
The net has this configuration: 2 4 1
Then then in puts and outputs look like this
0 0 : 0
1 1 : 0
1 0 : 1
0 1 : 1

oh and one more thing, i tried doubling the net configuration myNet.Net({4,8,2}) and this didn't work so well, what did i do wrong? is it the two output neurons?

also words don't explain how stupid i feel… i went back and looked at NN had i taken the time to look i would have noticed that thats an XOR
Edited on 11 November 2015 - 11:56 AM
Creator #97
Posted 11 November 2015 - 12:56 PM
Why did you double it?
Rougeminner #98
Posted 11 November 2015 - 01:09 PM
to see what would happen just experimenting i now know that doubling it is bad but i can't figure out why
Rougeminner #99
Posted 11 November 2015 - 01:36 PM
<NOOB Concept>
If i convert the input text from read to ASCII numbers for example A OK is 65 79,75 and i put them together like so

myNet.feedForward({65,7975}) -- this is A OK in numbers
myNet.backProp({71797968}) -- this is Good in numbers
then i could interpret it back to char's and then have a texting AI? is this a valid concept (correct me if i got the numbers wrong please)
Creator #100
Posted 11 November 2015 - 01:49 PM
The input should be binary. I think it can work with bigger/smaller numbers but it is preferable to use binary. Also, when inputting text, take each character and convert it to binary (255 ==> 10000000 OR 4 ==> 00000100) Then, you take each binary number (00000100 ==> {0,0,0,0,0,1,0,0}) and put them in a table. Then you net.feedForward({0,0,0,0,0,1,0,0})

Also, some users have voted they didn't find this implementation good. I'd like to know what you didn't like, so I can optimize/change the code.
Rougeminner #101
Posted 11 November 2015 - 02:13 PM
ok thanks.
Lupus590 #102
Posted 11 November 2015 - 02:18 PM
May I suggest adding a way to input strings and numbers and have it output likewise?
Creator #103
Posted 11 November 2015 - 02:27 PM
Well, I could do it. It is a good idea. Thanks for the suggestion! More of these are welcome.

rougeminer, congrats, you posted the first 100th reply to any of my programs.

I just thought of it. The string can only be of a certain length. Not longer, not shorter.
Rougeminner #104
Posted 11 November 2015 - 03:41 PM
well Lupus depending on what u mean i am making a program right now that converts txt to bin and it won't work to well until creator releases the ability to save the AI to a file, but i am close to done right now, as long as feedForward can take more than 2 args i should be good i will share the code with u

thx creator i didn't know that
Edited on 11 November 2015 - 02:41 PM
Creator #105
Posted 11 November 2015 - 03:55 PM
The AI can be save to a file. myNet.serialize()
Rougeminner #106
Posted 11 November 2015 - 06:45 PM
… I missed the memo… How can i put a table of varying size into feedforward i did feedforward(tbl) and it gave me ur error message
Creator #107
Posted 11 November 2015 - 06:48 PM
You can't. Once you define the number of input neurons, you have to give the same amount of inputs.
Rougeminner #108
Posted 11 November 2015 - 07:13 PM
Oh. Ok thanks so inputnpins need to equal the contents of the table or i need to step back and rethink
Creator #109
Posted 11 November 2015 - 07:19 PM
The first one.
Rougeminner #110
Posted 11 November 2015 - 09:08 PM
is there anyway to feed the AI a table of binary numbers instead of putting them all in it?
Creator #111
Posted 11 November 2015 - 09:12 PM
What exactly do you mean? Aren't the two things you said the same?

Please provide an example for both cases.
Rougeminner #112
Posted 11 November 2015 - 09:13 PM
its kinda hard to ask, let alone understand, by default u do feedForward({1,2}) what if i wanted to feed forward a separate table could i just to feedForward(tbl)?
Creator #113
Posted 11 November 2015 - 09:15 PM
Well, if tbl = {1,2} then it is possible.
Rougeminner #114
Posted 11 November 2015 - 09:33 PM
so i need it to return binary to be specific 01101000 01100101 01101100 01101100 01101111 (hello), but when i stuck it into the AI it always no matter what returned a number less that one, what am i missing?
i did myNet.feedForward({0110100001101001} and myNet.backprop({short for binary hello,}) and cycled it 1500 times and its still > 0.985313? i am confused


basically i am trying to turn your AI into a text based AI so that the user says Hi it translates to binary then sends a hello back to the player.
Edited on 11 November 2015 - 08:37 PM
Creator #115
Posted 11 November 2015 - 09:45 PM
Well, can you use the function net.serialize() and serialize the table and post it here so I can check what is wrong? Or better, post it on pastebin and notify me here when you've done so.
Rougeminner #116
Posted 11 November 2015 - 09:48 PM
i have tried to avoid pastern because of every time i have been plagiarized is it ok if i PM u the code later tonight?
Creator #117
Posted 11 November 2015 - 09:49 PM
It sure is. However not too late because it is 23:48 here.
Rougeminner #118
Posted 11 November 2015 - 10:02 PM
yikes ok. i thought u where east coast time
Creator #119
Posted 11 November 2015 - 10:03 PM
What time are you?
Konlab #120
Posted 13 November 2015 - 03:22 PM
how can a larger number of hidden neurons affect the results?
like for xor:
2,4,1
vs.
2,100,1
what will be the difference?

edit: I counted Creator's position:
~Hawaii GMT+2 Eastern Europe Time
edit2: 12 hour system fail I didn't counted the PM
Edited on 13 November 2015 - 02:28 PM
Creator #121
Posted 13 November 2015 - 03:34 PM
It will be slower. I read a thing that the number of neurons in the middle layer has to be equal to the number of possibilities.
Rougeminner #122
Posted 15 November 2015 - 08:46 PM
quick question eventually once i teach the AI enough it will be able to answer a "equation" with out the answer to it correct?

and is the AI built off the ANN method?
Creator #123
Posted 15 November 2015 - 09:05 PM
There is one thing you have to understand about neural networks, they can't magically solve equations, or output a response to a string you input. In order to have this, you'd need a much bigger NN with memory and all. This version can detect patterns, like figuring out the letters in a recording, or predicting the stock market.
Rougeminner #124
Posted 15 November 2015 - 09:29 PM
ok, thanks so i have to teach it literally everything it will learn? It won't pick up on things automaticity correct?
Creator #125
Posted 15 November 2015 - 09:35 PM
What do you mean?
Rougeminner #126
Posted 15 November 2015 - 11:09 PM
i was trying to ask if it will pick up on things over time like if i teach it 1+1 equals 2 and 2+2=4 will it learn 1+2 = 3 on its own with out my assistance
Creator #127
Posted 16 November 2015 - 05:48 AM
It will not. This is the way it learns: you give it a certain input and output. If you repeat this enough times, AI will catch the pattern and respond to new input accordingly.
Rougeminner #128
Posted 16 November 2015 - 12:43 PM
ok, thanks
Creator #129
Posted 16 November 2015 - 02:20 PM
You're welcome.

Well guys, there are some good news. I am adding a file format related to the AI API: .aidata. Basically what it allows you to do is to store training data. The format looks like this:


<input>"="<output>

where input and output have the correct number of elements. Also for best performance, input and output should be binary.
Creator #130
Posted 26 November 2015 - 04:28 PM
Furthermore, I have created an organization for AI. This organization will focus on the following things:
  • Managing the API itself
  • Creating a release for standard Lua/Love2D
  • Different training sets. Currently I have finished the one used to recognize handwritten in CC. Another one for standard Lua/Love2D will be added with your help.
  • Any other great idea you have.
Anyone wishing to join or help, should respond to this thread with the following info:
  • GitHub username
powerboat9 #131
Posted 27 November 2015 - 02:29 AM
Thanks. Do you have an MIT license? It's probably a good idea.
Edited on 27 November 2015 - 01:42 AM
powerboat9 #132
Posted 27 November 2015 - 02:39 AM
GitHub username: powerboat9
Creator #133
Posted 27 November 2015 - 08:20 AM
Will be adding you ASAP. Thanks for joining.

Ok, added you.

Quick update:


The data for Character recognition is done. That is each character and letter and their variations. For example, a can be:

111
1 1
111
1 1
1 1

OR


  1
1 1
111
1 1
1 1

Also the the Neural Network has been trained d 10 000 times for each character, number and their variations. However, the network still returns 1s for an unknown reason.
Rougeminner #134
Posted 10 December 2015 - 01:52 AM
wow, pretty quick advances in this AI quick question, what other Advanced things are you planning to do with this AI i don't mean features i mean projects. also is there a possibility you could include a planned features spoiler to the main post so we can know what to expect?
Edited on 10 December 2015 - 12:54 AM
Creator #135
Posted 10 December 2015 - 05:32 AM
Ok, I will do that. Nice idea.




Hint: Character recognition.
wilcomega #136
Posted 05 January 2016 - 09:13 PM
here are a few practical minecraft idea's:
  • Turtle + Camera Peripheral = living creature?
  • Audio Tape Peripheral = music producing computer?
  • Command computer player data = analyzing player's actions for turtles to replicate
  • Command computer level builder = ai generated mazes and dungeons?
  • Quadcopters??? idk
  • Enryption api = encryption breaking ai?
  • teach it to play the simple games from the forum = best high score ever?

just thinking about more practical minecraft applications.

also github username: wilcomega
Creator #137
Posted 05 January 2016 - 09:48 PM
Added you!
  1. Camera: You have to train it to react to different situations. Then yes.
  2. Audio: There is no input. Software written for that will be more effective.
  3. Turtles: So like reacting to certain patterns? Yes!
  4. Maze: Actually possible. Given a table with the already present blocks, it can generate more of those.
  5. Quad-copters: Again, you need a stream of consciousness input.
  6. Encryption: not really. The way it works in=s known. I don't think there is a way to teach AI to discover weaknesses. Also it would be unusable for password cracking. The better option would be brute-force attacks.
  7. Games: possible if given enough training.
ReBraLaCC #138
Posted 17 March 2016 - 05:12 PM
What are you able to do with it? like use it in games for enemies or ?
Creator #139
Posted 17 March 2016 - 05:20 PM
You have to teach them a pattern, and the neural network will learn it accurately enough. Visit this page for a better explanation.
Cross_Sans #140
Posted 23 March 2016 - 05:38 PM
Sorry, but i don't understand the "usage" of this thing. Can you explain me ?
Creator #141
Posted 23 March 2016 - 06:07 PM
Sorry, but i don't understand the "usage" of this thing. Can you explain me ?

The basic idea of neural networks is that you train them to react in certain ways when certain input is given. For example, you can train the xor function, or you can make it determine whether a cookie is good enough for sale based on a picture. To train them, you have to give them tons of sample input with corresponding output.
Cross_Sans #142
Posted 23 March 2016 - 07:03 PM
Sorry, but i don't understand the "usage" of this thing. Can you explain me ?

The basic idea of neural networks is that you train them to react in certain ways when certain input is given. For example, you can train the xor function, or you can make it determine whether a cookie is good enough for sale based on a picture. To train them, you have to give them tons of sample input with corresponding output.
Thanks for the responce :)/>
Creator #143
Posted 23 March 2016 - 07:04 PM
No problem!

By the way: response.
Cross_Sans #144
Posted 24 March 2016 - 11:39 AM
response
Oh, thanks ! If i'm making errors, it's because i'm from France, (i'm a french by the way ;)/> ).
Sewbacca #145
Posted 05 July 2018 - 01:03 PM
I have two questions related to this code:

myNet = AI.Net({2,4, 8, 16,1}) -- What will hapen here and how are the neurons connected?
myNet.feedForward({1,0}) -- Just 1 and zero are allowed values?
myNet.backProp({1})
myNet.getResults()
SquidDev #146
Posted 07 July 2018 - 06:01 AM
What will hapen here and how are the neurons connected?
This creates a network with 2 inputs, 1 output and 3 hidden layers, with 4 8 and 16 neurons respectively. Every neuron in one layer is connected to every neuron in the next (so the 2 inputs are connected to the 4 neurons in the 1st hidden layer, those 4 to the 8 neurons in the next, etc…)

Just 1 and zero are allowed values?
Any value is allowed. However, as Creator is trying to train it on binary functions, only 1 and 0 really make sense as inputs.
ToxicC00kie1001 #147
Posted 09 December 2018 - 10:14 PM
How do I go about setting an objective for the ai? ex: Get 'x' value as high as possible. I'd also like to know how to go about telling it what it can use like certain functions and such. ex: Use function1(), function2(), etc. In the end should be something like: Get 'x' as high as possible using function1(), function2(), etc.