Variables | |
| df = ROOT.RDataFrame(npoints) | |
| incircle = pidf.Filter("r <= 1.0").Count().GetValue() | |
| Now we have a dataframe with columns x, y, p (which is a point based on x and y), and the radius r = sqrt(x*x + y*y). | |
| int | npoints = 10000000 |
| We will inefficiently calculate an approximation of pi by generating some data and doing very simple filtering and analysis on it. | |
| float | pi_approx = 4.0 * incircle / npoints |
| pidf | |
| Define what data we want inside the dataframe. | |
| df012_DefinesAndFiltersAsStrings.df = ROOT.RDataFrame(npoints) |
Definition at line 25 of file df012_DefinesAndFiltersAsStrings.py.
| df012_DefinesAndFiltersAsStrings.incircle = pidf.Filter("r <= 1.0").Count().GetValue() |
Now we have a dataframe with columns x, y, p (which is a point based on x and y), and the radius r = sqrt(x*x + y*y).
In order to approximate pi, we need to know how many of our data points fall inside the circle of radius one compared with the total number of points. The ratio of the areas is
A_circle / A_square = pi r*r / l * l, where r = 1.0, and l = 2.0
Therefore, we can approximate pi with four times the number of points inside the unit circle over the total number of points:
Definition at line 45 of file df012_DefinesAndFiltersAsStrings.py.
| int df012_DefinesAndFiltersAsStrings.npoints = 10000000 |
We will inefficiently calculate an approximation of pi by generating some data and doing very simple filtering and analysis on it.
We start by creating an empty dataframe where we will insert 10 million random points in a square of side 2.0 (that is, with an inscribed unit circle).
Definition at line 24 of file df012_DefinesAndFiltersAsStrings.py.
Definition at line 47 of file df012_DefinesAndFiltersAsStrings.py.
| df012_DefinesAndFiltersAsStrings.pidf |
Define what data we want inside the dataframe.
We do not need to define p as an array, but we do it here to demonstrate how to use jitting with RDataFrame.
Definition at line 30 of file df012_DefinesAndFiltersAsStrings.py.