Giles Bowkett

Summarized using AI

Archaeopteryx: Lambdas in Detail

Giles Bowkett • February 11, 2015 • Earth

In the presentation "Archaeopteryx: Lambdas in Detail" at the MountainWest RubyConf 2010, speaker Giles Bowkett introduces the Archaeopteryx library, which facilitates music creation in Ruby using the MIDI protocol. The session is designed as a Q&A format, inviting interactions and questions from the audience. Bowkett discusses several key points regarding the use of Archeopteryx and its relation to programming concepts including Lambdas and probability matrices.

Key points covered include:

  • Introduction to Archaeopteryx:

    • Archaeopteryx is a Ruby library for creating music, relying on MIDI commands for synthesizing sound.
    • Bowkett emphasizes the simplicity of MIDI as a protocol, drawing parallels to basic programming concepts.
  • Lambdas in Ruby:

    • Lambdas are introduced as a powerful feature in Ruby that provide functionality similar to JavaScript functions.
    • Bowkett explains how to create objects and define accessor methods that incorporate lambdas, enhancing the functional capabilities of Ruby.
  • Understanding Google PageRank:

    • The presentation covers the PageRank algorithm, simplifying its core concepts into a probability matrix, which is crucial for understanding how search engines rank pages based on links.
    • The discussions emphasize that the complex functionality of systems like Google can often be distilled into straightforward principles.
  • Implementation Examples:

    • Bowkett showcases how simple code implementations can illustrate concepts such as spelling correction and probability matrices, using examples from Python and Ruby.
    • He discusses a historical context involving machine learning and probability in programming, particularly in fun contexts like Rock Paper Scissors.
  • Rhythm Generation with Archeopteryx:

    • The practical application of Archaeopteryx is demonstrated with a software program allowing users to create and manipulate drum rhythms. Bowkett illustrates how varying parameters in the code can dynamically alter musical outputs, making creative adjustments on-the-fly.
    • He highlights the importance of metaprogramming with lambdas for reusable code structures in music production.
  • Conclusions and Q&A:

    • The presentation concludes with an encouragement for creativity in programming, emphasizing the balance between technical skill and artistic expression.
    • Bowkett invites the audience to ask questions, indicating a willingness to clarify or expand on topics discussed during the session.

Overall, the presentation illustrates how programming concepts like lambdas, algorithms, and probability can converge to facilitate creative processes, particularly in musical contexts, while encouraging a playful approach to coding and creativity.

Archaeopteryx: Lambdas in Detail
Giles Bowkett • February 11, 2015 • Earth

Help us caption & translate this video!

http://amara.org/v/GGpM/

MountainWest RubyConf 2010

00:00:15.500 Oh, oh.
00:00:24.439 Okay, I have to get set up here. Hold on. I actually got here at 7:30, but we were too early, so we went to get food, and it took a while to find some vegan food. Yes, we're looking for vegan food.
00:00:46.040 Actually, we knew of an awesome place, but they were not open for breakfast. I win! So, the first thing I want to say is that normally I don't think introductions are a good idea. The most important thing is to get to the point and introduce yourself later.
00:01:11.640 However, there are a few things I do want to share to introduce myself. If you don't know why I'm wearing this hat, it's because I was out there. I don't know how many of you were here in 2008, but it's an homage to that.
00:01:32.159 The other thing is that I am not working with Ruby professionally. In fact, I have been doing so for several years, but currently, I work on making videos and doing career coaching. It's a kind of weird experiment, but I really like it.
00:01:49.320 Hopefully, it's going to enable me to write only the code I’m interested in and none of the code that bores me. I don't mean to suggest that any of my employer's code has bored me in the past.
00:02:01.079 I think you would be able to figure out that it has happened once or twice. This kind of gives an idea of what it feels like sometimes, like when they say you're a rock star developer or our ninja, responding to the bat signal—sometimes you'd rather just play a video game.
00:02:16.200 As I mentioned, this is a slide, and this website mentions no slides at all. You may come to the conclusion that I am a liar, and here’s a picture of me two years ago saying exactly the same thing. I promised slides and delivered something different.
00:02:28.020 I thought Archeopteryx was going to have a different feature set than it ended up having, so please bear with me. If you were expecting or demanding no slides, I assure you I'm going to make it quick, and there will be a lot of Q&A.
00:02:53.580 I want to have a discussion, so I'm going to be talking about Archeopteryx. Here I am attempting to give a presentation about Archeopteryx with no slides, which is why I decided to go with slides.
00:03:14.700 The other thing to know is that there's going to be some math. Math can sometimes get boring with symbols and whatnot, but there will also be animals, including this scary little turtle.
00:03:38.640 If you want to ask questions, please do so. I'm trying to make this a Q&A session, and I want to get through the slides quickly. The best way to ask a question is to go on Twitter.
00:04:02.159 If you see your friends asking a good question or someone else asks a good question, retweet it. If I see 300 retweets of the same question on Twitter, I'll know that's the one to address. Of course, you can also ask questions the old-fashioned way by raising your voice.
00:04:21.299 So, I don't know how many of you know what Archeopteryx is, but it is essentially a Ruby library for creating music. One of the major technologies that enables it is MIDI.
00:04:34.620 All you really need to know about MIDI is that it's like JSON or HTTP; it's an unbelievably simple protocol. It's basically a command for turning notes on and off.
00:05:00.000 If you've got a synthesizer, you can send it MIDI commands saying to play this note or that note. For example, if you have a soft synth or drum machine on your computer, you can send it a command saying to play this drum or that drum.
00:05:25.380 To work with MIDI in Ruby, you need a pair of gems: `gem install midi_lib` and `gem install mediator`. The MIDI lib was created around 2003; it's really old school and allows you to work with MIDI files.
00:05:46.220 Mediator was essentially created because I went around promoting Archeopteryx at these conferences, and someone looked at the code and said he wanted to make it better. Now it runs on this, which is mainly used for live MIDI.
00:06:10.480 To get Archeopteryx, you can check out the URL on GitHub, or you can just Google 'Giles MIDI', which I would recommend as the simpler option.
00:06:38.639 One of the things I want to discuss, and I’m going to make this quick, is Lambda. Lambda is a feature of Ruby that many people may not use as much, but it is incredibly powerful.
00:07:04.900 Here’s an example in JavaScript. If you go to the JavaScript console in Webkit and create a new Object, you can add a function to the object as an attribute, just like any other piece of data. You can reference it easily.
00:07:31.740 You can do something similar in Ruby by creating an object and then adding accessor methods. Here’s how you set it up: you create a Foo object and add an accessor 'bar'. You can set 'foo.bar' equal to a lambda.
00:07:57.240 This means that when you call 'foo.bar', you receive a proc, which is a function object. You can execute it by using 'foo.out.bar' or with square brackets, achieving similar behavior as JavaScript.
00:08:18.840 This is a different way of writing Ruby from how it is typically done, but the gist is that if you want to do this JavaScript-like function in Ruby, it is quite easy.
00:08:39.300 Next, I want to explain something that may seem like a tangent: how Google PageRank works. Here is the original white paper on Google PageRank.
00:09:00.780 The algorithm states that the PageRank of a given page is equal to a dampening factor applied to the PageRank of the pages linking to it divided by the number of outbound links. You iterate over the collection while applying the same equation.
00:09:27.940 It may sound complicated, but it can be simplified considerably. The formula has a series of terms, and it boils down to a few lines in Python.
00:09:53.250 The power lies in the probability matrix, which sets up probabilities for encountering various items. Here’s an example of a simple probability matrix indicating the likelihood of observing different animals in a context.
00:10:08.880 For instance, we could state that the probability of encountering an aardvark is 80% and a bird is 50%. This is simply associating items with probabilities.
00:10:30.540 Take, for example, a blog post with an error message. If you encounter a deeply annoying error message, all you need to do is Google it, and often you'll find a simple, one-liner solution.
00:10:50.520 If these terms were to link to my blog, that is what Google does: it assesses the probabilities that they will link, and because of a high probability, you would find my blog during a search.
00:11:10.780 In this way, when someone searches for a term like 'config.gem unpack' they'll find my blog post, as it has terms with high probabilities.
00:11:22.200 Going back to the PageRank implementation, the mistake lies in how the variable is named. When we call it 'pages', what we really mean are the referring pages or sources of inbound links.
00:11:42.060 A better way to express this concept is to clarify that we are dealing with inbound links.
00:12:02.220 Let’s look at the equation again, where the PageRank of the page is defined based on the links pointing to it, which gives us the basics of our probability matrix.
00:12:18.780 I included diagrams earlier which I know you got, so here’s how it translates to code. The basic equation looks at the PageRank of the inbound links compared to the number of links on the pages.
00:12:43.140 When it comes to distributions, I have some slides that are rather boring, so I’m going to skip those; however, it would be interesting if you were shocked by the idea that Google is imperfect.
00:13:06.240 If that's the case, I include a picture of a hippo to ease that pain, but it’s going to get worse. We’re transitioning from math to Python; brace yourselves; it might hurt.
00:13:19.080 I did this great presentation where I was promoting Archeopteryx, and while I excited folks, they asked how it works. So now I’ll share the code, but it may not be what they want.
00:14:00.840 The Google PageRank algorithm may have 126 lines of Python code. It sounds great; here's a small sample of how one could write a spelling corrector in just 21 lines.
00:14:21.300 This is from Peter Norvig, Chief Scientist at Google. He spoke about how he could create a solution for spelling error correction in less than a page.
00:14:40.920 Here’s a breakdown of the 21 lines he used, which compiled word frequencies—this is crucial in naturally determining what the correct spelling should be.
00:14:59.880 If you can compile frequencies in 21 lines, then compare this to simple implementations of PageRank in Ruby which could be done in just 5 lines.
00:15:14.280 Many people view Google as complex; however, its functionality can rely on surprisingly simple principles like probability and frequency matrices.
00:15:35.760 This analogy compares Google to a Post-it note; to understand their operations, you merely need to grasp probability fundamentals.
00:15:50.160 There’s something sick and wrong about the Python community regarding the lack of humor. It’s unreasonable to discuss Python day after day without jokes.
00:16:14.520 If you attend a Python meetup, the conversations are quite staid. If you were to ask someone about their code, it wouldn't spark any light-hearted banter.
00:16:27.720 In the context of programming, I can well imagine meeting the person who adapted Python for old Wang computers, but I doubt they'd make a humorous quip.
00:16:42.120 Here's some Python code I worked on in 2005; admittedly, it doesn't run now, but back then it learned to play Rock Paper Scissors.
00:17:01.200 Training a computer for Rock Paper Scissors might seem futile, but it illustrated probability matrices well enough. If you play the same move, it'll recognize a pattern.
00:17:22.020 The focus here is on tracking frequencies—this can lead up to deeper machine learning models in games as complex as chess.
00:17:39.600 The core concept of the program shows how slight changes in probabilistic outcomes affect results. A frequency matrix embodies that principle.
00:18:01.920 Here’s how the program triggers moves based on frequency, where inference and predictions emerge from Bayes’ theorem. This has been a lot of math, so here’s a cute hippo.
00:18:23.520 After delving into Bayes' theorem, I emphasize that Wikipedia can give a general introduction but isn't a definitive source. For substantial insights, dense texts like Judea Pearl's work are key.
00:18:42.780 The probability matrices yield intriguing predictions, but the complex mathematics can be dense, although these outputs help illustrate such concepts.
00:19:03.000 An example discussed revolves around detecting past rain based on current wetness—if a computer deduces rain from wet ground, that’s impressive.
00:19:21.720 The mathematical underpinning simplifies into code effectively when you consider conditional probabilities.
00:19:41.520 Considering the parameters of this data can be computation-heavy without the right approach, which is why efficient coding helps establish relations.
00:20:06.899 Next, let’s shift our attention to drum machines. Earlier, I mentioned I would demonstrate one, and here's how we can create a basic rhythm with it.
00:20:24.180 Here’s a software program called Reason that allows users to create and manipulate drum rhythms easily. It offers synths, drum machines, and samplers.
00:20:49.300 After setting up the utility, you can define samples and beats in various configurations to generate rhythms.
00:21:06.420 By manipulating drum samples, you can set base rhythms. This rhythm structure resembles the classic Roland TR-808, loved for its nostalgic value.
00:21:24.840 The process is based on organizing beats along a grid, which shows the rhythmic patterns—this flexibility can be expressed as a matrix.
00:21:47.280 With programming skills, you identify patterns among the generated beats—using floats to define probabilities elevates the musical creation process.
00:22:05.520 This probability matrix determines which drum hits to use. Modulating these parameters in creative ways can lead to variations of drum patterns.
00:22:23.080 The elegance of the coding means that if you input the right values consistently, you can control what sound outputs. This can lead to deep exploration within electronic music.
00:22:46.760 As a demonstration, I’ll show how Archeopteryx functions by checking out how it generates drum sequences, adjusting parameters on the fly.
00:23:09.180 The utility allows me to manipulate these values and listen to the immediate impact on the drumming. It allows for dynamic sessions using Ruby scripts.
00:23:39.480 While adjusting the drums, I'd like to showcase how I utilize random values in conjunction with lambda functions to increase diversity in the rhythms.
00:23:58.020 You can tweak these parameters, listening for changes, allowing for instantaneous feedback, and if values shift too dramatically, you can quickly revert.
00:24:20.520 To highlight what makes this technique unique, I often find excitement in seeing how these random values shift melodic patterns and keep the creation lively.
00:24:39.960 As you adjust the quantification of beats in the percussion, how low or high parameters become can significantly change the piece being generated.
00:25:05.580 In this case, Archeopteryx's clever use of lambdas aids in the algorithmic process of adjusting rhythms dynamically, inviting exploration into programmatic music.
00:25:30.900 The flexibility is vital; metaprogramming techniques are a strength when building reusable components.
00:25:49.260 Establishing strategies, I can encode behavior that depends significantly on input data, further enhancing the music structure.
00:26:11.220 This functional programming concept means I can encapsulate logic and pass it around, similar to how strategies can be executed in Java.
00:26:36.120 As I wrap up this discussion, I'm open to questions. If there’s anything unclear or any detail you wish to explore, please feel free to inquire.
00:27:02.220 You can change the probabilities in the definitions, adjusting how the program plays and interacts with rhythms. These choices lead to varied outputs.
00:27:23.580 If you raise or lower numbers in the setup, it can completely alter results, generating different experiences when you produce sequences.
00:27:50.460 In practical settings, I've found it advantageous to keep adaptability in my rhythm generation approach while also integrating existing sample libraries.
00:28:16.320 Music production can revolve around borrowing or reinterpretation of prior works, smoothing how those elements work into something new.
00:28:42.860 Specific references to innovative methods can evolve tremendously, resulting in unique compositions that integrate classic musical aspects.
00:29:10.380 As I conclude, there's a noteworthy balance between creativity and programming, where unique outputs can surface from simple code structures.
00:29:30.660 This flexibility greatly enhances the music creation process, paving the way for innovative developments using archeopteryx.
00:29:49.680 I am grateful for your patience during this presentation. Thank you for your time, interest, and encouragement as we explore these creative frontiers together!
Explore all talks recorded at MountainWest RubyConf 2010
+22