Barrios AI

Artificial Intelligence for Musicians

  1. Introduction
  2. Emergent Harmonic Structures | Software 1.0
  3. Pythagoras and the Music of the Spheres
  4. Building the Modes from Ancient Theory
  5. Harmonic Ratios in Nature and Music
  6. Musical Mathematics
  7. Exploring Chance and Randomness
  8. Statistics of Sound
  9. Software 2.0 | Deep Learning: Teaching Computers to See
  10. Software 2.0 | Deep Learning: Teaching Computers to Hear
  11. Software 3.0 | Generative AI: Teaching Computers to Read & Write
  12. Software 3.0 | NotebookLM as RAG

Chapter 5: Musical Mathematics

Free Preview

5.1 Probability and Statistics in Music

Notes follow probabilities: tonic notes recur, chromatic tones appear less. Probability and statistics let us tally those choices, whether in a Bach chorale or a Coltrane solo. In Python we’ll call on random, NumPy, and Matplotlib to test musical data.

5.2 Generating Musical Sequences with Weighted Chance

Probability isn’t just analysis. It drives creativity. Assign a weight to each note, then let randomness pick pitches in proportion to those weights.

import random

notes   = ['C', 'D', 'E', 'F', 'G', 'A', 'B']
weights = [0.1, 0.15, 0.2, 0.15, 0.2, 0.1, 0.1]  # likelihood for each note

random_sequence = random.choices(notes, weights, k=10)
random_sequence

Vary the weights to tilt your melody toward major, minor, or modal flavors.

Continue reading this chapter

You're reading a free preview. Purchase the book to unlock every chapter in Artificial Intelligence for Musicians.

✓ Full book unlocked✓ Every chapter✓ Runnable code✓ Lifetime access