Sunday, 5 February 2017

Can we create Matrix using AI?

Would it be possible for us to create real time world simulation?

We started using super computers with few thousands of processors, unbelievable number of RAM, insane Internet speed, and all that working as one unit.

We use them for predicting climate, solving problems, do different types of simulations, but can they run Matrix?
On first look you could think, ok, how hard it can be?

Let's try to think for few minutes what we need for building Matrix.
For this purpose we will speak in OOP world, so describing what kind of "objects" we need.

First we need "World", he will be filled with "People", "Animals", "Physics rules", "Oceans", "Nature", "Rivers", "Mountains", "Threes", "Cars", "Homes", ... and many other things.
Now you can think, ok, at some point I will create all of them, then you can think what to do next...?

What is the main ingredient for life itself? It's Sun. So we need to map our whole planetary system.
On then add "Sun", "Moon", "Mars" and others...
Create them and just add basic rules, all planets are circling around soon at some speeds, they are spinning at certain speeds, and we did that, perfect.

Now we have light on our planet, hmm, so now what we need is "Climate", some times we have sunny days, some days rain, some days wind, snow,...

Let's assume we did that too, now we have day and night zones, climate, so we can work on photosynthesis because we need oxygen. We did that too, ok, at this point it started to be very complex and we just started.

Let's say everything is done, let us concentrate only at one place, one city, and then on block.
How many people live there? How many streets, shops, jobs, cars, dogs, cats are there?
And you fill all that info, what is left is our SOUL!

We still can't create that good AI to simulate our way of thinking. Our way of getting knowledge, our way of getting friends, every person has something unique and that computer can't simulate. Still...

Best companies in the world didn't even scratch the surface what is our brain capable of.

When we count all necessary things we need to create in Matrix, your brain already started imagine that in your head, all the places, streets, different people, worlds and that machine can't do...

Machines are now just capable to use our data we provide them and manipulate in some sort to get a result we think it is good.
I hope it will stay like that for a long time, because if somebody do create that good program, we will all be without job :)

Let's say in we do create that good AI, what do we need more? Can you imagine how big data centers it will require, just to store memories of 1,000 people? Matrix is still out our reach, and it will take us some time to reach that goal, maybe we will never reach it but who knows, maybe where are we now is only one big simulation...

If you did like our story, and your are looking of more, please subscribe to our blog, post some comments, like us on Facebook, share it and enjoy.

Kind regards,

Saturday, 7 January 2017

Lotto Predictions - Java AI

Hello, we want to show you simple AI algorithm and how can he produce some lotto numbers for us.

We created small algorithm, load some numbers that happen before, do some calculations and print out the next 7 numbers winning combination.

First we need to have a way to represent this sequence of 7 numbers.
For example numbers: 37, 2, 11, 15, 14, 22, 1

What we can notice immediately is that we can sort them, it doesn't matter in witch order they arrived on screen, they will still represent combination of 7 numbers. So in our case it is: 1, 2, 11, 14, 15, 22, 37

We can create simple class for that.

Helper class:

public class Numbers {
    private final int num1;   private final int num2;   private final int num3;
    private final int num4;   private final int num5;   private final int num6;
    private final int num7;

    public Lotto(int num1, int num2, int num3, int num4, int num5, int num6, int num7) {
        this.num1= num1;   this.num2= num2;   this.num3= num3;
        this.num4= num4;   this.num5= num5;   this.num6= num6;
        this.num7= num7;
    // some getters for this numbers
Now we can reuse this helper class and initialize some results we already know.

First we will create some List and some maps, in list we will collect all previous result so it would be easier for us to use them and maps will be created just to remember how many points each number have.

In our case point would be how many time he was in results from before.

Using static block we will populate result list and we can start processing.

Go over result list and populate maps with numbers.
Call print prediction that will go over maps and find best matches.

Take a look at the code:

Main class:

public class Lotto {
    // here we will store all results that we know in advance
    private static List<Lotto> results = new ArrayList<Lotto>();
    // we will use this maps to store info for number how many times he already were in results
    private static Map<Integer, Integer> number1 = new HashMap<>();
    private static Map<Integer, Integer> number2 = new HashMap<>();
    private static Map<Integer, Integer> number3 = new HashMap<>();
    private static Map<Integer, Integer> number4 = new HashMap<>();
    private static Map<Integer, Integer> number5 = new HashMap<>();
    private static Map<Integer, Integer> number6 = new HashMap<>();
    private static Map<Integer, Integer> number7 = new HashMap<>();
    static { // this will load some results that already were in lottery winners
        Numbers l1 = new Numbers (2, 7, 9, 13, 14, 29, 31);
        Numbers l2 = new Numbers (8, 14, 16, 22, 27, 29, 37);
        Numbers l3 = new Lotto(12, 17, 18, 19, 26, 35, 39);
        Numbers l4 = new Lotto(4, 6, 9, 10, 11, 18, 32);
        Numbers l5 = new Lotto(2, 3, 6, 7, 10, 15, 25);
        Numbers l6 = new Lotto(13, 21, 22, 28, 30, 32, 39);
        Numbers l7 = new Lotto(9, 12, 19, 22, 28, 36, 39);
        Numbers l8 = new Lotto(11, 15, 18, 22, 24, 36, 37);
        Numbers l9 = new Lotto(4, 8, 12, 18, 19, 24, 31);
        Numbers l10 = new Lotto(4, 9, 13, 14, 17, 37, 39);
        // add values to the list          
    // our main program
    public static void main (String [] args) {
        for (Numbers l : results) {
            addNumber(l.getNum1(), number1); addNumber(l.getNum2(), number2);
            addNumber(l.getNum3(), number3); addNumber(l.getNum4(), number4);
            addNumber(l.getNum5(), number5); addNumber(l.getNum6(), number6);
            addNumber(l.getNum7(), number7);

    private static void printPrediction() {
        int n1Prediction = findNumber(number1);
        int n2Prediction = findNumber(number2);
        int n3Prediction = findNumber(number3);
        int n4Prediction = findNumber(number4);
        int n5Prediction = findNumber(number5);
        int n6Prediction = findNumber(number6);
        int n7Prediction = findNumber(number7);
        System.out.println("Prediction for new lotto result is:");
        System.out.print("Numbers: " + n1Prediction + ", " + n2Prediction
                        + ", " + n3Prediction + ", " + n4Prediction
                        + ", " + n5Prediction + ", " + n6Prediction
                        + ", " + n7Prediction);
    // our magic goes here
    private static int findNumber(Map<Integer, Integer> map) {
        int number = -1;
        int value = -1;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (entry.getValue() >= value) {
                number = entry.getKey();
                value = entry.getValue();
        return number;

    // if value exist in map then remove it and add it once again with counter + 1
    private static void addNumber(int num, Map<Integer, Integer> map) {
        if (map.containsKey(num)) {
            int exist = map.get(num).intValue();
            map.put(num, exist + 1);
        } else {
            map.put(num, 1);

After running this program we get this:
Prediction for new lotto result is:
Numbers: 4, 15, 9, 22, 30, 29, 39

Why did he find that results?

He was checking witch number is most popular to happen on that place and print out that one.
Our logic is fair simple, in order to create something "smarter" you will need better algorithm for this.

Add more results, change method print prediction, count more factors not just 1 and you should get better results, and at one point hit the jackpot!

Until then, please subscribe to our blog, post some comments, like us on Facebook, share it and enjoy.

Kind regards,