Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Reproductions Namespace Reference

Classes

struct  Avalanche
 Avalanche measurements for one BTW grain drop. More...
 
class  BTW_Sandpile
 Deterministic open-boundary Bak-Tang-Wiesenfeld sandpile. More...
 
struct  Gray_Scott_Preset
 One named Gray-Scott parameter preset. More...
 
struct  Linear_Fit
 Least-squares result for a log-log histogram. More...
 
struct  Native_Png
 Decoded subset of the dependency-free native PNG format. More...
 

Typedefs

using Gray_Scott_Cell = Reaction_Diffusion_Cell< double >
 
using Gray_Scott_Lattice = Lattice< Dense_Cell_Storage< Gray_Scott_Cell, 2 >, NeumannBoundary >
 

Functions

Linear_Fit fit_log_log_histogram (const std::vector< std::size_t > &samples, const std::size_t min_value, const std::size_t max_value, const std::size_t bins, const double sample_weight_power=0.0)
 Fit a power-law exponent from logarithmically binned samples.
 
void write_histogram_csv (const std::filesystem::path &path, const std::vector< std::size_t > &samples)
 Write an exact discrete histogram as CSV.
 
template<typename Lattice >
double morans_i_binary (const Lattice &frame, const typename Lattice::state_type empty_state, const typename Lattice::state_type type_a, const typename Lattice::state_type type_b)
 Compute Moran's I for two occupied Schelling cell types.
 
Gray_Scott_Lattice make_gray_scott_seed (const ca_size_t side, const std::uint64_t master_seed)
 Build the deterministic finite-amplitude Gray-Scott perturbation.
 
Gray_Scott_Lattice run_gray_scott (const Gray_Scott_Preset &preset, const ca_size_t side, const std::size_t steps, const std::uint64_t master_seed)
 Run one Gray-Scott preset from the shared deterministic seed.
 
RGB8 gray_scott_rgb (const Gray_Scott_Cell &cell)
 Convert one Gray-Scott state to an RGB colour.
 
void write_gray_scott_png (const std::filesystem::path &path, const Gray_Scott_Lattice &frame)
 Write a Gray-Scott frame as a native Aleph RGB PNG.
 
Native_Png decode_native_png (std::istream &in)
 Decode a PNG emitted by Aleph::CA::write_png.
 
Native_Png read_native_png (const std::filesystem::path &path)
 Read and decode a native Aleph PNG.
 
double mean_channel_difference (const Native_Png &lhs, const Native_Png &rhs)
 Compute normalized mean absolute per-channel PNG difference.
 
template<typename F >
void for_each_gosper_gun_cell (F &&visitor, const std::int64_t offset_x=0, const std::int64_t offset_y=0)
 Visit every live coordinate in the canonical Gosper gun.
 

Variables

constexpr std::array< Gray_Scott_Preset, 3 > gray_scott_presets
 Canonical visual presets used by the weekly Gray-Scott reproduction.
 
constexpr std::array< std::array< std::int64_t, 2 >, 36 > gosper_gun_cells
 Canonical 36-cell Gosper glider gun.
 

Typedef Documentation

◆ Gray_Scott_Cell

◆ Gray_Scott_Lattice

Function Documentation

◆ decode_native_png()

Native_Png Aleph::CA::Reproductions::decode_native_png ( std::istream &  in)
inline

Decode a PNG emitted by Aleph::CA::write_png.

Only the dependency-free writer's filter-0, stored-deflate output is accepted. This keeps golden comparisons strict and avoids a PNG dependency.

Parameters
inbinary PNG stream.
Returns
decoded dimensions and scanline bytes.
Exceptions
std::runtime_errorif the stream is malformed or unsupported.

Definition at line 528 of file ca_reproduction_support.H.

References ah_runtime_error_if, and Aleph::blossom_maximum_cardinality_matching().

Referenced by read_native_png(), and TEST().

◆ fit_log_log_histogram()

Linear_Fit Aleph::CA::Reproductions::fit_log_log_histogram ( const std::vector< std::size_t > &  samples,
const std::size_t  min_value,
const std::size_t  max_value,
const std::size_t  bins,
const double  sample_weight_power = 0.0 
)
inline

Fit a power-law exponent from logarithmically binned samples.

Each populated bin contributes its geometric midpoint and probability density (count / width) to an ordinary least-squares fit in log space. The omitted global normalization does not affect the slope.

Parameters
samplespositive integral event sizes.
min_valuesmallest sample included in the fit.
max_valuelargest sample included in the fit.
binsnumber of logarithmic bins.
sample_weight_powerweight each sample s by s^-sample_weight_power. The default 0.0 fits directly observed event probabilities.
Returns
fitted slope, intercept, R-squared and populated-bin count.
Exceptions
std::domain_errorif the fit range is invalid or fewer than two logarithmic bins are requested.
std::runtime_errorif fewer than two populated bins remain.
Complexity
O(samples.size() + bins).

Definition at line 107 of file ca_reproduction_support.H.

References ah_domain_error_if, ah_runtime_error_if, Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::density(), Aleph::CA::Reproductions::Linear_Fit::intercept, Aleph::max_value(), Aleph::min_value(), offset, Aleph::CA::Reproductions::Linear_Fit::points, Aleph::CA::Reproductions::Linear_Fit::r_squared, Aleph::CA::Reproductions::Linear_Fit::slope, and y.

Referenced by main(), main(), and TEST().

◆ for_each_gosper_gun_cell()

template<typename F >
void Aleph::CA::Reproductions::for_each_gosper_gun_cell ( F &&  visitor,
const std::int64_t  offset_x = 0,
const std::int64_t  offset_y = 0 
)

Visit every live coordinate in the canonical Gosper gun.

Template Parameters
Fcallable accepting (x, y).
Parameters
visitorcoordinate callback.
offset_xhorizontal offset.
offset_yvertical offset.

Definition at line 666 of file ca_reproduction_support.H.

References Aleph::blossom_maximum_cardinality_matching(), cell(), and gosper_gun_cells.

Referenced by main(), and TEST().

◆ gray_scott_rgb()

RGB8 Aleph::CA::Reproductions::gray_scott_rgb ( const Gray_Scott_Cell &  cell)
inline

Convert one Gray-Scott state to an RGB colour.

Parameters
cellconcentration pair.
Returns
palette colour.

Definition at line 484 of file ca_reproduction_support.H.

References cell(), and value.

Referenced by TEST(), and write_gray_scott_png().

◆ make_gray_scott_seed()

Gray_Scott_Lattice Aleph::CA::Reproductions::make_gray_scott_seed ( const ca_size_t  side,
const std::uint64_t  master_seed 
)
inline

Build the deterministic finite-amplitude Gray-Scott perturbation.

Parameters
sidesquare lattice side length.
master_seedseed for cell-local perturbations.
Returns
initial Gray-Scott frame.
Exceptions
std::domain_errorif side < 8.

Definition at line 441 of file ca_reproduction_support.H.

References ah_domain_error_if, Aleph::blossom_maximum_cardinality_matching(), h, and r.

Referenced by run_gray_scott().

◆ mean_channel_difference()

double Aleph::CA::Reproductions::mean_channel_difference ( const Native_Png &  lhs,
const Native_Png &  rhs 
)
inline

Compute normalized mean absolute per-channel PNG difference.

Parameters
lhsfirst decoded PNG.
rhssecond decoded PNG.
Returns
difference in [0, 1], where 0 is pixel-identical.
Exceptions
std::domain_errorif dimensions differ.

Definition at line 625 of file ca_reproduction_support.H.

References ah_domain_error_if, ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Reproductions::Native_Png::height, Aleph::CA::Reproductions::Native_Png::raw, row, and Aleph::CA::Reproductions::Native_Png::width.

Referenced by main(), and TEST().

◆ morans_i_binary()

template<typename Lattice >
double Aleph::CA::Reproductions::morans_i_binary ( const Lattice &  frame,
const typename Lattice::state_type  empty_state,
const typename Lattice::state_type  type_a,
const typename Lattice::state_type  type_b 
)

Compute Moran's I for two occupied Schelling cell types.

Empty cells are excluded. Occupied cells are encoded as +1 and -1; each occupied cell is connected to its four periodic Von-Neumann neighbours when those neighbours are occupied.

Template Parameters
Latticerank-2 lattice type.
Parameters
frametoroidal Schelling frame.
empty_statevalue representing a vacancy.
type_avalue representing the first population.
type_bvalue representing the second population.
Returns
Moran's I, or 0.0 when the statistic is undefined.
Complexity
O(rows * columns).

Definition at line 218 of file ca_reproduction_support.H.

References Aleph::CA::Lattice< Storage, Boundary >::at(), Aleph::blossom_maximum_cardinality_matching(), cols, k, Aleph::mean(), r, Aleph::CA::Lattice< Storage, Boundary >::rank, rows, Aleph::CA::Lattice< Storage, Boundary >::size(), Aleph::sum(), and value.

Referenced by main().

◆ read_native_png()

Native_Png Aleph::CA::Reproductions::read_native_png ( const std::filesystem::path &  path)
inline

Read and decode a native Aleph PNG.

Parameters
pathinput path.
Returns
decoded PNG.
Exceptions
std::runtime_errorif the file cannot be read or decoded.

Definition at line 612 of file ca_reproduction_support.H.

References ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), and decode_native_png().

Referenced by main().

◆ run_gray_scott()

Gray_Scott_Lattice Aleph::CA::Reproductions::run_gray_scott ( const Gray_Scott_Preset &  preset,
const ca_size_t  side,
const std::size_t  steps,
const std::uint64_t  master_seed 
)
inline

Run one Gray-Scott preset from the shared deterministic seed.

Parameters
presetfeed and kill rates.
sidesquare lattice side length.
stepsnumber of synchronous steps.
master_seedperturbation seed.
Returns
final Gray-Scott frame.

Definition at line 468 of file ca_reproduction_support.H.

References Aleph::blossom_maximum_cardinality_matching(), engine, make_gray_scott_seed(), and steps.

Referenced by main(), and TEST().

◆ write_gray_scott_png()

void Aleph::CA::Reproductions::write_gray_scott_png ( const std::filesystem::path &  path,
const Gray_Scott_Lattice &  frame 
)
inline

Write a Gray-Scott frame as a native Aleph RGB PNG.

Parameters
pathoutput path.
frameframe to encode.
Exceptions
std::runtime_errorif the output cannot be written.

Definition at line 501 of file ca_reproduction_support.H.

References ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), gray_scott_rgb(), out, and Aleph::CA::write_png().

Referenced by main().

◆ write_histogram_csv()

void Aleph::CA::Reproductions::write_histogram_csv ( const std::filesystem::path &  path,
const std::vector< std::size_t > &  samples 
)
inline

Write an exact discrete histogram as CSV.

Parameters
pathoutput path.
samplesintegral samples to count.
Exceptions
std::runtime_errorif the output cannot be written.
Complexity
O(samples.size() log samples.size()).

Definition at line 184 of file ca_reproduction_support.H.

References ah_runtime_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::count(), Aleph::histogram(), out, and Aleph::size().

Referenced by main().

Variable Documentation

◆ gosper_gun_cells

constexpr std::array<std::array<std::int64_t, 2>, 36> Aleph::CA::Reproductions::gosper_gun_cells
inlineconstexpr
Initial value:
{{
{{1, 5}}, {{1, 6}}, {{2, 5}}, {{2, 6}},
{{11, 5}}, {{11, 6}}, {{11, 7}}, {{12, 4}}, {{12, 8}},
{{13, 3}}, {{13, 9}}, {{14, 3}}, {{14, 9}},
{{15, 6}}, {{16, 4}}, {{16, 8}},
{{17, 5}}, {{17, 6}}, {{17, 7}}, {{18, 6}},
{{21, 3}}, {{21, 4}}, {{21, 5}},
{{22, 3}}, {{22, 4}}, {{22, 5}},
{{23, 2}}, {{23, 6}},
{{25, 1}}, {{25, 2}}, {{25, 6}}, {{25, 7}},
{{35, 3}}, {{35, 4}}, {{36, 3}}, {{36, 4}},
}}

Canonical 36-cell Gosper glider gun.

Definition at line 646 of file ca_reproduction_support.H.

Referenced by for_each_gosper_gun_cell().

◆ gray_scott_presets

constexpr std::array<Gray_Scott_Preset, 3> Aleph::CA::Reproductions::gray_scott_presets
inlineconstexpr
Initial value:
{{
{"spots", 0.0350, 0.0650},
{"stripes", 0.0250, 0.0500},
{"mitosis", 0.0367, 0.0649},
}}

Canonical visual presets used by the weekly Gray-Scott reproduction.

Definition at line 426 of file ca_reproduction_support.H.

Referenced by main(), and TEST().