The Art of Randomness Randomized Algorithms in the Real World (Ronald T. Kneusel) (Z-Library)
data
No Description
251
Views
0
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
(This page has no text content)
Page
3
(This page has no text content)
Page
4
THE ART OF RANDOMNESS Randomized Algorithms in the Real World by Ronald T. Kneusel San Francisco
Page
5
THE ART OF RANDOMNESS. Copyright © 2024 by Ronald T. Kneusel. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. First printing 28 27 26 25 24 1 2 3 4 5 ISBN-13: 978-1-7185-0324-3 (print) ISBN-13: 978-1-7185-0325-0 (ebook) Published by No Starch Press , Inc. 245 8th Street, San Francisco, CA 94103 phone: +1.415.863.9900 www.nostarch.com; info@nostarch.com Publisher: William Pollock Managing Editor: Jill Franklin Production Manager: Sabrina Plomitallo-González Production Editor: Sydney Cromwell Developmental Editors: Alex Freed and Eva Morrow ®
Page
6
Cover Illustrator: Gina Redman Interior Design: Octopod Studios Technical Reviewer: Doug Couwenhoven Copyeditor: George Hale Proofreader: Audrey Doyle Library of Congress Cataloging-in-Publication Data Name: Kneusel, Ronald T., author. Title: The art of randomness : using randomized algorithms in the real world / Ron Kneusel. Includes bibliographical references and index. Identifiers: LCCN 2023029979 (print) | LCCN 2023029980 (ebook) | ISBN 9781718503243 (paperback) | ISBN 9781718503250 (ebook) Subjects: LCSH: Algorithms. | Numbers, Random. | Python (Computer program language) Classification: LCC QA9.58 .K635 2024 (print) | LCC QA9.58 (ebook) | DDC 519.2/3- -dc23/eng/20231018 LC record available at https://lccn.loc.gov/2023029979 LC ebook record available at https://lccn.loc.gov/2023029980 For customer service inquiries, please contact info@nostarch.com. For information on distribution, bulk sales, corporate sales, or translations: sales@nostarch.com. For
Page
7
permission to translate this work: rights@nostarch.com. To report counterfeit copies or piracy: counterfeit@nostarch.com. No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
Page
8
In memory of George Marsaglia (1924–2011), PRNG designer extraordinaire u32 x32(){static u32 _=9;_^=_<<13;_^=_>>17;_^=_<<5;return _;}
Page
9
About the Author Ronald T. Kneusel has been working with machine learning in industry since 2003 and completed a PhD in machine learning at the University of Colorado, Boulder, in 2016. Ron has six other books: How AI Works: From Sorcery to Science (No Starch Press, 2023), Strange Code: Esoteric Languages That Make Programming Fun Again (No Starch Press, 2022), Practical Deep Learning: A Python-Based Introduction (No Starch Press, 2021), Math for Deep Learning: What You Need to Know to Understand Neural Networks (No Starch Press, 2021), Numbers and Computers (Springer, 2017), and Random Numbers and Computers (Springer, 2018).
Page
10
About the Technical Reviewer Doug Couwenhoven is a research scientist with more than 30 years of experience developing algorithms for digital imaging applications. He has a BS in physics and an MS in electrical engineering and signal processing. He spent the first 24 years of his career working at a large imaging company developing software algorithms for digital photography, printing, and imaging systems, and holds 50 US patents in the field. In 2013, he joined an aerospace technology company, and is currently part of a research group there that focuses on developing deep learning and machine learning algorithms for remotely sensed data.
Page
11
BRIEF CONTENTS Foreword Acknowledgments Introduction Chapter 1: The Nature of Randomness Chapter 2: Hiding Information Chapter 3: Simulate the Real World Chapter 4: Optimize the World Chapter 5: Swarm Optimization Chapter 6: Machine Learning Chapter 7: Art Chapter 8: Music Chapter 9: Audio Signals Chapter 10: Experimental Design
Page
12
Chapter 11: Computer Science Algorithms Chapter 12: Sampling Resources Index
Page
13
CONTENTS IN DETAIL FOREWORD ACKNOWLEDGMENTS INTRODUCTION 1 THE NATURE OF RANDOMNESS Probability and Randomness Discrete Distributions Continuous Distributions Testing for Randomness Truly Random Processes Flipping Coins Rolling Dice Using Voltage Random Physical Processes
Page
14
Atmospheric Radio Frequency Noise Voyager Plasma and Charged Particle Data Radioactive Decay Deterministic Processes Pseudorandom Numbers Quasirandom Sequences Combining Deterministic and Truly Random Processes The Book’s Randomness Engine The RE Class RE Class Examples Summary 2 HIDING INFORMATION In Strings Fixed Offset
Page
15
Random Offset In Random Data How Much Can You Hide? The steg_random.py Code In an Audio File A Quiet Live Performance The steg_audio.py Code In an Image File Defining Image Formats Using NumPy and PIL Hiding Bits in Pixels Hiding One Image in Another The steg_image.py Code Exercises Summary
Page
16
3 SIMULATE THE REAL WORLD Introduction to Models Estimate Pi Using a Dartboard Simulating Random Darts Understanding the RE Class Output Implementing the Darts Model Birthday Paradox Simulating 100,000 Parties Testing the Birthday Model Implementing the Birthday Model Simulating Evolution Natural Selection Static World
Page
17
Gradually Changing World Catastrophic World Genetic Drift Testing the Simulations Exercises Summary 4 OPTIMIZE THE WORLD Optimization with Randomness Fitting with Swarms Curves The curves.py Code The Optimization Algorithms Fitting Data Introducing Stacks and Postfix Notation
Page
18
Mapping Code to Points Creating gp.py Evolving Fit Functions Exercises Summary 5 SWARM OPTIMIZATION Packing Circles in a Square The Swarm Search The Code Placing Cell Towers The Swarm Search The Code Enhancing Images The Enhancement Function
Page
19
The Code Arranging a Grocery Store The Environment The Shoppers The Objective Function The Shopping Simulation Exercises Summary 6 MACHINE LEARNING Datasets Histology Slide Data Handwritten Digits Neural Networks Anatomy Analysis
Page
20
Randomness Initialization Extreme Learning Machines Implementation Testing Reckless Swarm Optimizations Random Forests Decision Trees Additional Randomness Models Combined with Voting Exercises Summary 7 ART Creating Random Art
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# The Art of Randomness: Randomized Algorithms in the Real World
## 【One-Line Pitch】
A hands-on, code-first exploration of how randomness powers everything from Monte Carlo simulations and steganography to evolutionary algorithms and neural networks—perfect for Python programmers who want to understand and harness randomness in practical applications.
## 【Book Arc】
- **Opening (~0%–8%)**: Introduces probability fundamentals—uniform and normal distributions, notation like [0,1), and the crucial insight that humans are terrible at generating randomness. Includes von Neumann's clever de-biasing algorithm and early experiments with randomness sources.
- **Early (~8%–20%)**: Dives into practical randomness generation with the RE (Randomness Engine) class supporting multiple generators (PCG64, MT19937, minstd, quasirandom Halton sequences, /dev/urandom). Demonstrates steganography—hiding data in images, audio files, and text using random pool selection.
- **Early-Middle (~20%–32%)**: Moves into simulation with Monte Carlo methods (estimating π via dartboards), the birthday paradox, and evolutionary simulation. Introduces genetic algorithms, differential evolution, and random optimization as nature-inspired search techniques.
- **Middle (~32%–44%)**: Covers swarm intelligence algorithms—canonical PSO, bare-bones PSO, GWO, Jaya—applied to curve fitting and function approximation. Introduces genetic programming with stack-based expression evaluation for evolving mathematical functions.
- **Middle-Late (~44%–52%)**: Applies optimization to real-world problems: image enhancement (finding optimal parameters for contrast adjustment), market basket analysis (simulating shopper behavior), and the critical role of randomness in machine learning dataset construction.
- **Late (~52%–end)**: Explores randomness in neural networks—weight initialization schemes, activation functions, and how random data augmentation improves model accuracy. Uses statistical tests (t-tests, Mann-Whitney U) to validate that observed improvements are real.
## 【Key Takeaways】
- **Humans cannot generate randomness** (Early): Studies show people bias coin flips unconsciously. Von Neumann's algorithm—flip twice, discard same results, keep first of different pairs—de-biases any biased source. This matters for any application requiring genuine randomness.
- **Multiple random number generators exist for different needs** (Early): The RE class wraps PCG64, MT19937, minstd, quasirandom Halton sequences, and system entropy sources. Quasirandom sequences fill space more uniformly than pseudorandom ones—critical for Monte Carlo integration where they dramatically improve π estimation accuracy.
- **Steganography leverages randomness for security** (Early): By selecting random "pool" words or pixel positions to hide data, you create output that passes entropy tests (chi-squared, correlation). Hidden images in WAV files and PNGs remain undetectable to statistical analysis.
- **Evolutionary algorithms balance exploration and exploitation** (Early-Middle): Genetic algorithms with fitness bias, crossover, and mutation can evolve solutions in static and changing environments. The fitness bias parameter controls selection pressure—higher values speed convergence but risk premature optimization.
- **Swarm intelligence offers multiple optimization strategies** (Middle): Particle swarm optimization (PSO) variants, differential evolution, and random optimization each have trade-offs. DE converges quickly but may hit local minima; RO particles search independently without communication, making it simpler but potentially slower.
- **Genetic programming evolves symbolic expressions** (Middle): Using stack-based postfix notation, the system evolves mathematical functions by combining operations (+,-,×,÷,mod) and constants. It successfully recovers underlying functions from noisy data—fitting lines, quadratics, and normal curves.
- **Randomness is essential for machine learning datasets** (Middle-Late): Random augmentation (zooming, shifting, rotating) improved MNIST digit classification accuracy from 87.3% to 90.3%—a statistically significant gain verified by t-tests and Mann-Whitney U tests. Dataset construction is as important as model architecture.
- **Statistical validation separates signal from noise** (Late): When comparing random initialization schemes or augmentation strategies, p-values from proper statistical tests tell you whether observed differences are real or chance. This rigor distinguishes genuine improvements from random variation.
## 【Reading Tips】
- **Skim the math notation sections** (~0%–4%) if you're comfortable with probability basics; the bracket notation ([0,1) vs (0,1)) is worth internalizing but the concepts are intuitive.
- **Deep-read the RE class implementation** (~8%–12%): Understanding how different generators are selected and seeded will help you choose the right tool for later chapters. The code is dense but foundational.
- **Run the steganography examples** (~12%–20%): These are the most immediately rewarding—hiding images in WAV files and verifying with entropy analysis. The command-line examples are copy-paste ready.
- **Pay attention to the optimization comparisons** (~32%–48%): Tables comparing F-scores across algorithms (GWO, PSO, DE, GA, Jaya, RO) reveal which methods work best for which problems. This is where the practical wisdom lives.
- **Don't skip the statistical tests section** (~52%–end): Understanding why p-values matter for comparing random initialization schemes will make you a more rigorous practitioner. The code patterns are reusable for your own experiments.
## 【Coverage Limits】
This guide covers the book's progression through randomness fundamentals, simulation, optimization, and machine learning applications. The excerpts do not cover the final chapters' advanced neural network architectures or any concluding synthesis; those sections may exist but are not represented in the source material.
##
Passage locations
Excerpt 1
uniform distribution is straightforward, whether continuous or discrete: each possible outcome is equally likely to appear. same side up each time. It’s conc...
View in text
Excerpt 2
lines load NumPy and PIL’s Image class. We only need Image. The next two lines load the file apples.png into im, an instance of the Image class. To make the...
View in text
Excerpt 3
eter values to tailor the function to the data. In the next section, we’ll start with the data and let the swarms tell us what the best-fit function and para...
View in text
Excerpt 4
milk (14.5%) ($1.00) milk rank = 23 candy rank = 3 Upper half median probability of being selected = median product value = Lower half median probability of...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay