Author Topic: Looking for old program or help recreating it  (Read 8534 times)

0 Members and 1 Guest are viewing this topic.

Offline random1

  • Newbie
  • Posts: 86
Looking for old program or help recreating it
« on: December 07, 2021, 11:37:55 am »
Many years ago, mid 90's  I came across a sort of sequential prediction tool.
I don't remember the name but it was suppose to show how bad people were
at random.
The program presented the user with two buttons labeled (0) and (1).  The user
would select one of the two and then the program would try to predict the users
selection.  The more a person played the better it got at predicting.  The users
input was held until after the prediction was made then it would be added to the
the predictors data string.
I did not understand the code back then but held on to it for many years thinking
it could come in handy.  I changed computers many times since then and the
source code got lost in the process.  It was written using qb45 is about all I can
remember.
I have a tool that processes around 800 binary strings and I thought this tool
might come in handy to test the randomness of the data.  The strings are just
a series of zeros and ones, either the event true=1 or false=0.

Anyway, looking for anyone knowledgeable in this sort of thing to post a few
ideas including source code.  The program could also include a 3rd state for
whenever no clear prediction could be made.  I use a wildcard (*)   

Small data sample
0001000001011100000011000100011000010010000000000000000011000000000000000001110010000000000001111000000001001110000000000000100000000011110000000000000000000000000000010100000000000000000100000000000000110001111000010001000000000000000000011010000000000000000010001101100000100001000000110011000011010010000000000000000000100001000011000110001010000000100000000000000000000000000000000000010000000000100000000000000010100000100000000000000000000000000000000000100001000000000000000010110100000000000010010000000000000000000100000000001100000011000000000000000000000000000000110010000110000100000   

Thanks R1
 



Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Looking for old program or help recreating it
« Reply #1 on: December 07, 2021, 11:43:35 am »
I think I saw a program like that for Rock, Paper, Scissors at a Basic forum. Might try that for searches.

Offline random1

  • Newbie
  • Posts: 86
Re: Looking for old program or help recreating it
« Reply #2 on: December 07, 2021, 03:08:49 pm »
All rock, paper, scissors that I have ever seen just use a random number generator
to select one of the options.

What I am looking for is more a learning algorithm for forecasting / prediction.
The app I mentioned learnt from the users inputs and used user data to predict the
users next choice.

My idea was to swap the user input with data strings and automate the process.  What I
am using now and how it works.

First it takes a number of random samples from within the string, both the number of samples
and the length of each sample are set within a configuration menu. Around 350 works best for
the number of samples along with a sample size of 8 to 25 digits, user defined.

Next it calculates ratios for ones vs zeros for each sample. This allows me to calculate a sort
of running average.  The overall totals for the main data string are calculated before the data
is fed into the predictor and the probabilities are used to help calculate a weight which is then
used in the final prediction.
   
The final prediction is made by looking at a sample taken from the last so many entries -1
so if the sample length is 25 then it collects the last 24 and then adds one to the zero count
and calculates the ratio then the same thing is done again adding a one to the ones count.

Whichever comes closest to the running average +/- the weight is the predicted value.  It's
sort of a best fit model.

If I remember correctly the program I mentioned at the head of the topic reached over a 80%
hit rate in less than 100 plays when looking at the last 10 or so attempts.

The program mentioned uses random choices at first until it had enough data to feed the prediction algorithm.

The more games played the better it got at predicting users next choice.  At the time I was not
able to figure out how the algorithm worked as it's code was way above my skill level.

I am starting a new predictor project and welcome any input from others.  Some of the 800 plus
data strings I use are too random to be of any use while others are not.  My goal is to find around
25 out of the 800 that can be predicted with a high degree of consistency. 

R1

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Looking for old program or help recreating it
« Reply #3 on: December 07, 2021, 03:51:38 pm »
Yeah the RPS thing was an AI or NeuroNet that picked up patterns and was to show how badly humans played Rock, Paper, Scissors because humans are bad at randomness.

I like this challenge, I will try an approach I used here:
https://www.qb64.org/forum/index.php?topic=2122.0

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Looking for old program or help recreating it
« Reply #4 on: December 07, 2021, 04:45:29 pm »
At first I thought this was crap, then I saw a > sign turned the wrong way!

I get better than average for AI:
Code: QB64: [Select]
  1. _Title "Predicting Human Randomness" 'b+ 2021-12-07
  2.     If Len(s$) < 8 Then
  3.         If Rnd < .5 Then AI$ = "H" Else AI$ = "T"
  4.     Else
  5.         sum = 0: count = 0
  6.         match$ = Mid$(s$, Len(s$) - 7, 7)
  7.         place = InStr(s$, match$)
  8.         While place <> 0 And place < Len(s$) - 7
  9.             count = count + 1
  10.             char$ = Mid$(s$, place + 8, 1)
  11.             If char$ = "H" Then sum = sum + 1
  12.             place = InStr(place + 1, s$, match$)
  13.         Wend
  14.         If count Then
  15.             Sound 500, 1  ' >>>>>>>>>>>>>>>>>>>>>>>>>>> this signals it found at least one match
  16.             ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> check how it does after the sound
  17.             If sum / count > .5 Then AI$ = "H" Else AI$ = "T"
  18.         Else
  19.             If Rnd > .5 Then AI$ = "H" Else AI$ = "T"
  20.         End If
  21.     End If
  22.     Input "Enter H or T "; p$
  23.     p$ = UCase$(p$)
  24.     If p$ = "H" Or p$ = "T" Then s$ = s$ + p$ Else Exit Do
  25.     Print "AI predicted "; AI$
  26.     If AI$ = p$ Then ai = ai + 1
  27.     Print "AI is correct "; 100 * ai / Len(s$); "% times."
  28. Print "AI is correct "; 100 * ai / Len(s$); "% times."
  29. Print "Goodbye!"
  30. Beep 'sorry I get crazy doing h enter, t enter
  31.  
  32.  

Sure if you see what AI is doing you can break it but how about not looking... ;-))

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Looking for old program or help recreating it
« Reply #5 on: December 07, 2021, 05:20:22 pm »
Ran code 1,000,000 times several times.  AI is 50% +- <1% against a Rnd selection for H or T.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • Resume
Re: Looking for old program or help recreating it
« Reply #6 on: December 07, 2021, 05:51:50 pm »
Human behavior has more patterns that just a random generator.

I vaguely remember that program from way back. If I recall, it used statistical probabilities based on past patterns, such as if the human hits Key A always or most of the time when pressing Key B twice in a row, etc, it used a crude AI to be more predictive.

I had a program that I wrote for Roulette back in the 1990's (I only found my first release of it on 3 1/2 floppies when I wrote it as shareware back in 1990) that determined basic patterns for RED/BLACK and groups of numbers, and against a real wheel I had back then, it was more than 50-50 (like 60% correct). But iPhone didn't exist back then, so I could not drag a large PC into a casino. Instead, I had my program analyze the wheel and betting layout, and came up with a set up numbers and bets to play that makes it very hard for the ball to find an open spot. (DM me if you want these, I have them somewhere)

I never won big money with it, but it made trips to AC and Vegas more enjoyable. Baccarat, that's a different story.

I should re-invent it now that iPhones do exist!  Hmmmm...

I bet we can come up with a better predictive AI today. Just a matter of how much time one's willing to spend on coding --- could make for an interesting QB64 game.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline cfalcon030

  • Newbie
  • Posts: 6
Re: Looking for old program or help recreating it
« Reply #7 on: December 07, 2021, 06:56:08 pm »
If you don't mind me asking, what is your end goal? If it's to determine the randomness of your sample data you will need a different algorithm like a Runs test and not a predictive algorithm.
https://en.m.wikipedia.org/wiki/Wald%E2%80%93Wolfowitz_runs_test

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Looking for old program or help recreating it
« Reply #8 on: December 07, 2021, 07:12:12 pm »
My goal was to try and catch humans (myself) being predictable when I try to be random.

I think if you get an AI that does better than 60% you've got something that catches patterns in human play.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Looking for old program or help recreating it
« Reply #9 on: December 07, 2021, 07:41:09 pm »
This discussion is 90% similar to a thing we studied once, but I took it overboard. I think this handworked example shows a way to answer this question without bogging you guys down with weird notation:

 [ You are not allowed to view this attachment ]  

tldr: there is a 1/4096 chance that this string was hammered out randomly on a keyboard:  0 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 1 1 1 0
You're not done when it works, you're done when it's right.

Offline random1

  • Newbie
  • Posts: 86
Re: Looking for old program or help recreating it
« Reply #10 on: December 08, 2021, 12:19:30 am »
My goal
Whatever code we can come up with, I have the methods to test it's effectiveness.

What I am looking for is a method to predict the next digit using the data string history
to make the prediction.  Everything else has already been coded, ie the before and after
code

Whatever I end up using will be part of a universal forecast / prediction tool.

When I coded the main program I done it in such a way that I can swap out the
predictor code without making any other changes.  The input string is named
Dat1$ and the predictors output variable is PV1$.  Anyone with the time to take
a stab at it can use these two variables for input and output.  Name any other
variables whatever you want.  If your code requires fine tuning of any of the
other variables then supply a list and I will add them to the configuration menu
where they can be adjusted.

The main program is already coded to do all the pre & post processing.  It's fully
functional and uses a prng to simulate the predicted value.  I always do this first
to test the code and secondly to get a base line to measure the predictors output. 
Any good predictor should be able to beat the prng's output.

Like I said, I start with over 800 data strings which are fed to the predictor one at a
time in hopes of finding maybe 25 that are mostly predictable.     

The configuration menu allows adjusting up to 10 constants that may be used by the
predictor for fine tuning.  These include but are not limited to, the number of data points,
# of samples to use, length of each sample, weights, trigger threshold etc...   

For development data just generate random strings 0's and 1's around 3000 to 5000
digits in length.  I will test any posted code against real data and report the results.

Thanks in advance

R1
 
   

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
Re: Looking for old program or help recreating it
« Reply #11 on: December 08, 2021, 12:57:27 am »
This is a cool question. Maybe there's a Markov chain-like hack that can be done to help with this, but I'm still maybe... call it 66% sure that the method I described above can handle this.

The Argument: If the user is doing some kind of pattern apart from randomness when they type, then the pattern may be detectable in any number of "frequencies", which means to say, detectable by looking at "clusters of N digits". For this problem, realistic values of N may be from 2 to say, 10.

The Method: we can define different "alphabets" based on clusters of 1's and 0's in groups of N. For N=2, we have a 4-letter alphabet 00, 01, 10, 11. For N=3, there are quite a few more "letters", i.e. 000, 001, 010, 011, etc etc , 110, 111. I call these clusters "letters" because you should think of each cluster as *one* symbol. Without driving the connection too hard, we can say A=00, B=01, C=10, D=11. Or further, choosing a different set of letters for N=3, a=000, b=001, c=010, etc etc.

With me so far? A big string of 1's and 0's as you have given can be translated into a string made of letters ABCD, which will have half the length as the original. Or, express the original string of 1's and 0's using the N=3 letters to get a shorter translation. Each translation carries the same information, of course. The point is, you can easily see which "letters" are repeated, which are ignored, so on and so forth. It's definitely a way to go. I may try it!

I don't want us to talk past each other though cause if I solve this thing I need an audience of N>0.

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

BUT, that's a lot of work. I think the cheapest, least airtight but nontrivial way to do this uses one variable and one rule: "once the user feels they have repeated themselves X times", remember X.
« Last Edit: December 08, 2021, 01:06:03 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Dimster

  • Forum Resident
  • Posts: 500
Re: Looking for old program or help recreating it
« Reply #12 on: December 08, 2021, 11:08:14 am »
Just looking at your sample set, you could just total the number of times a "0" was selected v's a "1". In your sample set the "0" out numbers the "1" by a large margin. So predicting a "0" at the beginning your program would be correct more times than it's wrong. If "0" is the predominant then that becomes the goto prediction and the program then just needs to watch for the pattern of the "1". ie, if a "1" then how often is the very next select another "1". So you just need the program to decide on when to predict a "1". We all have predictable behaviors. I would think, if you had a moving average for the selection of "1" your program could determine if the user is increasing or deceasing the selection of "1". Not that this kind of pattern prediction would be correct all the time but it could be correct more times than it would be wrong. This approach is not that sophisticated, such a program would not be a true Artificial Intelligent predictor of human behavior because there are only the two inputs (like a flip of a coin). Neither does it "learn" so I'd guess it would plateau in it's effectiveness of correct predictions and be very slow to adapt to the user's change in strategy of selection/repeat selections. But given enough data in the moving average it could adapt as well.

Offline random1

  • Newbie
  • Posts: 86
Re: Looking for old program or help recreating it
« Reply #13 on: December 08, 2021, 07:17:17 pm »
Dimster

All the strings have different ratios of 0's and 1's.  Some work out to 90/10 and your correct that
playing the value with the highest ratio in these cases would produce the most hits.  I am looking
for something that can take into account several factors such as runs of 0's or 1's, frequency, etc.
and then make it's prediction based on these factors. 

STxAxTIC
My manual analysis uses Markov chains and allows searching for strings within the chain.  See the
attached picture

These work well enough, it's the time that it takes, that's the problem.  After 10 or so analysis my mind
is worn out so to say processing the data.  I have a automated version of the Markov string analysis but
it needs some help or a sort of a decision tree to make the final prediction. 

No one piece of information is good enough to base a prediction on, I tried coding a decision tree with no
success as it too needs some sort of learning algorithm that combines the data into experts before
making it's choices.   

In the attached image, looking at the top string of data, you can see the first 4 values highlighted in
blue.  The tool searches the entire string looking for an exact match.  Whenever if finds a match it
records the value preceding the selected pattern.  The second string shows the results of the search

Only a small portion of the main data string is visible in the tools window.  The second string and the graph at the bottom show the results of the search string.  You can also see a simple set of statistics for the returned results. 

Shows (0)= the number of times 0 appears within the results
Out = it's last appearance
Avg= average
L/R = longest run
Probability
STC = short trend shows
Exp = the number of times the value is expected to show in a shortened data set.  It's calculated
using the overall probability * the short trend.  I think stc is set to 20.  You can see by this value
how well the results track with the overall.  If this value is different, ie, higher or lower than it's
expected value than it;s a good indicator to include in the prediction process.
   
The values are displayed for both 0's and 1's.  The color graph is there because it's easier on the eyes
than looking at the 0&1's string.

One approach would be to increase the number of statistical observations and then code some
sort of a decision tree to make the final choice.  The values shown are not sufficient so more
are needed.   In the automated tool I am building all these plus others are planned as part of
the final prediction.
The tool in the picture allows for adding and subtracting digits in the search string, if a person
only knew when to stop, LOL.
 

https://i.postimg.cc/NjvwW9KL/markov-analysis.png 
   

Thanks Again
R1
« Last Edit: December 08, 2021, 07:28:42 pm by random1 »

Offline random1

  • Newbie
  • Posts: 86
Re: Looking for old program or help recreating it
« Reply #14 on: December 08, 2021, 07:52:29 pm »
Something else I find interesting.  The results string shows 95 results.  Any 4 digit binary string
has 16 possible arrangements of 0's and 1's.   The expected average for any one pattern of four
digits is 95/16=6, rounded.  In the picture we can see that the pattern 0110 appears 8 times
which equals  .084 vs the expected .063.  Is this usable, maybe, maybe not.

https://i.postimg.cc/4dgDSryM/ma-2.png

R1

Edit
I missed a, 0110 in the search results, it appears 9 times for .094 hit rate
« Last Edit: December 08, 2021, 08:05:11 pm by random1 »