The Art of Randomness

Book description

The Art of Randomness is a hands-on guide to mastering the many ways you can use randomized algorithms to solve real programming and scientific problems. You’ll learn how to use randomness to run simulations, hide information, design experiments, and even create art and music. All you need is some Python, basic high school math, and a roll of the dice.

Author Ronald T. Kneusel focuses on helping you build your intuition so that you’ll know when and how to use random processes to get things done. You’ll develop a randomness engine (a Python class that supplies random values from your chosen source), then explore how to leverage randomness to:

  • Simulate Darwinian evolution and optimize with swarm-based search algorithms
  • Design scientific experiments to produce more meaningful results by making them truly random
  • Implement machine learning algorithms like neural networks and random forests
  • Use Markov Chain Monte Carlo methods to sample from complex distributions
  • Hide information in audio files and images, generate art, and create music
  • Reconstruct original signals and images from only randomly sampled data

Scientific anecdotes and code examples throughout illustrate how randomness plays into areas like optimization, machine learning, and audio signals. End-of-chapter exercises encourage further exploration.

Whether you’re a programmer, scientist, engineer, mathematician, or artist, you’ll find The Art of Randomness to be your ticket to discovering the hidden power of applied randomness and the ways it can transform your approach to solving problems, from the technical to the artistic.

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. About the Author
  6. About the Technical Reviewer
  7. BRIEF CONTENTS
  8. CONTENTS IN DETAIL
  9. FOREWORD
  10. ACKNOWLEDGMENTS
  11. INTRODUCTION
    1. Who Is This Book For?
    2. What Can You Expect to Learn?
    3. What I Expect You to Know
    4. How to Use This Book
  12. 1 THE NATURE OF RANDOMNESS
    1. Probability and Randomness
      1. Discrete Distributions
      2. Continuous Distributions
    2. Testing for Randomness
    3. Truly Random Processes
      1. Flipping Coins
      2. Rolling Dice
      3. Using Voltage
    4. Random Physical Processes
      1. Atmospheric Radio Frequency Noise
      2. Voyager Plasma and Charged Particle Data
      3. Radioactive Decay
    5. Deterministic Processes
      1. Pseudorandom Numbers
      2. Quasirandom Sequences
      3. Combining Deterministic and Truly Random Processes
    6. The Book’s Randomness Engine
      1. The RE Class
      2. RE Class Examples
    7. Summary
  13. 2 HIDING INFORMATION
    1. In Strings
      1. Fixed Offset
      2. Random Offset
    2. In Random Data
      1. How Much Can You Hide?
      2. The steg_random.py Code
    3. In an Audio File
      1. A Quiet Live Performance
      2. The steg_audio.py Code
    4. In an Image File
      1. Defining Image Formats
      2. Using NumPy and PIL
      3. Hiding Bits in Pixels
      4. Hiding One Image in Another
      5. The steg_image.py Code
    5. Exercises
    6. Summary
  14. 3 SIMULATE THE REAL WORLD
    1. Introduction to Models
    2. Estimate Pi
      1. Using a Dartboard
      2. Simulating Random Darts
      3. Understanding the RE Class Output
      4. Implementing the Darts Model
    3. Birthday Paradox
      1. Simulating 100,000 Parties
      2. Testing the Birthday Model
      3. Implementing the Birthday Model
    4. Simulating Evolution
      1. Natural Selection
      2. Static World
      3. Gradually Changing World
      4. Catastrophic World
      5. Genetic Drift
      6. Testing the Simulations
    5. Exercises
    6. Summary
  15. 4 OPTIMIZE THE WORLD
    1. Optimization with Randomness
    2. Fitting with Swarms
      1. Curves
      2. The curves.py Code
      3. The Optimization Algorithms
    3. Fitting Data
      1. Introducing Stacks and Postfix Notation
      2. Mapping Code to Points
      3. Creating gp.py
      4. Evolving Fit Functions
    4. Exercises
    5. Summary
  16. 5 SWARM OPTIMIZATION
    1. Packing Circles in a Square
      1. The Swarm Search
      2. The Code
    2. Placing Cell Towers
      1. The Swarm Search
      2. The Code
    3. Enhancing Images
      1. The Enhancement Function
      2. The Code
    4. Arranging a Grocery Store
      1. The Environment
      2. The Shoppers
      3. The Objective Function
      4. The Shopping Simulation
    5. Exercises
    6. Summary
  17. 6 MACHINE LEARNING
    1. Datasets
      1. Histology Slide Data
      2. Handwritten Digits
    2. Neural Networks
      1. Anatomy Analysis
      2. Randomness
      3. Initialization
    3. Extreme Learning Machines
      1. Implementation
      2. Testing
      3. Reckless Swarm Optimizations
    4. Random Forests
      1. Decision Trees
      2. Additional Randomness
      3. Models Combined with Voting
    5. Exercises
    6. Summary
  18. 7 ART
    1. Creating Random Art
      1. Moiré Patterns
      2. Random Walks
      3. A Grid
    2. Fun with Fractals
      1. The Chaos Game
      2. Iterated Function Systems
      3. Fractals Plotted with Points
      4. IFS Maps
    3. Exercises
    4. Summary
  19. 8 MUSIC
    1. Creating Random Sounds
      1. Sine Waves
      2. C Major Scale
    2. Generating Melodies
      1. Swarm Search
      2. The melody_maker.py code
      3. Implementation
    3. Exercises
    4. Summary
  20. 9 AUDIO SIGNALS
    1. Compressed Sensing
    2. Signal Generation
    3. Unraveled Images
    4. Compressed Sensing Applications
    5. Exercises
    6. Summary
  21. 10 EXPERIMENTAL DESIGN
    1. Randomization in Experiments
      1. Simple
      2. Block
      3. Stratified
    2. Defining the Simulation
    3. Implementing the Simulation
      1. Functions and Classes
      2. Schemes
    4. Exploring the Simulation
      1. Simple
      2. Block
      3. Stratified
    5. Exercises
    6. Summary
  22. 11 COMPUTER SCIENCE ALGORITHMS
    1. Las Vegas and Monte Carlo
      1. Permutation Sort
      2. Matrix Multiplication
    2. Counting Animals
    3. Testing Primality
      1. Modular Arithmetic
      2. The Miller-Rabin Test
      3. Non-witness Numbers
      4. Miller-Rabin Performance
    4. Working with Quicksort
      1. Running Quicksort in Python
      2. Experimenting with Quicksort
    5. Exercises
    6. Summary
  23. 12 SAMPLING
    1. Introduction to Sampling
      1. Terminology
      2. Bayesian Inference
    2. Discrete Distributions
      1. Sequential Search
      2. Fast-Loaded Dice Roller
      3. Runtime Performance
      4. Two Dimensions
      5. Images
    3. Continuous Distributions
      1. Inverse Transform
      2. Rejection
      3. Markov Chain Monte Carlo
    4. Exercises
    5. Summary
  24. RESOURCES
    1. Random Processes
    2. Steganography
    3. Simulation and Modeling
    4. Metaheuristics: Swarm Intelligence and Evolutionary Algorithms
    5. Machine Learning
    6. Generative Art and Music
    7. Compressed Sensing
    8. Experimental Design
    9. Randomized Algorithms
    10. Sampling
    11. Videos
  25. INDEX

Product information

  • Title: The Art of Randomness
  • Author(s): Ronald T. Kneusel
  • Release date: December 2023
  • Publisher(s): No Starch Press
  • ISBN: 9781718503243