Testing Benford’s Law in Symfony 5, Php Framework
Benford’s law used for election data, deepfakes, Genome data, scientific fraud detection, accounting fraud detection and macroeconomic data.
Dr. Frank Benford discovered that in many cases, the number 1 is the first digit about 30,1% of the time. For example, most numbers in a set (about 30,1%) will have a leading digit of 1. This is followed by about 17.6% starting with a number 2 and each subsequent numeral, 3 through 9, will be the leading digit with decreasing as seen in the image.
Testing Benford’s Law in Symfony Framework
In the traditional Symfony web application we want to find out how often “1” to be the first digit of the total line-numbers for each PHP file. We want to do same for each subsequent numeral, 2 through 9. To do this create a new traditional Symfony web application and count the line-numbers for each PHP file in Symfony. Then we will compare our result with Benford’s Law.
Open your terminal and run command as below:
find . -name \*.php -exec wc -l {} \; | awk ‘{print $1}’ | sort | cut -b 1 | uniq -c
\*.php check all the PHP files (or at least all files with a .php extension)
Word Count (wc) -l counts lines.
awk can be used for text processing.awk treats tab or whitespace for file separator by default.
After running this command result on Symfony 5.1 would be as below;
1217 1
973 2
813 3
507 4
419 5
420 6
256 7
214 8
201 9
There are some minor differences. But 1 is highest and numbers scale down pretty smoothly.
— — —
Here’s my articles which might interest you;
Formats Supported By the API Platform