AI in practice, when coding

Hi,

For a long time, even after being familiar with AI theoretically at university, AI was slightly terrifying for me, especially when I'd listen to media how it's great and superb in needs of new technology in modern countries in almost every aspect of science.

One day, out of the blue, I found myself needed to cop with AI for a program. I was partly scared. Since what was in mind about that was something too sophisticated, advanced and convoluted I couldn't step forward to write a code for that part of the program where AI was required. I thought of that for hours until someone happened to give me a very simple code for that purpose, comprising 3 or 4 lines of code, including the random() function at the central section, which was completely astonishing and quite surprising for me, because, this simple code acted as though it were a real man behind the code performing the tasks!! It changed my perspective on AI to a far extent, and I came here to ask you experts for more info. :)

Now, I think, AI is not that scary and horrible, at least according to my recent experience. Is it?
The random() function was actually the cause to make the code behave like an artificial human. Is it all about AI, or do we have more famous functions for that purpose?

And the last question in this post, is it right that the entire thing done to create some AI is using the ordinary code, for instance in C++, that we use for other (non-AI) programs too?



Last edited on
AI is a buzz word. There is no single AI method. It's just some non-human process that solves a problem in an "intelligent" (or sometimes "human-like") way. What to be considered intelligent can be discussed...

I would suggest you think less about what AI is and more about the problem that you want to solve. There is no need to complicate things for the sake of calling it AI.

When it comes to games I would call anything that controls the computer-controlled players "an AI" even if it's just a stupid random walk that is totally unaware of its surroundings. My thinking is that I could replace the logic to be more "intelligent" later on, or have it change during the game, so just referring to it as an AI, no matter how stupid it is, is still useful.
Last edited on
AI is both a buzz word and a field.

Here is my take on it, and I worked with neural nets and fuzzy hybrid systems for almost 2 decades, and this is a gross generalization but it has held true for most of the problems we dealt with.

Classic AI approaches let you get a frustrating 85% or so of the correct answer. That is, you dump some data at it, and it gives you the expected response back out about 85% of the time. If you get better than about 85% (say, you get 95%) then AI was probably not necessary, you could have used a faster simpler and probably more predictable and reliable method. That last 15% of accuracy will drive you kind of nuts trying to drive it down ... retraining the system, getting more data, adding and removing variables (sometimes variables that mathematically correlate to the output are actually driving the answer to the wrong side more than helping!). This is for things like looking at an image from a camera and understanding what you see, a human does it at a glance, a computer cannot do it at all unless in an extremely limited environment and even then it will mess up sometimes.

As far as behaving like a human, it depends on what you are doing. You clearly can't mimic a human playing chess by ONLY picking random legal moves; it would lose in about 10-15 against even an average human. Random actions from a list of reasonable actions works on the surface, but it can't emulate a *strategy* over a period of time. It only works in the instantaneous moment of looking human.

Last edited on
@Peter:
I got your clarifications and explanations for AI. They were useful and I learnt many things. Thanks.

Still, I want to re-ask my last mentioned question, this time this way: what are the famous functions used for AI? I know one of them, probably the most famous one, is random(), but is there anyone else which is commonly used in AI, please?

@jonnin:
Thanks so much. it was great and very innovative to me. I appreciate your talks.
So by mentioning that game, to a great extent, you demonstrated that the functions and logic involved in AI might be much more advanced than using the random function.
For me, to help myself make progress in using AI in code, apart from the logic of the code, I firstly need to know some other names in addition to random with reference to AI. So please if there is a correct answer, answer the question above.
Still, I want to re-ask my last mentioned question, this time this way: what are the famous functions used for AI? I know one of them, probably the most famous one, is random(), but is there anyone else which is commonly used in AI, please?

When jonnin and I talk about "methods" we do not mean member functions. We mean it in the non-programming sense of the word. The exact functions used is probably a bit too low-level for this kind of discussion.

I think artificial neural networks (ANN) is one of the most famous "methods" (https://en.wikipedia.org/wiki/Artificial_neural_network). I'm not going to explain the details but an ANN takes some input and produces some output. By training the ANN you can make it give output closer to what you want. There are many ways to structure and train an ANN. It's not a ready-to-use solution that you can just apply to your problem without understanding how it works. ANNs are not magic and they often require a lot of tweaking to get right. They are suitable for abstract problems like image recognition that are hard to come up with fixed rules for (imagine writing an algorithm for how a banana looks like) but if there is a more direct solution to the problem it's often preferred because it's often more efficient and easier to understand.

Other "methods" are pathfinding algorithms such as A* and Dijkstra's algorithm (https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm). As the name suggests, these are suitable for things like finding the shortest path (or cheapest according to some cost function) between two locations on a map, or for finding the closest "power-up" in a maze game.

Minimax (https://en.wikipedia.org/wiki/Minimax) is another "method" that is suitable for games like chess where the players take turn and everything about the game is known to all the players all the time.

These are some of the more famous ones (in my opinion) but there are of course many others. The methods used have be be selected and adjusted to the problems at hand. You might even want to combine multiple methods. For example, a chess AI that only use minimax might feel too predictable because it will always make the same move if the state of the board is the same, so you might want to throw in some randomness so that it doesn't always pick the "best move" (according to the algorithm).
Last edited on
I am not sure what question you want answered.
Yes, AI can be done in c++ and it looks like any other code. The tool I used most actually generated C code, and it was pretty horrible but you did not have to edit it. It was a big pile of magic numbers (the weights in ANN terms) hard coded and loads of pointers and arrays. Classic AI is pretty simple code. It is literally a chain of sum of products over arrays times a weight fed into a sigmoid or similar 'activation' function. you can code this after your second class in programming, and by looking up sigmoid online for an equation for it. This is the core of your 'back propagation' type networks.

Most of the nets I used were 'radial basis' which trains really fast and maps pretty well for one to one input to output. For the data where that did not work, I usually had a back-prop style (there are improvements to the classical version) with a fuzzy or other 'governor' sitting on top to 'correct' 'bad' output (basically a sanity check -- if it has wings and a jet engine, and you tell me its a car, I am not buying it).

you will spend more time playing with data (statistics, setting up training (you have to train on data where you know the desired output and sometimes you have to determine that yourself), and adding noise to the input, and such. The coding part is not hard even if you DIY, and libraries exist anyway if you don't want to do that.
Last edited on
Topic archived. No new replies allowed.