Markov Chains

patron

Member
Hi to all...
At last, a post to discuss the marcov chain...
I've read mathimatical books to understand this theory and to try to apply to my lottery, but not luck...
What about the neural network guys? what is your opinion for applying to a lotto game?
Really good job frank...
 

patron

Member
i just finished setting up the spreadsheet...
really good job man...
thank you..
i'm waiting for the next part..
 

Frank

Member
patron said:
i just finished setting up the spreadsheet...
really good job man...
thank you..
i'm waiting for the next part..

Thanks for your feedback Patron, I'm working on it, back soon.:)
 

Omega71

Member
Hi Frank,

I would have responded sooner but I have been away. I started putting together your spreadsheet before I left. So far it is going great. Now that I am back I am going to continue with part 3. If I run into any problems I will let you know. Thanks again Frank for your time.
 

Frank

Member
Good Luck, Omega 71 !

To help with the final stages, study these screenshots first. At the end of this process you should have a totalof 16 named ranges!

http://www.mediafire.com/download/1282ko1gq58lg6s/Project6_7(2).rar


Ok, this is the last instalment of this project. In this part on Sheet2 we will make a section of spreadsheet to allow input of 2 ball numbers, the first ocurring A and the ball that follows it, B and a button that runs a search for the draw numbers when B followed A at the current sheet 1 settings.

This facility needs 4 new named ranges:-

Click on cell K105, Name it firstno. Give it a border and a background colour, as its an input cell.

click on cell P105, Name it following_no. Give it a border and a background colour, as its an input cell.

click on cell O108 Name it draws. Enter text "Draws" as it is a column header..

The output range is in fact 2 cols wide, so I merged cells O109:p109 using the merge and centre button, then used format painter to copy this double width merged cell down to cell O178.

To name the range Select range O108:p178 Name it drawsrange. Put a black box border around it.

'.....................End of named ranges

To create a kind of control panel look, I added some text and formatting ..

In cell H105, I entered text "Find when", also put a label below each of the input cells K105,P105 .. B............A respectively.
I Merged cells K103:p104 and entered large text "Enter Numbers", added a couple of down arrows to point to the input boxes.
M105 contains text "followed" ,
Cell Q105 contains a formula =OFFSET(readout,firstno,following_no-1)

Cell R105 contains a formula =CONCATENATE(" times Over ",drawsback," draws in next but ",next_but," draw")

In cell W108 I entered a checksum formula =COUNTIF(drawsrange,">0")

I merged T108:V108 and entered a text label "checksum"

Now to pull all this together in a logical way is down to formatting and borders as shown in the screenshot.

Note Q103:Z104 is where the macro button will go.


''.......................................................................

Next you need a couple of macros and a button.

Its best if you stay on the same module as the other main macros , at the very top of the module it will say Option Explicit. underneath you need to add this line..

Dim drawnumbers(400) As Integer

it will now read:-
Option Explicit
Dim drawnumbers(400) As Integer


'thats the editing done here


then scroll to the bottom of the module to the next available free space and paste in these macros..

Sub Find_drawnumbers() 'corresponding to (hand) input values on sheet 2

Dim i, d, q, nextbut, firstnum, followno, column, count As Integer

For i = 1 To 400 'clear draws array ' holds list of draws N followed that number
drawnumbers(i) = 0
Next

count = 0
nextbut = Range("next_but").Value
followno = Range("firstno").Value
firstnum = Range("following_no").Value

d = Range("maxdraw").Value 'how many draws
q = Range("drawsback").Value - 1 'how far are you looking back

Application.ScreenUpdating = False
Sheets("sheet1").Select

Range("start").Offset(q - d, 0).Select 'Select 'Range("start").Select

For column = 0 To 5 'first column is 0 with x direction offset of 0

Selection.Offset(0, 1).Select 'move to right one

For i = 0 To q + 1

If Selection.Offset(-i, 0).Value = firstnum Then 'we are dealing with our first number and the numbers following it


If Selection.Offset(-i - 1 - nextbut, 0 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value

End If

If Selection.Offset(-i - 1 - nextbut, 1 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value

End If

If Selection.Offset(-i - 1 - nextbut, 2 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value

End If

If Selection.Offset(-i - 1 - nextbut, 3 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value

End If

If Selection.Offset(-i - 1 - nextbut, 4 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i - nextbut, 0 - column - 1).Value

End If

If Selection.Offset(-i - 1 - nextbut, 5 - column) = followno Then
count = count + 1
drawnumbers(count) = Selection.Offset(-i, 0 - column - 1).Value

End If

End If

Next i
Next column

Call readoutdraws(count)
Application.ScreenUpdating = True

End Sub


Sub readoutdraws(c As Integer) ' when A followed B.. result on sheet 2
Dim i As Integer

Sheets("Sheet2").Select
Range("drawsrange").Select
Selection.ClearContents

Range("draws").Select
Selection.Value = "Draws"
For i = 1 To c
Selection.Offset(i, 0).Value = drawnumbers(i) + 1 'the follower is in the next draw to the firstno
Next

Range("drawsrange").Select

Selection.Sort Key1:=Range("draws"), Order1:=xlDescending, Header:=xlYes _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Range("draws").Select
End Sub


' end of the new macros

There is a minor modification to the existing readout() macro too ..

At the very top, it begins:--

Sub readout()
Dim j As Integer
Sheets("sheet2").Select
Range("readout").Select


after the row Sheets("sheet2").Select ......... add these 2 rows
Range("drawsrange").Select
Selection.ClearContents

The new version now reads at the top...

Sub readout()
Dim j As Integer

Sheets("Sheet2").Select
Range("drawsrange").Select
Selection.ClearContents
Range("readout").Select


'----------------------------------- edit complete



Now to drive these macros:-
I created a forms button and shaped it to fit over Q103:Z104, edited the button text to read "Find the draw numbers when B followed A" and assigned the macro (right click) "find_drawnumbers" to it.

Ensure you have (within range) sensible ball number values entered into cells K105,P105 that you wish to know the data for.This button should now extract the relevant draw numbers for the parameters you set before running the main macro on sheet1, and tell you when ball B followed Ball A.
The screenshot also shows something I just added, a column working out the "following skip" between these draws. You can add this if you wish with formula in cell Q109 =O109-O110 and copy this down the column.

----------------------------------------------------------------------------------------------------------------------------------------------------

To Add a variable number of new draws :- Requires the existing button on sheet1 changing in size and shape to cover cells A2:C3 and the text editing to read "Add New Draw(s)". Cell A1 is a label containing text "set how many" you may need to widen column A to 82 pixels and set a smaller font to fit it in.

Cell B1 becomes new named range called "howmany", place a black box border around B1 and highlight the cell background as its an input cell.

Enter number 1 into cell B1, this is the default value ( of how many draws to add) that the macro will assume unless you change this value.

Now for the Macro:-
On the same module as the newdraw macro (you need to keep this as it is still used)

Add this new macro:-

Sub EnterMultipleNewDraws()
Dim i, number As Integer
number = Range("howmany").Value
For i = 1 To number
NewDraw
Next
Range("howmany").Value = 1

End Sub

Thats the modification completed, it will now add as many draws as you like....
'.................................................................


If you wish to add a spinner to change the value in cell J2 (note you can still type in values as well). then ..
.
on the Developer tab> Insert> choose spin button (active X control) from the menu
draw out the spin control taller than its width, so arrow up and arrow down is what you see. Right click on it, choose properties and select the Alphabetic tab.
Click on Linked cell and in the box to its right type in J2. Make sure you are still clicked on the spinner and in its properties, Click on Max and
choose what you think the maximum value should go to , say 10000 and enter it.
Be aware that whilst properties box is showing, wherever you click your mouse outside this box becomes the object whose properties you are
looking at. It is easy to click on the spreadsheet and not realise you are now looking at its properties - not the spinners ..watch out for that.
close the properties box.


Fine tune the shape and location of the spinner so its adjacent to the cell J2. Note whilst doing this you are in Design mode. This will prevent the spinner from working until you click on the design mode icon to turn it off. Now test the spinner !

If you managed that OK, repeat the excercise but this time link it to cell M1, place the new spinner near cell M1, you may need to adjust row 1height to fit it in comfortably.

Thats all folks. Enjoy !
I'm going for a lie down ... :sleeping:
 

bloubul

Member
Hi Frank

Tanks again for this massive task that have done. I appreciate it.
But I made 'n tine mistake this time. I'm missing a name range as I don't get the skips values next to the number of draws Q9 downwards. Other wise is going good. Please tell me where I've slipped again

BlouBul :ccol:
 

Frank

Member
Hi Bloubul,

If you are not getting an error message when macros run then all your named ranges must exist. Have you remembered to enter a formula in cell Q109, formula =O109-O110 ? Then copy this formula down the column to cell Q178 ?

You might notice that you will also need to format these cells Q109:Q178 with a custom format to suppress zeroes, as described earlier (type 0;-0;;@)

Good luck!

Please let me know how you get on. :)
 

Omega71

Member
Hi Frank,

I just completed the final part and everything is running smoothly. Thanks very much for all the time you put into it.
 

Frank

Member
Thank you Omega71 for getting back to me, I hope it was worth your while. :)

PS in case anyone tried it, dont use negative values in Cell M1.
Any results found are nonsense. For example -1 causes a draw to compare it with itself. :dizzy: Setting its spinner properties. to min =0 prevents this.

Using a large non zero value in M1 can crash the macro, as it ends up looking for comparisons out of range, so common sense is required.

A small positive value in M1 may sometimes return a top (newest) draw ( when A followed B) result which is a draw out from the correct value, whilst the rest of the list is correct. :dizzy:

I have found no anomalies when using the most obvious value for cell M1 =0. :) This is the most sensible Markov chain anyway. :)
 

patron

Member
As i told you before Frank excellent job man...
keep going...
I have a problem...
when i run the "find the draw numbers when b folloed A" macro...
At the results...
(lets say that i run for all th draws of my lottery 2366)
my first result is 28 draw and followed by 2363, 2357 and so on...
what i make wrong?
 

Frank

Member
patron said:
As i told you before Frank excellent job man...
keep going...

Thanks for that, Patron. Keep going? Well I was hoping people had had enough and were happy to call it a day. There is more on my sheet, which highlights the most recent draw numbers in the min and max tables and gives the option of listing the top 3 ball sets ( not just the max) and bottom 3 ball sets( not just the min) by using option buttons, but thats more modification work again and I wonder how many people are familiar with or want to learn how to use option buttons? :worry:
 

Frank

Member
Well you do need to be familiar with adding groups of option buttons in Excel before attempting to modify the existing sheet.

What we will need on sheet 2 are two groups of 3 buttons, each group being independent of the other.
One group will control maximum value choices ( max only, top 2, top3).
The other will control minimum value choices (min only, bottom 2, bottom 3).

If you've never done this before, its worth having a practice on a blank spreadsheet, using this turorial as a guide. I has a brilliant video that shows how easy it is when you know how.
http://blog.contextures.com/archives/2010/03/24/select-answers-with-excel-option-buttons/

The tutorial only has 2 buttons in a group, but you can try 3 as thats what is required in the real project. Group of 3 buttons 1 can be linked to any cell (all three to the same cell) whilst group of buttons 2 can be linked to a different cell (all three to the same cell).

If it works correctly you will be able to change the values in linked cell 1 to 1,2 or 3 without affecting the value (or the buttons) in the other group, and vice versa. It is important that you dont overlap button boundaries in the same group, or have part of a button outside the group box its supposed to be in. You will not need any fancy formulas similar to the video, as macros will be reading the values in the real thing.

tip:-
Once working its important not to disturb the option groups. Accidentally copying and pasting a button whilst copying a range later will mess things up!
Once you are confident you can do this, we can move on. :smokin:
 

Frank

Member
Ok, I'll try and fit this in this week before I dissappear for a couple of weeks, but I'm pretty busy.
 

HalfBee

Member
I'm not sure what you plan on getting out of this...

Rather than excel, I did my prototype in VB express and only for the 5/39 game I usually track. What I found (still experimenting) is that the percentages were really low (0 to 3%) for the numbers and fairly evenly distributed over the whole range. This makes it hard to determine what is going to spring up the next draw.

Not giving up, but can see it's going to take a lot to determine if it's useful.

More information on Markov Chains would help.
This is the way I interpret it:

Draw #1
1,3,14,21,33

Draw#2
5,8,14,25,39

for draw 1 it goes...

1 --> 5 8 14 25 39
3 --> 5 8 14 25 39
14 --> 5 8 14 25 39
21 --> 5 8 14 25 39
33 --> 5 8 14 25 39

Each gets 1 occurance of being followed by all balls in next draw
in case of a repeating number (like 14 above) it gets added as following
itself.

Repeat same proceedure with draw #2 adding in all the draw #3 numbers
etc. until we reach however much history we plan to use...

At the end we end up with and array of numbers 39*39

Now... with the skip option are you adding in every 2nd draw like:

Draw #1
1,3,14,21,33

Draw #2
5,8,14,25,39

Draw #3
11,15,22,31,38

Draw #4
9,12,17,24,27

1 --> 5 8 14 25 39 __&__ 11 15 22 31 38
3 --> 5 8 14 25 39 __&__ 11 15 22 31 38
14 --> 5 8 14 25 39 __&__ 11 15 22 31 38
21 --> 5 8 14 25 39 __&__ 11 15 22 31 38
33 --> 5 8 14 25 39 __&__ 11 15 22 31 38

or
just the numbers from Draw #3

1 --> 11 15 22 31 38
3 --> 11 15 22 31 38
14 --> 11 15 22 31 38
21 --> 11 15 22 31 38
33 --> 11 15 22 31 38

Thus looking to predict numbers two games out...

Just checking my reasoning here and looking for feedback...

HalfBee
 

Sidebar

Top