liveBook · Manning

Sampling

Also called sample method

Sampling is a procedure for selecting items from a collection or generating outcomes from a probability distribution according to a specified rule.

How 31 Manning books explain it

Troubleshooting Java: Read, debug, and optimize JVM applications

Sampling is a profiling technique that observes selected parts of a program’s execution to reveal its behavior.

How it is used
Uses sampling as a first investigation step to locate executing code and identify possible latency, lock, or memory issues.
How deep it goes
Walks through sampling and interpreting results, while reserving invocation counts and lock details for instrumentation.
Examples
Investigates a delayed HTTP endpoint and an endpoint that creates many memory-consuming objects.
What you can do after
Diagnose execution and memory issues with VisualVM sampling and select areas for deeper profiling.

Read how Troubleshooting Java: Read, debug, and optimize JVM applications explains sampling →

Optimization Algorithms: AI techniques for design, planning, and control problems

A sampling method that generates candidate points using random draws from a specified space or distribution.

How it is used
Uses sampling to initialize populations and select parents or survivors in population-based optimization.
How deep it goes
Compares sampling patterns and selection pressure, with Python implementations for generating points and selecting parents.
Examples
Illustrates two-dimensional initial populations and random parent selection in a ticket-pricing optimization problem.
What you can do after
Apply it via pymoo to generate random or Latin hypercube initial populations and compare their dispersion.

Read how Optimization Algorithms: AI techniques for design, planning, and control problems explains sampling →

Advanced Algorithms and Data Structures

A random sampling algorithm generates candidate solutions through random choices and selects among the sampled results without iterative optimization after initialization.

How it is used
Finds a low-crossing valid graph embedding by selecting the best of independently generated drawings.
How deep it goes
Works through candidate generation, validation, crossing counts, and best-result tracking; leaves geometry-specific intersection tests abstract.
Examples
Uses random vertex positions in a rectangle and edge-intersection counts, with pseudocode for validation and scoring.
What you can do after
Build it from scratch for graph embeddings by rejecting invalid candidates and retaining the valid drawing with the fewest crossings.

Read how Advanced Algorithms and Data Structures explains sampling →

Deep Learning with Python, Third Edition

The process of drawing values or examples from a probability distribution, here to generate new content from a learned space.

How it is used
Generates text through token choices and images through points in a learned latent space.
How deep it goes
Implements categorical and top-K token sampling and a VAE sampling layer, with practical comparisons of temperature settings.
Examples
Compares continuations of an advice prompt and decodes points from a two-dimensional MNIST digit space.
What you can do after
Apply it via Keras to select text tokens or sample latent points for a digit-generating VAE.

Read how Deep Learning with Python, Third Edition explains sampling →

Grokking Statistics

Sampling is the process of selecting observations from a population to form a sample for analysis or experimentation.

How it is used
Supports experiments, data mining, and decisions by relating observed data to a larger population.
How deep it goes
Explains population definition, random selection, sample size, context, and bias without deriving statistical sampling formulas.
Examples
Uses a six-person dorm sleep study, self-driving taxi records, airport metrics, filament factories, and wearable-device selection.
What you can do after
Apply it to define a population, select a sample, question representativeness, and disclose bias and context.

Read how Grokking Statistics explains sampling →

Learn Generative AI with PyTorch

A prediction strategy that samples next tokens according to predicted probabilities instead of always taking the maximum.

How it is used
Uses sampling to extend text and music prompts one predicted token or event at a time.
How deep it goes
Works through sampling loops, context limits, probability adjustment, and stopping conditions in LSTM and Transformer implementations.
Examples
Compares repeated text completions under different settings and generates a MIDI continuation from 250 musical events.
What you can do after
Build it from scratch using probability-weighted draws and adjustable temperature and top-K settings.

Read how Learn Generative AI with PyTorch explains sampling →

Natural Language Processing in Action, Second Edition

Sampling is a decoding method that selects the next token probabilistically from a distribution over candidate tokens.

How it is used
Applies probabilistic decoding to make autoregressive language generation less predictable and more varied.
How deep it goes
Explains conditional token probabilities, ranking, temperature, and nucleus-sampling configuration, while simplifying the full branching process.
Examples
Uses GPT-2 inference, ranked next-token probabilities, a fishbone decision tree, and nucleus sampling for the prompt “NLP is a”.
What you can do after
Apply it via Hugging Face Transformers by enabling sampling and configuring top_p during GPT-2 text generation.

Read how Natural Language Processing in Action, Second Edition explains sampling →

AI Model Evaluation

The process of selecting a subset of observations or traffic from a larger population for analysis or processing.

How it is used
Uses sampling to select evaluation examples and limit shadow traffic according to evaluation goals.
How deep it goes
Explains selection options, documentation, operational trade-offs, and repeated-run stability checks without prescribing a universal sample size.
Examples
Uses production-log samples, segment and edge-case selection, shadow requests, and repeated five-point judge scores.
What you can do after
Practice selecting and documenting evaluation samples, controlling shadow traffic, and checking whether judge outputs are stable.

Read how AI Model Evaluation explains sampling →

Tiny Python Projects: Learn coding and testing with puzzles and games

How it is used
Uses random selection to build varied outputs, mutate text, choose workouts, and assemble word-based passwords.
How deep it goes
Explains choice, unique sampling, replacement, seeding, exact index selection, and string reconstruction rather than probability theory.
Examples
Demonstrates insults, character mutation, ransom capitalization, workout selection, and word-based password generation.
What you can do after
Apply it via Python’s random module to select unique items, choose one value, reproduce runs, mutate text, and generate outputs.

Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains sampling →

Cloud Observability in Action

Sampling is the technique of selectively capturing or discarding telemetry records according to a decision policy.

How it is used
Reduces distributed-tracing and logging volume before collection, ingestion, storage, and querying become operationally expensive.
How deep it goes
Compares no, head-based, and tail-based strategies, including decision timing, error coverage, state, latency, and timeout limitations.
Examples
Uses fixed percentages, error-bearing traces, downstream timeouts, production span volumes, and heuristic log-event pruning.
What you can do after
Evaluate sampling strategies against trace relevance, network and storage cost, implementation complexity, and incomplete-request behavior.

Read how Cloud Observability in Action explains sampling →

Agent Design Patterns

Sampling is the process of generating or selecting an output from a stochastic model or operation.

How it is used
Uses repeated candidate outputs to retry failed criteria or reconcile answers in agentic workflows.
How deep it goes
Explains token-level variability and implements a bounded assessment loop, but does not detail the model's sampling algorithm.
Examples
Illustrates sampling with a generic Python resampler and an ordered-triples mathematics problem posed for repeated model runs.
What you can do after
Build it from scratch as a bounded resampler with a worker, assessor, branching function, and failure path.

Read how Agent Design Patterns explains sampling →

Causal AI

A sampling process is a procedure that generates observed outcomes by drawing values from a probability distribution.

How it is used
Uses sampling to generate model outcomes and represent how observed datasets arise from population distributions.
How deep it goes
Defines random draws and IID conditions, then demonstrates library calls and their place in a DGP-to-data hierarchy.
Examples
Shows categorical draws, pgmpy DataFrames, a Pyro plate, and five observations from a simulated window-breaking process.
What you can do after
Apply it via pgmpy or Pyro to generate outcomes and distinguish sampled data from its assumed population distribution.

Read how Causal AI explains sampling →

Inside Deep Learning: Math, Algorithms, Models

The method that draws random values from the distribution object in this section.

How it is used
Generates autoregressive sequences by choosing tokens from predicted probability distributions.
How deep it goes
Explains seed processing, probability-based token selection, temperature adjustment, and a faster hidden-state loop.
Examples
Uses character-level Shakespeare generation from an “EMILIA:” seed and a food-choice analogy for temperature.
What you can do after
Apply sampling in PyTorch with softmax and torch.multinomial, or speed generation with a GRUCell step loop.

Read how Inside Deep Learning: Math, Algorithms, Models explains sampling →

Effective Conversational AI

Sampling is a language-generation decoding strategy that selects output tokens probabilistically from a model's predicted distribution.

How it is used
Generates varied candidates for chatbot intent data, dialogue rewrites, and simulated user replies.
How deep it goes
Contrasts nondeterministic sampling with repeatable greedy decoding and adjusts temperature, without explaining token-selection internals.
Examples
Uses password synonyms, repeated voice-error rewrites, and generated replies to chatbot test scenarios.
What you can do after
Apply it via LLM decoding settings to generate multiple candidates, then select or refine the helpful ones.

Read how Effective Conversational AI explains sampling →

LLM Evaluation and Alignment, The Foundational Ideas

Random sampling selects evaluation cases probabilistically so that each case has a known chance of being selected for review.

How it is used
Routes evaluations to human audits and compares stochastic responses to detect uncertain or hallucinated claims.
How deep it goes
Explains distributions, independent generation, consistency scoring, sample counts, and operational limitations.
Examples
Uses human audit routing, Pantheon responses, sentence consistency checks, and sample-count comparisons.
What you can do after
Apply it via stochastic generation and human-audit routing to estimate reliability or flag potentially hallucinated claims.

Read how LLM Evaluation and Alignment, The Foundational Ideas explains sampling →

Build an Advanced RAG Application (From Scratch)

A sampling technique generates text by probabilistically selecting tokens from a model's predicted distribution rather than always choosing the top-scoring token.

How it is used
Controls LLM text generation by balancing deterministic behavior, coherence, diversity, and creative variation.
How deep it goes
Defines temperature, top-k, and top-p sampling with parameter effects, examples, advantages, and disadvantages, but stops short of implementation code.
Examples
Uses the prompt “The quick brown fox” with k = 3 and p = 0.8 to illustrate candidate restriction and probabilistic continuation.
What you can do after
Apply it via temperature, top-k, and top-p controls to customize generated text for diversity, coherence, and user preferences.

Read how Build an Advanced RAG Application (From Scratch) explains sampling →

Building Quantum Software with Python

Sampling is the process of generating outcomes according to a specified probability distribution.

How it is used
Uses repeated measurement to generate distribution samples, interpret counts, and extract problem-relevant information from quantum states.
How deep it goes
Explains distribution encoding through state amplitudes, repeated measurement, count interpretation, and Python simulation without formal derivations.
Examples
Uses a Galton board, a single-qubit circuit, Python-generated samples, uniform random values, and good-versus-bad marble populations.
What you can do after
Apply it via Python's random.choices to simulate measurements and use repeated counts to approximate outcome probabilities.

Read how Building Quantum Software with Python explains sampling →

Outlier Detection in Python

Sampling is the selection of a subset of observations from a larger dataset for analysis or modeling.

How it is used
Reduces model-training cost and sometimes prediction cost when datasets are too large for practical full-data processing.
How deep it goes
Explains sample-size trade-offs, synthetic-outlier testing, prediction exceptions, and normal-class coverage without prescribing a universal size.
Examples
Uses hundreds or thousands of training records, synthetic outliers, 256-point Isolation Forest samples, and full normal-class coverage.
What you can do after
Apply it via sampling-based outlier detectors while measuring reliability, preserving legitimate variation, and balancing speed against accuracy.

Read how Outlier Detection in Python explains sampling →

Graph Neural Networks in Action

Sampling is the selection of a subset of data elements for computation or analysis.

How it is used
Makes graph neural network training feasible when the full graph exceeds available processing or memory capacity.
How deep it goes
Explains subset selection, PyG implementations, approximation, risks, and sampler choice without detailing sampling algorithms internally.
Examples
Uses PyG NeighborSampler with GCNConv and contrasts sampled subgraphs with full-batch graph convolution.
What you can do after
Apply it via PyTorch Geometric loaders and samplers to train GNNs on graphs that do not fit comfortably in memory.

Read how Graph Neural Networks in Action explains sampling →

Machine Learning Platform Engineering

A sampling strategy is a rule for selecting generated tokens from a model's probability distribution.

How it is used
Controls LLM response variety and determines how production systems handle probabilistic outputs.
How deep it goes
Explains temperature, top-K, and top-P behavior with parameter examples, but stops short of implementation internals.
Examples
Uses temperature values from 0.0 to 1.5, top-K values from 1 to 100, and top-P values from 0.1 to 1.0.
What you can do after
Operate/configure sampling parameters and replace exact-output tests with semantic, factual, and guideline-based evaluation.

Read how Machine Learning Platform Engineering explains sampling →

Statistics Every Programmer Needs

Random sampling is a sampling procedure in which selections are made according to a probability mechanism rather than a deterministic choice.

How it is used
Uses probability-driven scenarios to analyze uncertainty, variability, risk, staffing, and future prices.
How deep it goes
Explains the simulation workflow from model definition through repeated trials and result analysis, but does not provide implementation code.
Examples
Demonstrates absenteeism counts, Poisson outcomes, call-center overstaffing, and simulated future stock prices.
What you can do after
Apply random sampling to construct scenarios, compare simulated and theoretical distributions, and interpret uncertainty for operational or investment decisions.

Read how Statistics Every Programmer Needs explains sampling →

Bayesian Optimization in Action

Uniform sampling draws points so that equal-size regions of the sampling domain have equal probability.

How it is used
Uses uniform random points as a baseline for objective optimization and draws possible function realizations from Gaussian-process predictions.
How deep it goes
Defines uniform sampling, illustrates clustering and wasted evaluations, and demonstrates GP sampling in Python, stopping short of sampling theory.
Examples
Uses bounded objective search, clustered random evaluations, and five plotted samples from a zero-mean Gaussian process.
What you can do after
Apply it via random search for bounded objectives and use GPyTorch predictive distributions to generate reproducible function samples.

Read how Bayesian Optimization in Action explains sampling →

Fabulous Adventures in Data Structures and Algorithms

Sampling is the process of generating a random outcome according to a probability distribution.

How it is used
Uses probability distributions to generate random outcomes for games, simulations, sequences, and uncertainty-aware decisions.
How deep it goes
Develops PMFs, PDFs, Markov transitions, and Metropolis sampling, while deferring detailed algorithmic implementations for particular distributions.
Examples
Uses colored marbles, dice and simulated events, beta-shaped densities, dart-area geometry, random text, and posterior distributions.
What you can do after
Apply sampling to generate discrete outcomes, continuous values, Markov sequences, and Metropolis-based posterior samples.

Read how Fabulous Adventures in Data Structures and Algorithms explains sampling →

Grokking Bayes

Sampling is the process of generating values or outcomes from a specified probability distribution.

How it is used
Supports Bayesian model checking, posterior approximation, prediction, and decision-making through simulated outcomes.
How deep it goes
Defines random variates, demonstrates distributional convergence, and motivates Monte Carlo and MCMC without fully developing MCMC best practices.
Examples
Uses Beta(1, 1), normal, and Beta(4, 3) distributions, 10,000-sample histograms, and scipy.stats.rvs.
What you can do after
Apply sampling to Bayesian models, estimate posterior quantities, perform predictive checks, and evaluate sampling results.

Read how Grokking Bayes explains sampling →

How Large Language Models Work

Sampling is the computational process of selecting output tokens from a probability distribution over vocabulary items.

How it is used
Explains how autoregressive language models convert next-token probabilities into generated text.
How deep it goes
Traces probability calculation, weighted selection, repetition, randomness, and stopping without detailing sampling variants.
Examples
Uses “I love to eat,” weighted food-token choices, repeated prompts, and an end-of-sequence stopping example.
What you can do after
Evaluate why outputs vary and adjust randomness when choosing between more consistent or more creative generation.

Read how How Large Language Models Work explains sampling →

Effective Data Analysis

Random selection is a sampling procedure in which participants or subjects are chosen from a population using chance-based selection.

How it is used
Supports experiments by selecting participants or subjects from a population before testing causal hypotheses.
How deep it goes
Defines pure, stratified, and clustered selection, but does not detail implementation or sample-size decisions.
Examples
Uses experimental participants, population subgroups, and randomly selected groups as concrete selection examples.
What you can do after
Apply pure, stratified, or clustered selection when designing an experiment.

Read how Effective Data Analysis explains sampling →

Deep Learning with R, Third Edition

Sampling is the process of drawing values or instances from a probability distribution or representation space.

How it is used
Generates text by choosing each next token from a language model’s predicted probability distribution.
How deep it goes
Explains greedy, random, temperature-scaled, and top-k strategies with runnable examples, but does not develop formal decoding theory.
Examples
Uses generated text at temperatures 2, 0.8, and 0.2, alongside top-k runs with k=5 and k=20.
What you can do after
Apply it via R and Keras 3 to generate text with greedy, random, temperature-scaled, or top-k choices.

Read how Deep Learning with R, Third Edition explains sampling →

Build AI Drug Discovery Pipelines

Random sampling is the selection of items uniformly at random from an available population or pool.

How it is used
Initialize molecular-docking active learning before labels exist, and provide a random baseline for virtual-screening enrichment.
How deep it goes
Defines uniform selection, provides a NumPy implementation, and notes library-imbalance drawbacks.
Examples
Uses molecular-pool initialization and a 1,000-compound screening example with 100 known actives.
What you can do after
Apply it via NumPy to select an initial subset of molecular candidates without replacement.

Read how Build AI Drug Discovery Pipelines explains sampling →

AI Agents in Action, Second Edition

How it is used
Selects the next token during LLM generation from the model’s predicted probability distribution.
How deep it goes
Defines token selection and names decoding strategies, but stops short of explaining their algorithms.
Examples
Contrasts coder and creative-writer settings and summarizes temperature and top-p trade-offs.
What you can do after
Configure generation by adjusting temperature or top-p for variety and setting max tokens to cap response length.

Read how AI Agents in Action, Second Edition explains sampling →

Machine Learning System Design

Sampling is the process of selecting a subset of observations from a larger dataset for analysis or model training.

How it is used
Improves dataset efficiency when automatically generated data is huge, imbalanced, or full of duplicates.
How deep it goes
Defines stratified selection and prioritization but does not develop specific sampling algorithms.
Examples
Uses clickstreams, feature-based groups, algorithmic clusters, and fresh-versus-old temporal groups.
What you can do after
Apply stratification to reduce redundant data and emphasize groups relevant to the modeling problem.

Read how Machine Learning System Design explains sampling →

Delivering Machine Learning Projects: From design to deployment

Sampling is the process of selecting a subset of observations from a larger population or data set.

How it is used
Guides data-set construction during exploratory data analysis before modeling.
How deep it goes
Warns against random selection and uses plots to inspect distribution, without defining formal sampling methods.
Examples
Uses restaurant tips and bills plus temperature readings distributed across days of the year.
What you can do after
Evaluate whether a sample preserves distributional information needed by modeling algorithms.

Read how Delivering Machine Learning Projects: From design to deployment explains sampling →

Also covered in

What to know first

Related concepts

Questions about sampling

What is sampling?

Sampling is a procedure for selecting items from a collection or generating outcomes from a probability distribution according to a specified rule.

Which Manning books explain sampling?

Troubleshooting Java: Read, debug, and optimize JVM applications, Optimization Algorithms: AI techniques for design, planning, and control problems, Advanced Algorithms and Data Structures, Deep Learning with Python, Third Edition, Grokking Statistics, Learn Generative AI with PyTorch, Natural Language Processing in Action, Second Edition, AI Model Evaluation and 23 more.

What should I know before learning sampling?

Manning books that teach sampling usually introduce language model, probability distribution, generation and mean first.

What is the difference between sampling and Sobol sequence?

Sampling is a procedure for selecting items from a collection or generating outcomes from a probability distribution according to a specified rule. A Sobol sequence is a low-discrepancy quasi-random sequence designed to distribute points evenly across a multidimensional domain.

What kinds of sampling are there?

Kinds of sampling include random sampling.

What is sampling a kind of?

Sampling is a kind of filtering. Filtering is the selection or exclusion of data or items according to specified criteria.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.