|
Post by turtleman on Aug 13, 2023 11:53:25 GMT -5
I'm trying to calculate the moving (or running) average in real time. Only four numbers (comprised of 1 or 2 digits) need to be averaged at a time, while the number of values can be in the thousands. I'm pretty sure this calls for using an array, but so far I'm stumped. There's probably an LB example out there somewhere, and a point in the right direction would be most appreciated. Thanks!
|
|
|
Post by tsh73 on Aug 13, 2023 12:39:55 GMT -5
Have a look The data was random spikes over sin() I put results into Open Office to see it indeed do average. n=100 dim a(n) pi=acs(-1) for i =1 to n aa=4*pi*i/n a(i)=2*rnd(0)+10*sin(aa) if i>3 then 'needs 4 data points to count average avg=(a(i)+a(i-1)+a(i-2)+a(i-3))/4 end if print i, a(i), avg next
|
|
|
Post by tenochtitlanuk on Aug 14, 2023 5:12:31 GMT -5
|
|
|
Post by tenochtitlanuk on Aug 14, 2023 6:28:17 GMT -5
nomainwin
WindowWidth =1000 WindowHeight = 650
open "Display" for graphics_nsb as #wg
#wg "trapclose quit"
#wg "down ; fill 180 180 180 ; size 4"
aveTerm =0
for i =1 to 140 newTerm =( -1 +2 *rnd( 0)) +10 *sin( i /10) aveTerm =aveTerm *0.75 +newTerm *0.25 #wg "color red ; set "; 10 +i *7; " "; int( 350 +20 *newTerm) #wg "color green ; set "; 10 +i *7; " "; int( 350 +20 *aveTerm) scan next
#wg "flush ; getbmp scr 1 1 1000 650" bmpsave "scr", "runningAveraged.bmp"
wait
sub quit h$ close #h$ end end sub
|
|
|
Post by turtleman on Aug 14, 2023 6:57:28 GMT -5
Thanks a lot for everyone's help. I have to admit, however, that so far I've been unable to adopt the examples to my application. And as usual, I'm amazed how concise the examples are compared to my usual spaghetti code.
I need more time to figure this out and will get back with the results. Thanks again – your efforts are very much appreciated!
|
|
|
Post by tsh73 on Aug 14, 2023 7:54:17 GMT -5
|
|
|
Post by turtleman on Aug 14, 2023 8:32:43 GMT -5
tsh73: Thanks Anatoly, but I already saw the Wikipedia descriptions, along with descriptions on several other sites, and was also amazed at the different types of moving averages. For my gambling application, I'm mainly interested in trying to detect trends. Yeah, I know, "past performance isn't necessily indicative of future results"; but after 38 years of casino play, I’m leaving no stone unturned. The results from my simulator have matched my casino results with uncanny accuracy, though of course, it still hasn't shown the path to riches! It has, however, shown what doesn't work. Anyway, if persistence pays, my day is coming!
|
|
|
Post by Walt Decker on Aug 14, 2023 9:10:55 GMT -5
I do not know if this is on wiki but:
' PP = 0 PM = 0 P1 = 0 P2 = 0 P3 = 0 P4 = 0 Mean = 0 LowRng = 200 HiRng = 500
P1 = FN.GetNumber(LowRng, HiRng) P2 = FN.GetNumber(LowRng, HiRng) P3 = FN.GetNumber(LowRng, HiRng) P4 = FN.GetNumber(LowRng, HiRng) Mean = FN.Average(P1, P2, P3, P4) PRINT "AVERAGE = "; Mean
FOR I = 1 TO 100 PP = P4 PM = P3 P4 = FN.GetNumber(LowRng, HiRng) P3 = PP PP = P2 P2 = PM P1 = PP Mean = FN.Average(P1, P2, P3, P4) PRINT "AVERAGE = "; Mean NEXT I
END
FUNCTION FN.GetNumber(LowNum, HighNum)
Num = 0 Num = RND(0) * (HighNum - LowNum) + LowNum
FN.GetNumber = Num END FUNCTION
'----------------- '-----------------
FUNCTION FN.Average(N1, N2, N3, N4)
Ave = 0 Ave = (N1 + N2 + N3 + N4) / 4
FN.Average = Ave END FUNCTION '
|
|
|
Post by meerkat on Aug 14, 2023 9:33:30 GMT -5
you may want to try a MLR (multiple linear regression) this program allows any number of variables. For example if you had maybe a Ace club, 7 diamond, 3 spades or whatever. You could set it up to show you the probability of success. MLR post
|
|
|
Post by Rod on Aug 14, 2023 12:30:32 GMT -5
It’s maths, you will never beat the house.
|
|
|
Post by turtleman on Aug 14, 2023 12:40:36 GMT -5
Really? I never heard that before! LOL
|
|
|
Post by Rod on Aug 14, 2023 13:49:49 GMT -5
Well history tells us Casino wins, Punter loses, else we would be inundated with rich punters and not the mega rich casinos we have.
|
|
|
Post by turtleman on Aug 14, 2023 14:13:33 GMT -5
True, but casino gambling (for me) is a lot cheaper and somewhat safer than scuba and skydiving! Besides, it's just entertainment! Yeah, sure it is!
|
|
|
Post by Rod on Aug 15, 2023 3:09:26 GMT -5
Entertainment is fine. The next issue for me with a moving average is that you are looking backwards, how to turn it round and make it predictive? A working card or dice or roulette example would give our mathematicians something to play with.
|
|
|
Post by meerkat on Aug 15, 2023 6:03:58 GMT -5
You can use multiple linear regression (MLR) for predictive modeling. Multiple linear regression is a statistical technique used to model the relationship between multiple independent variables (also known as predictors or features) and a dependent variable (also known as the target or outcome). It's commonly used for predictive analysis when you want to understand how changes in the predictor variables are associated with changes in the target variable.
The problem I see is how to select the variables. In the case of the roulette, you may want a simple regression analysis where you simply give it a list of the numbers as the show up. But MLR always needs something to base it on. Like time of day, or previous number - who knows. It would be interesting to see what the predictions would be. It may find that the numbers have some bias based on time, or temperature, or both. Then again it may predict nothing. That's the challenge. Just tooo much fun.
|
|