monte-carlo.cuses the monte-carlo method- The random coordinates are generated by the
xorshift128plusPRNG function. - Multiple instances can be ran independently in parallel, stopped at any time, and the results can be averaged together (should be weighted).
- ensure that the PRNG receive different initial seeds
- The random coordinates are generated by the
simple-grid.cpick random points within a grid- Some randomness is involved, but random values are generated within a grid which results in a more uniform distribution.
- Values are only usable and outputted after an entire grid scan, this can take different amount of time depending on the grid size.
- The grid size is defined by
GRID_SIZEat the beginning. - ensure that the PRNG receive different initial seeds
change before compilation
dwellLimit-unsigned long- the maximum number of times a number will be iterated and checked for divergence, convergence, and cyclic orbits before it is deemed asUNDECIDEDC_EQUIVALENCE_THRESHOLD-double- iterations with points closer than this are returned as convergenceO_EQUIVALENCE_THRESHOLD-double- orbits where values are closer than this are considered a memberupdateInvl-unsigned long long- the number of values that will be checked until an update message is printedS_SEED-unsigned long long- this number will be xor'ed with the system time to generate a seedFILE_OUTPUT-intwhen used, actually boolean -1to enable logging to file,0to disable.
This program heavily relies on random so this is important. This section explains where the random values come from.
- Random doubles within range are returned by
_22()and_01(), all these function relies onxorshift128plusto generate its mantissa. xorshift128plusshould be sufficient for this usage- On unix systems the PRNG is seeded by system time,
/dev/urandom, andS_SEED - On windows systems, the PRNG is only seeded by
time(), andS_SEED. This should be good enough due to the chaotic behavior of the function.- IF YOU ARE RUNNING MULTIPLE INSTANCE ON WINDOWS, MAKE SURE THEY ARE NOT STARTED WITHIN 1 SECOND OF EACH OTHER
- After the initial seeding, the function is called 128 times to scramble the states up
- The states are xor'ed with the aforementioned seed sources every time a status message is displayed
Another PRNG can be used in place of this one as long as it returns 64 bits
Using your favorite compiler, compile your choosen file and mem-func.c
Example: using gcc to compile the Monte Carlo file with optimization
gcc .\monte-carlo.c .\mem-func.c -O3 -o monte-carlo
Output is printed to standard output, it is also written into log.txt. Multiple instances of the program (when ran in the same directory) will write to the same file, each instance is identified by its start time provided by time.h
Output is formatted as follows
- When an instance is started -
instance 1645383166 startedis printed (or whatever the time is) followed by a row of keys - When an update is printed (see
updateInvl), a row of comma delimited data is printed in the format oftimestamp, instance, member, not member, undecided; the number of computed area is simply: 16 * (member + (1 or 0 multiplied by) undecided) / (member + undecided + not member) - When membership of a value cannot be determined (dwell limit reached), the number and its exact floating point bit representation is printed
analyze.jsis for a simple and basic overview of the log- paste the log file as an array of strings into
datato the file and execute it with your favorite javascript interpreter - setting
dataIfalsey anddataPtruthy reads data fromlog.txt. THIS ONLY WORKS FOR simple-grid DATA; THIS ONLY WORKS FOR simple-grid DATA; THIS ONLY WORKS FOR simple-grid DATA - results will be printed into console
- The first table is individual analysis of each instance
idis the instance id, or the time the instance was startedcomputationTimeis the amount of time from the instance's start to the time of the output logmem,notmem, andundeciare member, not a member, and undecidedtotalTestedis the number of points testedcomputationRateis the average rate of calculationdiffToAvgHLog10anddiffToAvgLLog10are the common log of the difference from the instance's value to the average value among all instances†dBAHLog10anddBALLog10are the common log of the difference from the instance's value to the best existing average which by default is 1.5065918849±0.0000000028 by Thorsten Förstemann. This can be changed.†- † = the sign of the difference is appended to show potential bias
- Table 2 shows sums of data along with its common log
instanceNumis the number of instances or log filestotalComputationTimeis the total runtime among all instancestotalTested,totalMember,totalNonMember, andtotalUndecidedare the sum of respective values among all instance
- Previous versions of this program included basic statistical analysis of the area estimate, but it was wrong and has been removed. Please analyze the data on your own