AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() ![]() We can add some print statements to generate some output as well: Print *, "Result (0=success): ", infoīefore we try to compile this program, we need to enable LAPACK and BLAS linking. If all goes according to plan, the value after calling SGELS should be zero. While we might be able to explain each, the LAPACK documentation does a far superior job. The remaining scalar inputs basically deal with the dimensions of our arrays. The first input, 'N', specifies that the arrays are normal as opposed to transposed. The SGELS call becomes: ! Perform a least squares fit - documentation at: The call to SGELS itself can appear daunting, but we've organized our inputs for this simple problem relatively well. The work array is simply necessary to call SGELS. ! and our totalshots and goals arrays should be properlyĪllocate(adata(n,2), bdata(n,1), work(2*n))Īdata(:,1) = 1.0 ! So an intercept is calculated ! The 'n' variable now holds the number of data points, Real, dimension(:,:), allocatable::bdata, adata ! Arrays for calling LAPACK's SGELS driver Real, dimension(:), allocatable::totalshots, goals The SGELS subroutine will modify the data in both A and b in the course of its operations, so it's often desirable to create arrays just for this task, leaving the original data untouched. This matrix will only have a single column, but we need to create a new array rather than using our original data array directly. We also need a b matrix containing our goals scored data. The first column of A, in order to properly sove for the intercept, should be entirely set to 1.0. Since we also want to calculate a y-intercept in this linear regression, though, our A matrix should have two columns and n rows. Our A matrix will contain the total shots taken data. The overdetermined system we're attempting to solve is defined simply as: To calculate our least squares fit, we need to configure two major arrays. The loading routine is not particularly interesting, so we can continue to our actual least squares analysis with the data properly loaded. ! Load each data point as integers and re-store ! First number is the number of data points The variables n, totalshots, and goals are defined in the main program, but are within the scope of this subroutine: ! Simply loads the NWSL data from a text file Our routine will also assign a variable with the number of data points to allow dimensioning some additional arrays before our analysis begins. We first need a simple subroutine to load the data into two arrays of type REAL for LAPACK to analyze. ![]() The simple data file can be downloaded here: nwsl2016.txt We can eliminate players who did not take any shots since they don't really conform to our analysis. With some minor spreadsheet manipulation, we can build a single text file that contains the number of shots taken by each player and the corresponding number of goals scored by said player over the course of the NWSL 2016 season. Amongst the plethora of data are two sets we would need, shots taken and goals scored by each player. The National Womens Soccer League, or NWSL, is a professional soccer league within the United States, and it started reliably tracking player statistics during its 2016 season. With the proper statistics, we can actually estimate the the percentage of goals resulting from a single player's total number of shots. It would be impossible to score, in fact, if no shots are taken. First, though, we'll need some sample data.įor those familiar with the sport of soccer (or football outside of the United States of America), one might expect that a correlation exists between the number of shots taken and the number of goals scored by any given player. LAPACK provides a number of routines supporting least squares operation, and this example uses SGELS, a single-precision generalized least squares solver. This quick example will look at solving an overdetermined system via a least-squares regression. Both libraries are extremely common within scientific computing, and their inclusion with Simply Fortran should improve productivity for many of our users. LAPACK, or Linear Algebra Package, provides an enormous collection of subroutines for dealing with many types of matrix operations and linear systems, while BLAS, or Basic Linear Algebra Subprograms, provides lower level vector and matrix math operations. With the release of Simply Fortran 2.37, LAPACK and BLAS routines are now easily available on all supported platforms.
0 Comments
Read More
Leave a Reply. |