Aleph-w 7.10.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.
 
 Entropy_Observer (const Entropy_Observer &other)=default
 Copy another observer: the entropy of each step, and whether it has seen a frame.
 
 Entropy_Observer (Entropy_Observer &&other) noexcept
 Take the samples of another observer, which is left with none.
 
Entropy_Observer & operator= (const Entropy_Observer &other)=default
 Copy another observer into this one: the entropy of each step, and whether it has seen a frame.
 
Entropy_Observer & operator= (Entropy_Observer &&other) noexcept
 Exchange this observer with another, which is left with the previous samples of this one.
 
void swap (Entropy_Observer &other) noexcept
 Exchange in O(1) the samples of this observer and another.
 
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 601 of file ca-observer.H.

Constructor & Destructor Documentation

◆ Entropy_Observer() [1/3]

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

Construct an empty entropy observer.

Exceptions
Thisfunction does not throw.

◆ Entropy_Observer() [2/3]

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

Copy another observer: the entropy of each step, and whether it has seen a frame.

Parameters
[in]otherobserver to copy.

◆ Entropy_Observer() [3/3]

template<std::size_t MaxState>
Aleph::CA::Entropy_Observer< MaxState >::Entropy_Observer ( Entropy_Observer< MaxState > &&  other)
inlinenoexcept

Take the samples of another observer, which is left with none.

The implicit move took the samples but copied the flag of the initial sample: the moved-from observer, reused, skipped the initial frame of its next run.

Parameters
[in,out]otherobserver to move from.

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

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 661 of file ca-observer.H.

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

Referenced by main().

◆ 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 694 of file ca-observer.H.

References Aleph::and, Aleph::Array< T >::append(), 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 710 of file ca-observer.H.

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

◆ operator=() [1/2]

template<std::size_t MaxState>
Entropy_Observer & Aleph::CA::Entropy_Observer< MaxState >::operator= ( const Entropy_Observer< MaxState > &  other)
default

Copy another observer into this one: the entropy of each step, and whether it has seen a frame.

Parameters
[in]otherobserver to copy.
Returns
this observer.

◆ operator=() [2/2]

template<std::size_t MaxState>
Entropy_Observer & Aleph::CA::Entropy_Observer< MaxState >::operator= ( Entropy_Observer< MaxState > &&  other)
inlinenoexcept

Exchange this observer with another, which is left with the previous samples of this one.

Parameters
[in,out]otherobserver to move from.
Returns
this observer.

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

References Aleph::CA::Entropy_Observer< MaxState >::swap().

◆ 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 681 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 670 of file ca-observer.H.

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

Referenced by main().

◆ swap()

template<std::size_t MaxState>
void Aleph::CA::Entropy_Observer< MaxState >::swap ( Entropy_Observer< MaxState > &  other)
inlinenoexcept

Exchange in O(1) the samples of this observer and another.

Parameters
[in,out]otherobserver to exchange with.

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

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

Referenced by Aleph::CA::Entropy_Observer< MaxState >::operator=().

Member Data Documentation

◆ entropy_

◆ seeded_


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