Lotto Max Neural Network.

In order to get rich I created a neural network to pick lottery numbers for me.
I trained the neural network by using previous results of the lottery found on this website:
http://www.lottomaxnumbers.com/previous-results.asp
The input neurons are basically the numbers from the previous week and I train them to
generate the next weeks numbers. This is nothing more than wishful thinking that it will
work however and is purely for entertainment purposes.
As anyone who knows stats, the rolling of dice is independent. If I was to have an accurately
trained neural network I would need to know the true input (ball position, random number generator system)
at the start to know the final position.
So yeah this week I spent $5 on lotto. Wish me luck. I’ll tell you how it turned out tomorrow and share
the algorithm/program if it doesn’t work 😉

Wish me luck!

The result… Terrible.
http://www.wclc.com/winning-numbers/draw-videos.htm
May 19 2017 => 8 11 18 25 34 35 38 b44

My numbers => 04 20 23 41 42 46 47
Not a single number matched. So much for past results predicting future.

Tic Tac Toe Heuristic or Neural Network

I’ve finally I’ve decided to delve a bit into neural works as I’ve seen some amazing things done with them.

In order to learn more about neural networks I decided to code a tictactoe Artificial Intelligence (AI) and maybe apply what I’ve learned to something a bit more complicated. I used neural networks by having each board as input neurons with the proper/best move coded as output neurons. Which means I have 9 inputs 10 hidden neurons and 9 outputs. The inputs and outputs are between -1 and 1 where -1 represents x and 1 represents o and 0 is an empty spot on the tictactoe board. Coding it this way works fine, I was able to train the AI by entering perfect training data.
Having each input producing an exact move/output. The problem with this way of training the AI is that you have to precalculate everything. The AI isn’t really learning as it plays and in the end you might as well be using a heuristic as the rules (training data) to win
are decided by your input/output.

So what would be the best dynamic way to code a tictactoe neural network?

Why do humans learn so much faster, and by faster I mean play fewer games to understand the rules. Part of the reason could be that they are learning from their mistakes/losses. So if your AI loses, make sure to record what your opponent did. This way you learn even when you lose. This will cut down the amount of time required to train the neural network.

So this is how I would do this:
let NN = empty neural network
let b = current empty board
let b_array = array of boards (previous moves)

while move = NN->calculate(b) && !done
{
// no move trained? make a random move
if( !move ) {
b = random_move( b );
b_array.add( b );
}
if( xs_won( b ) )
{
NN->addTestData( b_array );
done = true;
}
else if( ys_won( b ) )
{
// add opponents data, learn from his win.
NN->addTestData( ^b_array );
done = true;
}
else if( draw(b) )
{
// there could be a draw, and you both did nothing wrong.. perhaps.
}
}

This method of learning is interesting, however I can see there are flaws if a player makes a bad move, but your opponent makes a worse move. This could cause your neural network to learn moves that are not necessarily good moves and for draw games maybe you both made poor moves. How do you make sure data that is trained that is wrong doesn’t poison the whole network?

That’s all for now.

Ion wind and plasma propulsion.

Here are some of the most interesting ION wind experiments and discussion on youtube.
It took me a while to find some of these videos so I figured I would create an index for them here on my site.
For ease of looking up and so you can check them out if you are interested in ion wind experiments.

Using Ion Propulsion in model Aircraft. A good start for ion air based lifters.

Make: An Ion thruster.

Ion Lifters.

University of Hong Kong ion wind blimp Jun 23/2011

Nasa experiments on Ion wind.
These are really cool experiments that show the possibilities of high efficiency ion wind transportation using
carbon nanotubes of course. A good scientific place for learning about ion wind.
https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20100000021.pdf

Finally something to ponder, looks cool but probably doesn’t work for various reasons.
I figured I would post this here because it looks like their company does some neat stuff.
Plasma propulsion tests Dec 15/2015 – Part 1

Part 2.

Collatz Conjecture

I was looking into solving the Collatz Conjecture and I came up with a couple of simple tools and programs to help out.

Collatz Conjecture table of solutions/series produced by a PHP script.

n (n base 2) solutions to 3n+1 and n/2 as a series (in base 2)
1 (1) 1
( 1 )
2 (10) 2, 1
( 10, 1 )
3 (11) 3, 10, 5, 16, 8, 4, 2, 1
( 11, 1010, 101, 10000, 1000, 100, 10, 1 )
4 (100) 4, 2, 1
( 100, 10, 1 )
5 (101) 5, 16, 8, 4, 2, 1
( 101, 10000, 1000, 100, 10, 1 )
6 (110) 6, 3, 10, 5, 16, 8, 4, 2, 1
( 110, 11, 1010, 101, 10000, 1000, 100, 10, 1 )
7 (111) 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 111, 10110, 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
8 (1000) 8, 4, 2, 1
( 1000, 100, 10, 1 )
9 (1001) 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 1001, 11100, 1110, 111, 10110, 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
10 (1010) 10, 5, 16, 8, 4, 2, 1
( 1010, 101, 10000, 1000, 100, 10, 1 )
11 (1011) 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
12 (1100) 12, 6, 3, 10, 5, 16, 8, 4, 2, 1
( 1100, 110, 11, 1010, 101, 10000, 1000, 100, 10, 1 )
13 (1101) 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
14 (1110) 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 1110, 111, 10110, 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
15 (1111) 15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 1111, 101110, 10111, 1000110, 100011, 1101010, 110101, 10100000, 1010000, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
16 (10000) 16, 8, 4, 2, 1
( 10000, 1000, 100, 10, 1 )
17 (10001) 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
18 (10010) 18, 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 10010, 1001, 11100, 1110, 111, 10110, 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
19 (10011) 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 10011, 111010, 11101, 1011000, 101100, 10110, 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
20 (10100) 20, 10, 5, 16, 8, 4, 2, 1
( 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
21 (10101) 21, 64, 32, 16, 8, 4, 2, 1
( 10101, 1000000, 100000, 10000, 1000, 100, 10, 1 )
22 (10110) 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 10110, 1011, 100010, 10001, 110100, 11010, 1101, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )
23 (10111) 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1
( 10111, 1000110, 100011, 1101010, 110101, 10100000, 1010000, 101000, 10100, 1010, 101, 10000, 1000, 100, 10, 1 )

2 axis graph of Collatz conjecture.

6 axis graph of Collatz conjecture.

You can see that the number of steps to get to the final value of 1 depends mostly on how many 1 digits there are in binary value.
The more 0 digits there are the more times it can be divided evenly by 2 which leads to the final value of 1.
Look at the series produced by n=3, n=7 or n=15

1. The reason these values take the most steps to solve is because anything with a 0 can be divided by 2.
For example: 10, 100, 1000, 10000, 100000 will become 1 by the collatz conjecture quickly using the function/rule: n/2 for n%2=0

Step by step solution to n=7. In base 2 and base 10.

base 2 base 10
111 7
1110+111+1 3×7+1
10110 22
1011 22/2
10110+1011+1 3×11+1
100010 34/2
10001 17
100010+10001+1 3×17+1
110100 52
11010 52/2
1101 26/2
11010+1101+1 3×13+1
101000 40
10100 40/2
1010 20/2
101 10/2
1010+101+1 5×3+1
10000 16/2
1000 8/2
100 4/2
10 2/2
1 1

After finding the binary approach to the collatz conjecture and making my graphs,
I found out that others have gone there before:

http://www.journalrepository.org/media/journals/BJMCS_6/2014/Aug/Nag4212014BJMCS12538_1.pdf’

Unfortunately the argument of the paper is that no formal proof to the Collatz conjecture exists due to Hasse’s algorithm.

Here’s a really good video explaining more on collatz conjecture.

PHP base_convert

I wrote a simple tool to visualize numbers in different bases to help solve a math problem I was thinking about
the other day. It uses PHP. If you share this script make sure to sanitise data.

<html>
<head>
</head>
<body>
<h1> Convert numbers </h1>
Use this form to convert numbers between different bases. <br/>
This can be useful for visualizating numbers in different bases. <br/>

<form>
Input base number:<br/>
<input type=”text” name=”base_in” value=”10″/><br/>
Numbers To Convert (1 per line)<br/>
<textarea name=”input_data” rows=”5″ cols=”20″>
<?php
if( isset( $_REQUEST["input_data"] ) )
{
echo $_REQUEST["input_data"];
}
?>
</textarea><br/>
Output base number:
<br/><input type=”text” name=”base_out” value=”2″/><br/>
<input type=”submit” name=”submit” value=”submit”/><br/>
</form>

<?php
if( isset( $_REQUEST["input_data"] ) )
{
$base_in = $_REQUEST["base_in"];
$base_out = $_REQUEST["base_out"];
$input_data = $_REQUEST["input_data"];
$lines = preg_split(“/(\r?\n)/”, $input_data);
$lines_count = count( $lines );

echo “<b> output in base $base_out</b><br/>”;
foreach( $lines as $line)
{
// do stuff with $line
echo base_convert( $line, $base_in, $base_out).”\n<br/>”;
}
}
?>

</body>
</html>

PHP Performance

I’ve noticed the performance of my PHP is dog slow. I’ve since put in some debugging code and performance measuring code. My code might not be as modular or pretty looking but at least it will work in a reasonable amount of time. Object oriented PHP is causing me many performance headaches. It was disgustingly slow.

Here’s a link to probably the best guide/page on the net on PHP optimisation.

http://www.wardontheweb.com/10-performance-tips-to-speed-up-php/
Another decent site/page with citations/references:

http://www.hm2k.com/posts/50-php-optimisation-tips-revisited

Problem Solved
It turns out much of my class headaches came from an extremely slow classloader function.
So if you are having issues with PHP class loading look into what your class loader is doing.
Mine was searching everywhere for the class and this was wasting gobs of time.
Meanwhiles all classes were in 2 directories.

Read about writing your own autoloader here for php classes.
http://php.net/manual/en/language.oop5.autoload.php

PHP mysql_connect is slow 1 second for localhost windows 7

I recently moved my development from XP to Windows 7 and found that webpages I had developed were taking 5 seconds long to load. This was unacceptable of course so I had to track down the problem.
I eventually tracked down the offending function/method pdo::construct. I also found that mysql_connect was taking about 1 second to make a connection. After a little googling I found an explaination that php had issues with IPv6 and that you could fix the problem by either disabling IPv6 or switching to the ipaddress 127.0.0.1 when making your connection.

Here’s a link to the thread where I found the information.

It’s a simple problem but I figured I would share/help boost visibility of it.

This is a reposted restored from wayback machine.

New wave physics – Extraordinary claims require extraordinary evidence.

There’s a company out there called Brilliant Light Power that has supposedly found a new state of matter for hydrogen.
Hydrogen in this hydrino state releases a lot of light energy. All it looks like is they have
a car battery melting silver in magnetic coils and then are pumping hydrogen in to burn it.
It seems like their machine is nothing more than an overly complicated spark plug.
Melting silver with a car battery is impressive, usually it takes a fair bit of power to do that.
Maybe I’ll try it sometime.
Here’s an example of induction melting.

A couple of the red flags for the company.
1. They were originally called “Black Light Power“.
2. They “got” 50 million dollars in funding already and this is all they produced (It’s a neat apparatus but 50 million for burning hydrogen?)
3. They claim to have invented a new type of physics. (hydrino, dark energy etc)
4. They claim to have invented a new type of physics.
5. They claim to have invented a new type of physics.
6. Their machine is needlessly complex for what it does.

Oh did I repeat myself. Yeah new physics. So yeah if your using melted silver as a catalyst for this reaction why are you flinging the silver around like a juggler
tossing his balls in the air?
Why aren’t you just using a pool of melted silver in a cup like those guys above in my url and just blasting the molten pool of silver with the hydrogen.
Oh yeah also light energy is less energetic than say infrared or heat so yeah burning hydrogen produces heat + light. Light is going to be the less useful amount
of energy. The black orb… that’s cool. You could patent that use it as some sort of solar orb you plug into your ceiling.. ok maybe not stupid idea.

People are wasting their time + money looking in this. Thinking that the energy problems are going to be solved with some miracle solution.
Fusion has been off on the horizon for 30 yrs.

Learning about The SmartFoxServer: massive multiplayer server

I’ve always loved multiplayer games and one of the first attempts I made at writing a mutliplayer game was a game written in Turing that would attempt to write to a shared hard drive everytime a players moved their position in the game. It was interesting. I learned that day that files were not immutable under DOS and would crash the game if two or more clients accessed the shared file at the same time.
Now nearly 20 years later we’ve had huge games such as World of Warcraft with up to 6 million subscribers and hundreds of thousands of users.

The technologies and solutions these companies came up with to scale this many users are varied and interesting.
However one solution that you can get out of the box is this server. I’ve tested it out, think it’s ok for what I would need. Now it comes down to price.
The unlimited license is €3,000.00 which is about $3380 american or $4480 canadian dollars.
It’s expensive. It probably works out to about $1 per a user.

The limited 5000 user license is only 2,100.00 euros. This works out to about 50 cents a user.