Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Entropy_Observer< MaxState > Class Template Reference

Records the Shannon entropy of the state distribution. More...

#include <ca-observer.H>

Collaboration diagram for Aleph::CA::Entropy_Observer< MaxState >:
[legend]

Public Member Functions

 Entropy_Observer ()=default
 Construct an empty entropy observer.
 
const Array< double > & entropy () const noexcept
 Return the entropy time series.
 
std::size_t size () const noexcept
 Return the number of entropy samples.
 
void reset () noexcept
 Clear all entropy samples.
 
template<typename Lattice >
void on_step_begin (const std::size_t step, const Lattice &frame)
 Record entropy of the initial frame.
 
template<typename Lattice >
void on_step_end (const std::size_t step, const Lattice &frame)
 Record entropy after a completed step.
 

Private Attributes

Array< double > entropy_
 
bool seeded_ = false
 

Detailed Description

template<std::size_t MaxState>
class Aleph::CA::Entropy_Observer< MaxState >

Records the Shannon entropy of the state distribution.

Computes the entropy in nats over the integer states in [0, MaxState). Pushes one sample per step (including the initial frame).

Template Parameters
MaxStateexclusive upper bound on the state values.
Complexity
Callbacks are O(N + MaxState) per sampled frame.
Thread-safety
Thread-safe for concurrent readers after simulation stops; not thread-safe for concurrent callbacks.
Exception-safety
Strong guarantee unless array allocation throws.

Definition at line 548 of file ca-observer.H.

Constructor & Destructor Documentation

◆ Entropy_Observer()

template<std::size_t MaxState>
Aleph::CA::Entropy_Observer< MaxState >::Entropy_Observer ( )
default

Construct an empty entropy observer.

Exceptions
Thisfunction does not throw.

Member Function Documentation

◆ entropy()

template<std::size_t MaxState>
const Array< double > & Aleph::CA::Entropy_Observer< MaxState >::entropy ( ) const
inlinenoexcept

Return the entropy time series.

Returns
entropies in nats, including the initial frame.
Exceptions
Thisfunction does not throw.

Definition at line 563 of file ca-observer.H.

References Aleph::CA::Entropy_Observer< MaxState >::entropy_.

◆ on_step_begin()

template<std::size_t MaxState>
template<typename Lattice >
void Aleph::CA::Entropy_Observer< MaxState >::on_step_begin ( const std::size_t  step,
const Lattice &  frame 
)
inline

Record entropy of the initial frame.

Template Parameters
Latticelattice type.
Parameters
[in]stepstep index about to run.
[in]frameframe before the step.
Exceptions
std::bad_allocif appending the sample allocates.

Definition at line 596 of file ca-observer.H.

References Aleph::and, Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Entropy_Observer< MaxState >::entropy_, Aleph::CA::Entropy_Observer< MaxState >::seeded_, and Aleph::CA::shannon_entropy().

◆ on_step_end()

template<std::size_t MaxState>
template<typename Lattice >
void Aleph::CA::Entropy_Observer< MaxState >::on_step_end ( const std::size_t  step,
const Lattice &  frame 
)
inline

Record entropy after a completed step.

Template Parameters
Latticelattice type.
Parameters
[in]stepcompleted step index, ignored.
[in]frameframe after the step.
Exceptions
std::bad_allocif appending the sample allocates.

Definition at line 612 of file ca-observer.H.

References Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Entropy_Observer< MaxState >::entropy_, and Aleph::CA::shannon_entropy().

◆ reset()

template<std::size_t MaxState>
void Aleph::CA::Entropy_Observer< MaxState >::reset ( )
inlinenoexcept

Clear all entropy samples.

Exceptions
Thisfunction does not throw.
Complexity
O(size()).

Definition at line 583 of file ca-observer.H.

References Aleph::Array< T >::clear(), Aleph::CA::Entropy_Observer< MaxState >::entropy_, and Aleph::CA::Entropy_Observer< MaxState >::seeded_.

◆ size()

template<std::size_t MaxState>
std::size_t Aleph::CA::Entropy_Observer< MaxState >::size ( ) const
inlinenoexcept

Return the number of entropy samples.

Returns
sample count.
Exceptions
Thisfunction does not throw.

Definition at line 572 of file ca-observer.H.

References Aleph::CA::Entropy_Observer< MaxState >::entropy_, and Aleph::Array< T >::size().

Member Data Documentation

◆ entropy_

◆ seeded_

template<std::size_t MaxState>
bool Aleph::CA::Entropy_Observer< MaxState >::seeded_ = false
private

The documentation for this class was generated from the following file: