Wikipedia Preview for R Markdown documents

Wikipedia Preview (developed by Wikimedia’s Inuka team) is so cool:

When readers navigate in and out of a webpage through interacting with several hyperlinks, they can easily lose context of what they were reading in the first place. Content sites would like their readers to read and engage with their content and understand it without having to get contextual information elsewhere. Wikipedia Preview can solve this problem for content providers by allowing readers to have concise and visual contextual information from Wikipedia within a content provider’s mobile properties - website or webapp.

Making Of: Session Tick visualization

In this post I will walk through my R code for a data visualization I created for the session length dataset project at the Wikimedia Foundation.

Animation of optimization in torch

In this post I will show you how to use the {gganimate} R package to make an animated GIF illustrating Adam optimization of a function using {torch}:

Animated GIF illustrating Adam optimization of a function

library(torch)
library(gganimate)
library(tidyverse)

We will use torch::optim_adam() to find the value of x that minimizes the following function:

f <- function(x) (6 * x - 2) ^ 2 * sin(12 * x - 4)

The function looks as follows:

The adam_iters dataset will contain an iter column (for the iteration/step identifier) and an x column (the value of x after each iteration):

Pivoting posteriors

In Stan, when a parameter is declared as an array, the samples/draws data frame will have columns that use the [i] notation to denote the i-th element of the array. For example, suppose we had a model with two parameters – \(\lambda_1\) and a \(\lambda_2\). Instead of declaring them individually – e.g. lambda1 and lambda2, respectively – we may declare them as a single lambda array of size 2:

parameters {
  real lambda[2];
}

When we sample from that model, we will end up with samples for lambda[1] and lambda[2]. We want to extract the i from [i] and the name of the parameter into separate columns, yielding a tidy dataset.