Advertisement

Artificial Neural Network and NPC AI

Started by July 30, 2006 08:22 AM
12 comments, last by jolyqr 18 years, 6 months ago
Basically I'm doing a project which consist in developing a NPC controlled by an ANN. The ANN is controlled by a class. The net has got 3 units: -1 input unit of 7 neurons (x1, x2, x3, x4, etc.) -1 hidden unit of 2 neurons (z1 and z2) -1 output unit of 4 neurons (y1, y2, etc.) The net input data are : -player life -npc life -player weapon -npc weapon -distance between player and npc -player state -npc state The net outputs are: -npc flees the player -npc attacks -npc search for items -npc follows the player The goal of the net is to change the npc states. Ex: making the npc attack or flee according to the inputs. After being trained with more than 50 patterns, some problems happened. The weights found seemed too big, indeed some weights were equal to 5000. It resulted to a bad generalisation. So the NPC became weird, started to attack the player even though he was not in its line of sight. I don't think I did some mistakes in my formulas... Please help me.... cheers !!
If you train your net the right way, either your net topology is wrong,
or you have a solutionset which is impossible.

Enourmus node weights is a result of one of these...
The wrong topology actually makes the solution impossible,
so there is no way to map the full solution onto the net, it is just
impossible. When there are no possible solutions, weights often go of to
crazy values (and still bad results)

To me, 2 hidden nodes is a little to few for this problem,
i think i would go for 4 or 5....

are input and output bits or floats?
-Anders-Oredsson-Norway-
Advertisement
input values are binary so they stay betwee O and 1.
It's the same for output values. Basically are you suggesting me to add three neurons in my hidden unit?
binary = 0 _or_ 1, not between 0 or 1 :-)

what i think would be a good idea is to learn your net the 50 patterns, and then test it to see if it got all of them right! At what level do you stop training? 80% 90% 100%? If you cant reach 100% with your patterns (and all patterns contains your wanted output from a givven input) then the net cant hold the solution, and if this is true, adjusting the number of hidden units is a good idea (my gut tells me that you need 4 or more) Also, you should train the net with alot of different initial random values, so that you get the global maximum, and not a local maximum... Basically, i would create a small trainer, which tries 1000s of combinations of initial values and number of hidden nodes, then leave it over night, and make it save the best results (top 15 messured in correctness 100% over training data, and the time (iterations) it used to get there...) This way, the system do most of the work, and you only need to do the final testing! If your results still are wrong, you probably need to apply more patterns for training. Also remember that too many hidden nodes can overspecialize your net, ill guess that from 3 to 5, you should get nice results.

Good luck :-)

-Anders
-Anders-Oredsson-Norway-
Think of it this way. You have two hidden nodes. These nodes are linear sums of the input vector. Do you believe there is sufficient resolution in the partition space of a plane to handle the combinatorics of the input space? I don't. From my experience, I expect when permitting structural variation in the network learning, to find a good solution with the number of hidden nodes anywhere between sqrt(m) and m^2, where m is the length of the input vector (if you were using an RBF, you would expect this to go as high as T for an optimal solution, where T is the size of the training set!). Minimising this number is not always the best approach either, since it forces widespread over-generalisation. Maximising the number causes over-fitting. You need to find the balance between the two appropriate to your problem.

Cheers,

Timkin
Quote:
Original post by uncutno
binary = 0 _or_ 1, not between 0 or 1 :-)

what i think would be a good idea is to learn your net the 50 patterns, and then test it to see if it got all of them right!
-Anders

That's what I'm trying to do.

Quote:
At what level do you stop training? 80% 90% 100%?

I'm stopping the training if the epoch number is greater than 1000 or when the new weights calcutlated aren't greater than the old one

Quote:
If you cant reach 100% with your patterns (and all patterns contains your wanted output from a givven input) then the net cant hold the solution, and if this is true, adjusting the number of hidden units is a good idea (my gut tells me that you need 4 or more)


I've got now 7 hidden neurons.

Quote:
Also, you should train the net with alot of different initial random values, so that you get the global maximum, and not a local maximum... Basically, i would create a small trainer, which tries 1000s of combinations of initial values and number of hidden nodes, then leave it over night, and make it save the best results (top 15 messured in correctness 100% over training data, and the time (iterations) it used to get there...)


That's quiet technical. What do you mean by best result? How to reach the 100% ?


Quote:
This way, the system do most of the work, and you only need to do the final testing! If your results still are wrong, you probably need to apply more patterns for training. Also remember that too many hidden nodes can overspecialize your net, ill guess that from 3 to 5, you should get nice results.

Good luck :-)
Advertisement
Quote:
Original post by Timkin
Think of it this way. You have two hidden nodes. These nodes are linear sums of the input vector. Do you believe there is sufficient resolution in the partition space of a plane to handle the combinatorics of the input space? I don't. From my experience, I expect when permitting structural variation in the network learning, to find a good solution with the number of hidden nodes anywhere between sqrt(m) and m^2, where m is the length of the input vector (if you were using an RBF, you would expect this to go as high as T for an optimal solution, where T is the size of the training set!). Minimising this number is not always the best approach either, since it forces widespread over-generalisation. Maximising the number causes over-fitting. You need to find the balance between the two appropriate to your problem.

Cheers,

Timkin



okay. you're trying to say that the hidden neurons have to belong to the interval:

[sqrt(m),m^2]

where m is the input numbers.

I have to disagree somewhat with uncutno. If you train a NN to 100% accuracy on 50 input patterns, you have a very high probability of overfitting you data. Effectively the optimizer will do its best to get you to that 100% accuracy and will use random correlations to get there. The end result is you have a NN that does incredibly well on the training set, but then doesn't work well at all outside the training set.

I would recommend that you cut the training set into 5 sets of 10 patterns each. Use 4 of those sets (40 patterns) to train and watch the performance on the left out 10 patterns. When the performance on the left out set reaches a minimum, stop training there. (Usually this requires that you train for a long time, watch the left out set, and then identify when you should have stopped, then either revert back to that point.) You can continue this process by leaving out a different 10 each time, retraining on the 40, etc. etc.

Let me know if I can clarify any of the details.


-Kirk

Quote:
Original post by kirkd
I have to disagree somewhat with uncutno. If you train a NN to 100% accuracy on 50 input patterns, you have a very high probability of overfitting you data. Effectively the optimizer will do its best to get you to that 100% accuracy and will use random correlations to get there. The end result is you have a NN that does incredibly well on the training set, but then doesn't work well at all outside the training set.

I would recommend that you cut the training set into 5 sets of 10 patterns each. Use 4 of those sets (40 patterns) to train and watch the performance on the left out 10 patterns. When the performance on the left out set reaches a minimum, stop training there. (Usually this requires that you train for a long time, watch the left out set, and then identify when you should have stopped, then either revert back to that point.) You can continue this process by leaving out a different 10 each time, retraining on the 40, etc. etc.

Let me know if I can clarify any of the details.


-Kirk


Thanks!!!

I did not get everything. I think if you illustrate your thought by using a net example that would be better...

[Edited by - jolyqr on August 1, 2006 1:07:16 PM]
I don't really understand your question.

What I tried to say is that if you train your NN to 100% accuracy/performance on the training set, the net will likely find random correlations which allow it to get to that level. Then when you use the net in a new situation outside those used for training, it may not perform well. I would bet that it would perform quite poorly.

The method I described is referred to as cross-validation. Take you dataset of 50 patterns, as you called them. Take out 10 at random and use the remaining 40 to train your net. The training protocol is trying to maximize performance on thost 40. If you watch the performance on teh 10 that were left out at random during the training, what you'll typically see is that the net starts off terrible (as expected), gradually it improves in performance, and then it starts to get worst. All the while it is gettting better and better on the 40 training patterns. This is where overtraining starts to set in. The net has captured most of the detail of the problem and is now starting to find random correlations in the training data. These leads to a loss in performance on the 10 left out patterns.

What typically is done is that the process is repeated a number of times in order to make sure that each training pattern was left out at some point, and also to ensure that the random selection of 10 to leave out was not biased in some way. By repeating the process and then averaging the performance results, you get a better estimate of how well the net will perform in a new situation.

I hope that helps.

-Kirk

This topic is closed to new replies.

Advertisement