2022
Notes on calculating online statistics
In this article, I collect simple derivations that demonstrate how to calculate several statistical quantities using point-by-point online statistics. A particular emphasis is made to support multiple weighting schemes (not limited to just uniform weights).
Solving for Spherical Harmonic Analysis Quadrature Weights
In “More Notes on Calculating the Spherical Harmonics”, I used a simple iterative approach to converge on relatively accurate analysis of coefficients from a pixelized image on the sphere. In this article, we will look at the other method to improve the accuracy of approximating integration with finite sums by including so-called quadrature weight factors.
Spherical Harmonic Transforms on Ring-based Pixelizations
In two previous articles, I described the details of performing spherical harmonic synthesis and analysis using an equidistant cylindrical projection (ECP) pixelization scheme as the assumed map format. In this article, I’ll describe the generalizations to the algorithms which permit supporting the transform of any “ring-based” pixelization of the sphere.
More Notes on Calculating the Spherical Harmonics
This article is a long-overdue follow up to Notes on Calculating the Spherical Harmonics which considers the analysis of real-space map on the sphere to its spherical harmonic coefficients.
2020
Basic D&D Statistics: Dice Rolling with Advantage
In the previous part of this series, we explored how to build the probability distributions for sums of dice rolls. That is sufficient for a great fraction of dice rolling in D&D, but a critical extra case to be considered are rolls made with advantage or disadvantage. In this article, we investigate how to extend our definitions to include die rolls with (dis)advantage.
Basic D&D Statistics: Sums of Dice Rolls
Being reliant on the roll of the dice, actions and outcomes in Dungeons and Dragons are fundamentally tied to probability and statistics. In this article I explore how the sums of dice are related to discrete probability distributions, building up from the case of a single die up to combining any arbitrary set of dice. The quantitative tools we develop will be sufficient to make basic assessments on the (un)likeliness of a given observed outcome.
Prefaulting Memory Mapped Arrays in Julia
One of the key facts about memory maps is that the mapping is performed asynchronously, with the data being loaded on demand as it is used. In some cases, though, we may know that the entire mapped region will be required — and only at the end of some other long-running process — so that there would be an advantage to expending some parallel effort to prefault the entire mapping into memory. In this article I motivate such a use case, and then I explore two separate ways of achieving the prefaulting behavior.
Convenient sentinels for keyword arguments in Julia
When writing a high-level interface function that takes many keyword options, the desired default values may sometimes be best set conditionally based on the values of other keywords. In such a case, handling the interdependency among keywords can be easiest if the function declaration uses a sentinel value like
nothing
, but then the type restrictions must be rewritten toUnion{T, Nothing}
in every case, which can get tedious. With a relatively simple macro, though, we can automate this transformation.Pre-normalizing Legendre Polynomials Addendum
The main
Legendre.jl
series contains a detailed article considering the numerical accuracy of the recurrence implementation as a whole. This short addendum presents a mathematical transformation which is used to improve the accuracy of one of the recurrence relation coefficients for the spherical harmonic normalization.Numerically computing the exponential function with polynomial approximations
Numerically computing any non-trivial function (spanning the trigonometric functions through to special functions like the complex gamma function) is a large field of numerical computing, and one I am interested in expanding my knowledge within. In this article, I describe my recent exploration of how the exponential function can be implemented numerically.
Plots of the Spherical Harmonics Eigenmodes
This posting is a simple addendum to the much longer article, Notes on Calculating the Spherical Harmonics. Because it had already grown so long, I left out making any plots of individual eigenmodes, so here I simply present plots of the first 50 degrees of the pure spherical harmonic eigenmodes, which can be useful to help visualize some of the symmetry properties that were discussed in the longer article.
Notes on Calculating the Spherical Harmonics
In this article I review the critical properties of the Spherical Harmonics. In particular, I concentrate on filling in a couple of details regarding numerical computation of the spherical harmonic transformations that I have found to be unstated or less clear than ideal in the literature.
Introducing Legendre.jl
The Legendre.jl package accumulates the features shown throughout this series (and more) into a package expressly designed for calculating numerically accurate Legendre polynomials in a performant manner. In this article I formally introduce the package and demonstrate how it can be used to quickly prototype a couple of useful computations that I have encountered in CMB analysis.
Typesetting ADS references in BibLaTeX bibliographies
The NASA Astrophysical Data System (ADS) is a database of pre-print and peer-reviewed papers spanning physics and astronomy. In particular, the ADS entry links together the pre-print and peer-reviewed papers, so including the ADS entry in a printed BibLaTeX bibliography can be a big convenience to readers of your paper.
Maintaining numerical accuracy in the Legendre recurrences
An algorithm for calculating special functions is no use if it has poor numerical accuracy and returns inaccurate or invalid answers. In this article I discuss the importance of using fused multiply-add (FMA) and a form of loop-unrolling to maintain numerical accuracy in calculating the associated Legendre polynomials to degrees and orders of order 1000 and greater.
Pre-normalizing Legendre Polynomials
In the previous part we computed Legendre polynomials via a few recurrence relations, but the polynomial values grow rapidly with degree and quickly overflow the range of standard finite floating point numbers. In this posting we explore baking in a normalization factor into the recurrence relation — such as used when the Legendre polynomials are used to calculate the spherical harmonics — that eliminates the overflow.
Calculating Legendre Polynomials
The Associated Legendre Polynomials are implicitly defined as the solution to a second-order differential equation, but most practical uses require an efficient means of explicitly evaluating the functions for any degree, order, and argument. In this article I introduce the implementation used in Legendre.jl which is based on evaluating a series of recurrence relations.
Introduction to Associated Legendre Polynomials
The Associated Legendre Polynomials are an important set of functions in cosmic microwave background (CMB) research. In this first part of an upcoming series, I motivate the need for a new high-performance Julia package — Legendre.jl — which I am writing to recreate a key algorithm in my thesis research.
Image-based Color Palette
Building a color theme around a primary photo can be useful, but picking the “main” colors by hand can be a challenge. Thankfully using a couple of simple analysis techniques, we can extract a color palette automatically.
2015
Linear model regression matrices
An extremely common operation on data series is to regress the data with a particular model. Many times, the desired model is a linear combination of known basis functions, and when this is true, the regression of a data series can be encapsulated as a matrix operator. Describing the process as a matrix operation—rather than just using the regression coefficients—isn’t always useful, but it’s description is rarer. Because I needed a regression in this form for my research, I have chosen to write up the solution here.
2014
Bellman k-segmentation algorithm
The Bellman
$k$
-segmentation algorithm generates a segmented constant-line fit to a data series, but in trying to learn and implement this algorithm, I found it difficult to find the segmentation algorithm rather than the [apparently more common]$k$
-means algorithm, so in this article I describe and provide code for the$k$
-segmentation algorithm.Choosing a computationally efficient distance function
One of the simplest statistical properties of a data set is its mean. The next step is often to quantify how well the mean represents the data. A variety of techniques exists, but in this article, I show why the mean-squared error is an excellent choice for dynamic programming algorithms. The mean-squared error has the advantage that it coincides well with our intuitive idea of distance (being closely related to Euclidean distance) as well admitting a computationally efficient implementation.
Random Deviates of Non-uniform Distributions
Most (if not all) programming languages allow you to draw a [pseudo]-random deviate from a uniform distribution. In many scientific situations, though, there is a desire to produce random deviates drawn from a different probability distribution. In this article, I derive relations telling us how to generate these non-uniformly distributed random deviates.