Artificial intelligence repository
Content
First things first, the bibliography contains all the books that I consider are the real basis of what the code is about. And in general, what AI is about.
This part of the repository tries to explain what a genetic algorithm is and how "evolution" occurs.
A key idea is to find a good representation of the chromosome and how to encode, decode and
"score" (fitness function) a chromosome.
We are trying to write a genetic algorithm which input is a number and the outout is
a formula that generate that number just using: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' and
operators such as: '+', '-', '*', '/'.
For example: 10 is an input and an output could be: 6 + 4, 8 + 2, 7 + 5 - 2, and so on.
The number of generations is limited to 32000.
The code is written in java, so, so far to execute it, we must use a javac command:
- javac Chromosome.java
And then:
- java Chromosome
C++ code :D
in this code I implemented the descendent algorithm for two variables.
For several variables I'd recommend use the same idea, changing as many arguments as
it's needed.
The code is written in C++, so, to execute it you need to compile with C++ compiler
- g++ gradient.cpp -o gradient
And then:
- ./gradient
Clustering is one of my favorites subjects in artificial intelligence. In this folder you will find an implementation of the K-Means clustering (where K represents the number of the clusters). The data for this case are points(which were generated with "random" numbers), and I did some graphical implementation, so, every cluster was visible (in a plot with a specific color). The code is really straight and simple.
To execute it, you need to have Java installed.
In order to compile the code:
- javac KMeans.java
and to execute:
- java KMeans
The output of the code allows you to do two things:
- You will have the numbers classified in the cluster in your bash
- You will have a representation of the points (this open to the use that you give to your clusters, but in my opinion every data should be represented in a simple and graphical way, because if not, what's the point, isn't it?).
Abstraction of the problem:
Given a point (x_coordinate, y_coordinate) in the cartesian plane, inside the rectangle (0,0) and (20, 12), classify if the point is inside the circle with center in (10,8) and radius 3.
This code was actually a project in my bachelor.
The representation of a the regular neural network with one inner(hidden) layer.
The idea here is that you generate the numbers with a prolog program(generarNumeros.pl), so the txt files represent the training sets.
The code was written in C++.
The program called:
-probarMejor.cpp
it represents the neural network and in it we are trying to build the net and figure out how many neurons and iterations we will need to learn.
This is one of my favorite pieces of code.
The way to compile the code is as follow:
- g++ probarMejor.cpp -o probarMejor
And then to execute the code:
- ./probarMejor
The output of the program is by standard output and again, one part of the information is related to the number of iterations, neurons and the percentage of well classified.
Another program that we can be delighted of is the "anticonceptivo.cpp"
How to compile?:
- g++ anticonceptivo.cpp -o anticonceptivo
executing as follow:
- ./anticonceptivo
or
- ./anticonceptivo 16 0.669 1000.txt file.out
Some heuristics and useful programs that can be used in any search problem
This is java code, so, the way to compile is using javac command, for example:
-javac AStarHeuristic.java
And the way to execute in this case would be:
-java AStarHeuristic
Basically what I was looking for here was to be sure that I covered some of the real basics of artificial intelligence and graph theories.
The way to run this code is running the program called: GraphImplementation.java
To compile:
- javac GraphImplementation.java
To execute:
- java GraphImplementation
And that's it.
Here comes a change of paradigms/change of thinking. So instead of trying to find a function that can maps some data properly(like neural networks or just a neuron like perceptron), we are going to store a bunch of data and form a "data base", so, everytime that we are trying to find a new value, we just try to find to which "register" in our database is more likely to represent that new value. In this new way of thinking we are going to follow the kNN algorithm.
How do you execute it ?
This part of the rep was written in Python.
running with Python:
python kNN.py
The output will depend on the whatever main function you are managing and how you represent your data. In this case, the data is found in iris.data
nQueens is a problem which consist in positioning n queens in a board, in a way that non of them kill each other. Basically what you have to do is to be aware of the constraints and conditions of the problem, and of course know how a queen moves. In this implementation, those constraints are checked from left to right and from top to bottom.
The code was written in C++ again and you know how to run it:
compiling:
- g++ nqueens_backtracking.cpp
running:
- ./nqueens_backtracking
REALLY important: the concept of backtracking is a steping stone in artificial intelligence. Here is an example of a simple implementation of it (nQueens.cpp).
I am still working in this part of the repository. Coming soon
I am still working in this part of the repository. Coming soon
I am still working in this part of the repository. Coming soon