Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ca-metrics.H File Reference

Free metric helpers for cellular automata frames. More...

#include <cmath>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <ah-errors.H>
#include <tpl_array.H>
#include <ca-traits.H>
#include <tpl_ca_concepts.H>
Include dependency graph for ca-metrics.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::CA
 
namespace  Aleph::CA::ca_metrics_detail
 

Concepts

concept  Aleph::CA::ca_metrics_detail::HasAtNode
 Detect whether L exposes a graph-style at_node(size_t) accessor.
 

Functions

constexpr std::uint64_t Aleph::CA::ca_metrics_detail::fnv1a_step (std::uint64_t h, const std::uint8_t b) noexcept
 Mix one byte into an FNV-1a hash.
 
template<typename T >
std::uint64_t Aleph::CA::ca_metrics_detail::fnv1a_mix (std::uint64_t h, const T &value) noexcept
 Mix every byte of value (in little-endian order) into an FNV-1a hash.
 
template<typename Lattice , typename F >
void Aleph::CA::for_each_cell (const Lattice &lat, F &&f)
 Visit every cell of a lattice in canonical row-major order.
 
template<typename Lattice >
ca_size_t Aleph::CA::count_state (const Lattice &lat, const typename Lattice::state_type &s)
 
template<typename Lattice >
ca_size_t Aleph::CA::count_alive (const Lattice &lat)
 
template<typename Lattice >
ca_size_t Aleph::CA::total_cells (const Lattice &lat) noexcept
 
template<typename Lattice >
double Aleph::CA::density (const Lattice &lat, const typename Lattice::state_type &s)
 
template<typename Lattice >
double Aleph::CA::alive_density (const Lattice &lat)
 
template<typename Lattice >
Array< ca_size_t > Aleph::CA::state_histogram (const Lattice &lat, std::size_t max_state)
 Count occurrences of every integer state in [0, max_state).
 
template<typename Lattice >
double Aleph::CA::shannon_entropy (const Lattice &lat, std::size_t max_state)
 Shannon entropy in nats of the [0, max_state) distribution.
 
template<typename Lattice >
std::uint64_t Aleph::CA::frame_hash (const Lattice &lat)
 Deterministic 64-bit FNV-1a hash of the lattice cells.
 
template<typename Lattice >
bool Aleph::CA::frames_equal (const Lattice &a, const Lattice &b)
 
template<typename Lattice >
ca_size_t Aleph::CA::cell_diff_count (const Lattice &a, const Lattice &b)
 

Variables

constexpr std::uint64_t Aleph::CA::ca_metrics_detail::fnv_basis = 14695981039346656037ull
 FNV-1a 64-bit basis and prime constants.
 
constexpr std::uint64_t Aleph::CA::ca_metrics_detail::fnv_prime = 1099511628211ull
 

Detailed Description

Free metric helpers for cellular automata frames.

Provides allocation-free utilities to compute simple aggregate statistics over any LatticeLike lattice without coupling them to a particular boundary policy or storage type. Used both by the Phase-7 observers (ca-observer.H) and by user code that needs to evaluate a metric ad-hoc on a frame.

Catalogue:

  • for_each_cell(lat, f) — generic cell visitor for ranks 1, 2 and 3, plus the rank-1 graph lattice.
  • count_state(lat, s) — number of cells in state s.
  • count_alive(lat) — count_state(lat, T{}, true), i.e., number of cells whose value differs from state_type{}.
  • density(lat, s) — alive ratio in [0, 1].
  • state_histogram(lat, max) — array of counts per integer state in [0, max).
  • shannon_entropy(lat, max) — Shannon entropy in nats over the state distribution; 0 for empty or constant lattices.
  • frame_hash(lat) — deterministic 64-bit FNV-1a hash of the cell sequence in row-major order. Stable across runs and across builds (no random seed, no implementation- defined hashing).
  • frames_equal(a, b) — bit-for-bit comparison.
  • cell_diff_count(a, b) — number of cells that differ.

All helpers are header-only inline templates and do not allocate (state_histogram allocates one buffer that the caller may pre-size).

Author
Leandro Rabindranath Leon

Definition in file ca-metrics.H.