Change-Property Toolbar getting sloppy

Having made a simple dice roller statistic report using three Global Properties and the Hotkeys for the Change-Property Toolbars, it worked fine. For a while.

This is how the report on the hotkeys looks like

* Soviet CRT roll number 1 = 10
* added to Soviet CRT roll total = 10
* Soviet CRT roll average = 10

After a few rolls the third report gets missing from time to time and then all together.

* Soviet CRT roll number 4 = 6
* added to Soviet CRT roll total = 22

* Soviet CRT roll number 5 = 8
* added to Soviet CRT roll total = 30
* Soviet CRT roll average = 6

* Soviet CRT roll number 6 = 6
* added to Soviet CRT roll total = 36

* Soviet CRT roll number 7 = 3
* added to Soviet CRT roll total = 39
* Soviet CRT roll average = 5

* Soviet CRT roll number 8 = 8
* added to Soviet CRT roll total = 47

* Soviet CRT roll number 9 = 6
* added to Soviet CRT roll total = 53

* Soviet CRT roll number 10 = 1
* added to Soviet CRT roll total = 54

The number rolled is added to a GP, and this GP value is divided by the number of rolls (a second GP) to calculate the average (the third GP).

Here is a link to a tiny example module showing the strange behavior:

Any help is welcome.

The reason you see no print-out of the new average is because the value stored in that Global Property didn’t change. Hence, there were no change, and therefor there’s no report of the change.

Also, you should probably cast your sum to a float when you do the division by number of observations, so that you get a decimal average. If you sum property is called Sum and your count property is called N, then the calculation of the average property (say Average) value should be

{((float)Sum) /  N}

When you print it out, you may want to round it to some number of digits after the decimal point. For example

{Math.round(Average * 100) / 100}

How many decimal points to round to really depends on the uncertainty on the mean, which is given by √(Variance/N). The variance is given by 1/(N-1)Σ (x_i - Average)^2. The uncertainty should be quoted with one significant digit, and the value - the average - should be given to the same precision.

In fact, it doesn’t really make sense to report the average without also quoting the spread, given by √(Variance). The mean only tells you what the user’s expectation value is, not how widely it is distributed. Thus, you should really also calculate the variance and quote the spread.

Normally, one can only calculate the variance after the mean as been measured, and one must have the full set of observations to do so. That is impractical in Vassal. However, there is a way to calculate a running value of the variance. For the first observation x, we set

  • Average = x
  • Variance = 0
  • N = 1

For subsequent observations x, we set

  • OldAverage = Average
  • OldVariance = Variance
  • OldN = N
  • N = OldN + 1
  • Average = OldAverage + 1 / N * (x - OldAverage)
  • Variance = (N - 2) / (N - 1) * OldVariance + 1 / (N - 1) * (x - OldAverage) * (x - Average)

(see also Wikipedia).

If the variance differs significantly from the expected variance, then there’s cause to think that the distribution isn’t perhaps the expected distribution. One cannot use the mean to draw such a conclusion.

Yours,
Christian

Many thanks, Christian,

that solved the “mystery.” And as a side effect, it helped to employ the result properly as float.