Adam T. Bradley

Social Network Simulation with PaperJS

What it’s doing: Each “node” has a “belief” that matches its hue, represented as an angle between 0 and 359 degrees. Every 25 frames (once a second or so), a node is chosen at random and given a choice whether to speak; if it does (this is represented by a fading circle expanding from the node). Every other node has a chance to hear the speaking node based on the distance between the speaker and the listener–the farther you are from the speaker, the less likely you are to hear.

Once a node does hear another node, it will only care about what it’s hearing under one of two conditions:

  1. The hearer’s beliefs (i.e. color) are similar to the speakers, in which case the hearer’s beliefs will move slightly closer to the speaker’s; or
  2. The hearer’s beliefs are very different from the speakers, and its beliefs will move even further away from the speaker’s.

In either case, there is a small chance the hearer will “subscribe” to the speaker, which adds a line between the two and means the hearer will always hear announcements from that speaker.

NB: This isn’t designed–at least in this incarnation–to be a realistic simulation of anything. It’s another experiment with PaperJS.

Word Hail

This is a minor experiment with Paper.js, made while I (re-)teach myself to animate color and movement. (Click through to view.)

RMarkdown and Jekyll

While migrating my blog recently from WordPress to Jekyll, I looked for easy ways to post RMarkdown documents to my blog. I ended up developing two options of my own (available on GitHub):

jekyll.R provides two R functions to let you add posts or drafts to your Jekyll blog direct from the RStudio console, by knit()ing an .Rmarkdown document into markdown with the YAML “front-matter” Jekyll expects. This is probably the best option for blogs.

rmarkdown_converter.rb is a Jekyll plugin that provides an Rmarkdown “converter”. This lets write your posts in RMarkdown and save them in your site’s _drafts or _posts directory with the extension Rmd or Rmarkdown, just like you normally post standard markdown documents.

The downside here is that changes to your R environment (you get a new computer and don’t reinstall all of the packages you had before, you upgrade R and one of the packages you used to use is no longer supported, etc.) can make it impossible to build your blog (or at least some posts). It might be more useful for some non-blog sites.

This code borrows heavily from the sample converter on the Jekyll plugins documentation page and this post by Simon Elliston Ball.

Stately and sexual health

|

I've been asked to look into doing some kind of analysis of this Sexual Health Rankings data. The data's available as a spreadsheet providing data by state, so I'm using my preliminary, check-this-stuff-out phase, as an opportunity to check out R's xslx package and Stately.

xslx allows you to read and write Excel workbooks from R. Below, I use the high-level read.xslx function to read blocks of cells from worksheets as dataframes, which is quick and easy to work with.

Stately is a quick and easy (and fun) way to draw simple choropleth maps of the US. It's implemented as a font and some CSS; to use it in a web page, you just create a list with each letter A-Z and a-y and style the elements as needed. I've written an R script that generates the html you need to generate a map with Stately.

More Shiny

Another Shiny app, this one taking data on U.S. unemployment from Quandl and generating graphs and tables describing it. I was mainly trying to update my Shiny knowledge based on the new(-ish) version 0.4.

ShinyUnemployment

This app is on GitHub, so it should be possible to run it with:

runGitHub(‘shiny_unemployment’, ‘atbradley’)

What’s Matt Listening To?

Matt Asher, over on his blog, analyses the playlist from a local pop-music station in Toronto, and provides an interesting script for generating HTML-based charts in R. He wonders how Radio Paradise‘s playlist would look in comparison.

I copy-pasted five days worth of Radio Paradise’s playlist into this file and tinkered with it in R.

library(devtools)
source_gist(<a href="https://gist.github.com/atbradley/5034250" target="_self">5034250</a>)

We have here 1530 individual plays, with 1274 unique tracks. That already sounds like more variety than Toronto’s Virgin Radio offers–most songs on RP were only played once. This makes the kind of chart Matt did for Virgin Radio a little boring here:

cat(HTML.chart(smry, 250, ytLinks = T))
   Band of Horses: On My Way Back Home
   Fleet Foxes: Your Protector
   The Derek Trucks Band: This Sky
   Anna Ternheim: Bow Your Head
   Big Sugar: Come A Little Closer
   Calexico: Sinner In The Sea
   Cult With No Name: Under The Dirt
   Cult with No Name: You Know Me Better Than I Know Myself
   Death Cab for Cutie: Home Is a Fire
   Elvis Costello: Pump It Up
   Fink: Warm Shadow
   Jenn Grant: The Fighter
   Johnny Marr: The Messenger
   Keren Ann: My Name Is Trouble
   Laura Marling: Devil’s Spoke
   Neil Halstead: Full Moon Rising
   Night Beds: 22
   Night Beds: Ramona
   Radical Face: Black Eyes
   Rebecca Zapen: Colorado
   Soha: C’est bien mieux comme ca
   Stereophonics: In a Moment
   The Cinematic Orchestra: To Build A Home
   The Jam: Town Called Malice
   The Slow Show: Falling Slow
   1 Giant Leap: The Way You Dream (feat. Michael Stipe and Asha Bhosle)
   Aimee Mann: Charmer
   Air: La Femme D’Argent
   Alpha Rev: New Morning
   Alt-J: Something Good
   Alt-J: Tessellate
   Amy Winehouse: You Know I’m No Good
   Andrew Bird: Tenuousness
   Ane Brun: These Days
   Anna Ternheim: What Have I Done
   Anni B Sweet: Take On Me
   Antje Duvekot: Phoenix
   Arcade Fire: We Used To Wait
   Barra and Govinda: Through The Veil
   Basia Bulat: Go On
   Beck: Beautiful Way
   Beck: Paper Tiger
   Ben Harper: Jah Work
   Beth Orton: Dawn Chorus
   Beth Orton: Magpie
   Blood Sweat & Tears: I Love You More Than You’ll Ever Know
   Bob Dylan: Don’t Think Twice, It’s All Right
   Bob Marley: Sun Is Shining
   Bohren & Der Club Of Gore: Constant Fear
   Bonobo: El Toro
   Bonobo: Nitelight
   Bruce Cockburn: Wondering Where the Lions Are
   Built To Spill: Gone
   Built To Spill: Wherever You Go
   Cake: Love You Madly
   Calexico: Splitter
   Cat Power: Cherokee
   Choir of Young Believers: Hollow Talk
   Chris Whitley: To Joy (Revolution of the Innocents)
   Christians and Lions: Skinny Fists
   Claude Chalhoub: Don’t Wake Me Up
   Coldplay: Spies
   Cowboy Junkies: Lay it Down
   Crowded House: Private Universe
   Dandy Livingstone: Rudy a Message to You
   Danger Mouse & Daniele Luppi: Problem Queen (w/ Norah Jones)
   Dave Matthews Band: Broken Things
   David Bowie: Ziggy Stardust
   Death Cab for Cutie: Doors Unlocked and Open
   Dengue Fever: Uku
   Depeche Mode: Precious
   Dire Straits: Ride Across The River
   Dire Straits: Sultans Of Swing
   Dire Straits: The Man’s Too Strong
   Dire Straits: When It Comes To You
   Doc Watson: Windy and Warm
   Donovan: Sunshine Superman
   Doves: Lifelines
   Duke Ellington: How High The Moon
   Eastmountainsouth: The Ballad Of Young Alban and Amandy
   Elbow: Grounds For Divorce
   Elbow: Lippy Kids
   Elbow: Red
   Elephant Revival: Cosmic Pulse
   Elliott Brood: The Valley Town
   Emily Barker & the Red Clay Halo: Fields of June (w/ Frank Turner)
   Fleetwood Mac: Landslide
   George Harrison: What Is Life
   Gillian Welch: Scarlet Town
   Githead: Take Off
   Gomez: Just As Lost As You
   Gooding: First Lullabye
   Great Lake Swimmers: Your Rocky Spine
   Gregory Alan Isakov: That Moon Song
   Grinderman: Star Charmer
   Grizzly Bear: Speak In Rounds
   Ian Moore: Civil Light
   Interpol: The Scale
   Ismael Lo: Tajabone
   Jack White: Love Interruption
   Jenny Lewis: Pretty Bird
   Jesse Sykes & The Sweet Hereafter: The Dreaming Dead
   Jimi Hendrix: The Wind Cries Mary
   Jimmy Cliff: The Harder They Come
   Joan Osborne: Brokedown Palace
   John Cale & Brian Eno: Lay My Love
   John Lee Hooker: Dimples
   John Lee Hooker: This Is Hip
   Joni Mitchell: Cold Blue Steel And Sweet Fire
   José González: Stay in the Shade
   José González: Killing For Love
   Junip: Line Of Fire
   Kate Miller-Heidke: The Devil Wears a Suit
   Kathleen Edwards: Goodnight, California
   Led Zeppelin: Dazed and Confused
   Loreena McKennitt: Marco Polo
   Los Lobos: Bertha
   Lucinda Williams: Rescue
   Ludovico Einaudi: Divenire
   Ludovico Einaudi: Primavera
   Luna: California (All the Way)
   Lyle Lovett: Friend Of The Devil
   Mark Knopfler: Privateering
   Medeski, Martin & Wood: Ice
   Morcheeba: Enjoy the Ride
   Morcheeba: Over & Over
   Morcheeba: The Music That We Hear (Moog Island)
   Muddy Waters: I Can’t Be Satisfied
   Neko Case: Hold On, Hold On
   Neko Case: Things That Scare Me
   Nick Drake: Pink Moon
   Nick Drake: Things Behind The Sun
   Norah Jones: Light as a Feather
   Norah Jones: Say Goodbye
   Orchestra Baobab: Dee Moo Woor
   PJ Harvey: On Battleship Hill
   PJ Harvey: You Said Something
   Patti Smith: Nine
   Paul Weller: Dragonfly
   Peter Gabriel: Digging in the Dirt
   Peter Gabriel: Sky Blue
   Peter Gabriel: Solsbury Hill
   Peter Tosh: Mystery Babylon
   Pinback: Sender
   Queens Of The Stone Age: No One Knows
   R.E.M.: New Test Leper
   Rachel Zeffira: The Deserters
   Radiohead: Staircase
   Radiohead: Street Spirit (Fade Out)
   Ray LaMontagne: Be Here Now
   Red Rider: Lunatic Fringe
   Redd: Hala Ask Var Mi
   Rilo Kiley: Dreamworld
   Rilo Kiley: Hail To Whatever You Found In The Sunlight That Surrounds You
   Rolling Stones: Monkey Man
   Rolling Stones: Time Waits For No One
   Roxy Music: Love is the Drug
   Sade: No Ordinary Love
   Santana: Se A Cabo
   Sarah Blasko: I Awake
   Sarah McLachlan: Sweet Surrender
   Serafina Steer: Night Before Mutiny
   Shivaree: Goodnight Moon (Live at KCRW)
   Silversun Pickups: Draining
   Son Volt: Live Free
   Sophie Zelmani: Hard To Know
   Specials: Ghost Town
   Spirit of the West: And If Venice is Sinking
   Stevie Wonder: Superstition
   Stone Roses: Fools Gold
   Stone Roses: I Wanna Be Adored
   Stranglers: Golden Brown
   Sun Kil Moon: Gentle Moon
   Supergrass: Hollow Little Reign
   Supergrass: Tales Of Endurance
   Suzanne Vega: Rock in This Pocket (Song of David)
   Talking Heads: Crosseyed And Painless
   Tame Impala: Elephant
   The Bad Plus: Flim
   The Barr Brothers: Beggar In The Morning
   The Beatles: Come Together
   The Beatles: Dear Prudence
   The Black Keys: Gold On the Ceiling
   The Black Keys: Sister
   The Cure: Close To Me
   The Cure: Just Like Heaven
   The Cure: Lullaby
   The Dandy Warhols: Love Song
   The Decemberists: Calamity Song
   The Decemberists: Don’t Carry It All
   The Donnis Trio: Tip of the Tongue
   The Doors: People Are Strange
   The Kinks: A Well Respected Man
   The Lumineers: Stubborn Love
   The Police: Driven To Tears
   The Psychedelic Furs: Heaven
   The Republic Tigers: Buildings and Mountains
   The Shins: Bait And Switch
   The Shins: Black Wave
   The Spring Standards: Watch the Moon Disappear
   The Veils: The Leavers Dance
   The Wallflowers: Reboot The Mission (w/ Mick Jones)
   The Who: Love, Reign O’er Me
   Thea Gilmore: All Along The Watchtower
   Thievery Corporation: Forgotten People
   Thievery Corporation: Lebanese Blonde (w/ Pam Bricker)
   Thievery Corporation: The Richest Man in Babylon
   Tom Petty: Breakdown
   Tom Petty: You Got Lucky
   Tom Waits: Please Call Me, Baby
   Tor: Glass & Stone
   Tori Amos: Strange Little Girl
   Trace Bundy: Bristlecone
   Trentemøller: Sycamore Feeling
   U2: The Unforgettable Fire
   VAST: I Know How To Love
   Vetiver: You May Be Blue
   Vienna Teng: Blue Caravan
   Waifs: Lighthouse
   Ween: Flutes of The Chi
   Wilco: Outtasite (Outta Mind)
   Wilco: You Are My Face
   Wild Nothing: Shadow
   Wye Oak: Civilian
   Yo La Tengo: The Point of It
   Yoav: Yellowbrite Smile
   Younger Brother: Train
   thenewno2: Never Too Late
   !Deladap: Lautlos
   10,000 Maniacs: Don’t Talk
   A Filetta: Like a Breath of Air
   A Fine Frenzy: Pinesong
   A Fine Frenzy: They Can’t If You Don’t Let Them
   A Man Called Adam: Yachts
   Aaron Copland: Fanfare for the Common Man
   Afro Celt Sound System: Big Cat
   Afro Celt Sound System: Mojave
   Afro Celt Sound System: Onwards
   AfroCubism: Djelimady Rumba
   Agnes Obel: Riverside
   Aimee Mann: Calling It Quits
   Aimee Mann: Great Beyond
   Aimee Mann: Humpty Dumpty
   Aimee Mann: Wise Up
   Air: Alone In Kyoto
   Air: Mer Du Japon
   Air: Space Maker
   Alexi Murdoch: Towards The Sun
   Alison Krauss & Union Station: Lie Awake
   Alison Krauss / Gillian Welch: I’ll Fly Away

Charting the artists played rather than the tracks gives us a more interesting chart, and reveals that someone at Radio Paradise really likes the Beatles and U2:

cat(HTML.chart(smry.artists, 250))
   The Beatles
   U2
   Radiohead
   The Shins
   Dire Straits
   Peter Gabriel
   Calexico
   Porcupine Tree
   R.E.M.
   Rolling Stones
   Beck
   The Cure
   Elbow
   Elvis Costello
   The Black Keys
   Tom Petty
   Wilco
   Cowboy Junkies
   Los Lobos
   Morcheeba
   Talking Heads
   Beth Orton
   Bob Dylan
   Bob Marley
   Fleetwood Mac
   Neko Case
   Norah Jones
   Pearl Jam
   Supergrass
   The Dandy Warhols
   The Decemberists
   Thievery Corporation
   Aimee Mann
   Andrew Bird
   Anna Ternheim
   Arcade Fire
   Chris Isaak
   David Bowie
   Death Cab for Cutie
   Doves
   Eels
   Fleet Foxes
   John Lee Hooker
   Led Zeppelin
   Nick Drake
   Night Beds
   Patty Griffin
   Pink Floyd
   Radical Face
   The Derek Trucks Band
   Tori Amos
   Air
   Alt-J
   Band of Horses
   Ben Harper
   Big Sugar
   Built To Spill
   Cake
   Crowded House
   Elliott Smith
   Gomez
   Great Lake Swimmers
   Iron & Wine
   Jack White
   Neil Halstead
   PJ Harvey
   Stevie Wonder
   The Doors
   The Kinks
   The Who
   Black Rebel Motorcycle Club
   Bonobo
   Bruce Cockburn
   Cult With No Name
   Dave Matthews Band
   Death Cab For Cutie
   Dengue Fever
   Depeche Mode
   Elephant Revival
   Fink
   Grateful Dead
   Harry Manx
   Jeff Beck
   John Lennon
   Joni Mitchell
   José González
   Loreena McKennitt
   Lucinda Williams
   Ludovico Einaudi
   Mark Knopfler
   Morphine
   Muddy Waters
   Neil Young
   Oi Va Voi
   Other Lives
   Paul Simon
   Ray LaMontagne
   Rilo Kiley
   Santana
   Silversun Pickups
   Son Volt
   Spoon
   Stereophonics
   Stone Roses
   Suzanne Vega
   The Police
   The Pretenders
   Tom Waits
   Vast
   Wye Oak
   Younger Brother
   Afro Celt Sound System
   Amy Winehouse
   Antje Duvekot
   Bat For Lashes
   Boy & Bear
   Broken Bells
   Broken Social Scene
   Caro Emerald
   Cracker
   Cult with No Name
   Danger Mouse & Daniele Luppi
   Doc Watson
   Duke Ellington
   Eric Clapton
   First Aid Kit
   Gillian Welch
   Githead
   Gotye
   Gregory Alan Isakov
   Gustavo Santaolalla
   Guster
   Hooverphonic
   Jefferson Airplane
   Jenn Grant
   Jenny Lewis
   Jimi Hendrix
   Jimmy Cliff
   Joe Strummer & The Mescaleros
   Johnny Marr
   José González
   Junip
   KT Tunstall
   Kate Miller-Heidke
   Kathleen Edwards
   Keren Ann
   Laura Marling
   Leo Kottke
   Lost In The Trees
   Luna
   Madrugada
   Massive Attack
   Medeski, Martin & Wood
   My Morning Jacket
   Old 97s
   Paul Weller
   Poe
   Rebecca Zapen
   Robert Plant
   Sarah Blasko
   Sarah McLachlan
   Soha
   Sophie Zelmani
   Tame Impala
   The Barr Brothers
   The Byrds
   The Cinematic Orchestra
   The Jam
   The National
   The Republic Tigers
   The Slow Show
   The Smashing Pumpkins
   The Wailin’ Jennys
   The Wallflowers
   Thea Gilmore
   Toad The Wet Sprocket
   Toots & The Maytals
   Van Morrison
   Vienna Teng
   Ween
   thenewno2
   1 Giant Leap
   A Fine Frenzy
   Alpha Rev
   Amadou & Mariam
   Amy Macdonald
   Ane Brun
   Anni B Sweet
   Aretha Franklin
   Barra and Govinda
   Basia Bulat
   Big Country
   Big Head Todd & The Monsters
   Billie Holiday
   Björk
   Blackfield
   Blood Sweat & Tears
   Bohren & Der Club Of Gore
   Buffalo Springfield
   Cat Power
   Chinawoman
   Choir of Young Believers
   Chris Whitley
   Christians and Lions
   Claude Chalhoub
   Cloud Cult
   Coldplay
   Creedence Clearwater Revival
   Crosby Stills & Nash
   Dandy Livingstone
   David Byrne & St. Vincent
   David Gilmour
   Derek and the Dominoes
   Donovan
   Eastmountainsouth
   Elliott Brood
   Elton John
   Emily Barker & the Red Clay Halo
   Entrain
   Equation
   Feist
   Fiona Apple
   Flaming Lips
   Garbage
   George Harrison
   Glen Hansard
   Gooding
   Greg Laswell
   Grinderman
   Grizzly Bear
   Gus Black
   Hem
   I Am Kloot
   Ian Moore
   Imogen Heap
   Interpol
   Ismael Lo
   J.J. Cale
   Jackson Browne
   James Taylor
   Jenny Lewis & The Watson Twins
   Jesse Sykes & The Sweet Hereafter
   Joan Osborne
   Joe Bonamassa
   John Cale & Brian Eno
   John Hiatt
   John Martyn
   John Mellencamp
   Kate Bush
   Little Feat

It could be interesting to do this kind of analysis with soma fm. Their stations–at least all the ones I’ve checked–post their playlists to Twitter, which gives us a built-in API for importing their playlist feeds. It might also be interesting (or it might not) to use Last.fm’s API to pull a list of user-contributed tags for each song, and analyze radio stations that way (or use the data to recommend radio stations to last.fm users).