mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 20:36:53 +01:00
Got rid of the EntropyMemoisation struct as it just makes readability worse.
This commit is contained in:
parent
a501292046
commit
fdb6ced123
@ -52,20 +52,20 @@ Wave::Wave(uint32_t height, uint32_t width,
|
||||
double log_base_s = log(base_s);
|
||||
double entropy_base = log_base_s - base_entropy / base_s;
|
||||
|
||||
memoisation.plogp_sum.resize(width * height);
|
||||
memoisation.plogp_sum.fill(base_entropy);
|
||||
memoisation_plogp_sum.resize(width * height);
|
||||
memoisation_plogp_sum.fill(base_entropy);
|
||||
|
||||
memoisation.sum.resize(width * height);
|
||||
memoisation.sum.fill(base_s);
|
||||
memoisation_sum.resize(width * height);
|
||||
memoisation_sum.fill(base_s);
|
||||
|
||||
memoisation.log_sum.resize(width * height);
|
||||
memoisation.log_sum.fill(log_base_s);
|
||||
memoisation_log_sum.resize(width * height);
|
||||
memoisation_log_sum.fill(log_base_s);
|
||||
|
||||
memoisation.nb_patterns.resize(width * height);
|
||||
memoisation.nb_patterns.fill(static_cast<uint32_t>(nb_patterns));
|
||||
memoisation_nb_patterns.resize(width * height);
|
||||
memoisation_nb_patterns.fill(static_cast<uint32_t>(nb_patterns));
|
||||
|
||||
memoisation.entropy.resize(width * height);
|
||||
memoisation.entropy.fill(entropy_base);
|
||||
memoisation_entropy.resize(width * height);
|
||||
memoisation_entropy.fill(entropy_base);
|
||||
}
|
||||
|
||||
void Wave::set(uint32_t index, uint32_t pattern, bool value) {
|
||||
@ -78,14 +78,14 @@ void Wave::set(uint32_t index, uint32_t pattern, bool value) {
|
||||
|
||||
// Otherwise, the memoisation should be updated.
|
||||
data.get(index, pattern) = value;
|
||||
memoisation.plogp_sum.write[index] -= plogp_patterns_frequencies[pattern];
|
||||
memoisation.sum.write[index] -= patterns_frequencies[pattern];
|
||||
memoisation.log_sum.write[index] = log(memoisation.sum[index]);
|
||||
memoisation.nb_patterns.write[index]--;
|
||||
memoisation.entropy.write[index] = memoisation.log_sum[index] - memoisation.plogp_sum[index] / memoisation.sum[index];
|
||||
memoisation_plogp_sum.write[index] -= plogp_patterns_frequencies[pattern];
|
||||
memoisation_sum.write[index] -= patterns_frequencies[pattern];
|
||||
memoisation_log_sum.write[index] = log(memoisation_sum[index]);
|
||||
memoisation_nb_patterns.write[index]--;
|
||||
memoisation_entropy.write[index] = memoisation_log_sum[index] - memoisation_plogp_sum[index] / memoisation_sum[index];
|
||||
|
||||
// If there is no patterns possible in the cell, then there is a contradiction.
|
||||
if (memoisation.nb_patterns[index] == 0) {
|
||||
if (memoisation_nb_patterns[index] == 0) {
|
||||
is_impossible = true;
|
||||
}
|
||||
}
|
||||
@ -104,14 +104,14 @@ int Wave::get_min_entropy(std::minstd_rand &gen) const {
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
// If the cell is decided, we do not compute the entropy (which is equal
|
||||
// to 0).
|
||||
double nb_patterns_local = memoisation.nb_patterns[i];
|
||||
double nb_patterns_local = memoisation_nb_patterns[i];
|
||||
|
||||
if (nb_patterns_local == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Otherwise, we take the memoised entropy.
|
||||
double entropy = memoisation.entropy[i];
|
||||
double entropy = memoisation_entropy[i];
|
||||
|
||||
// We first check if the entropy is less than the minimum.
|
||||
// This is important to reduce noise computation (which is not
|
||||
|
@ -5,18 +5,6 @@
|
||||
#include <random>
|
||||
#include "core/vector.h"
|
||||
|
||||
// Struct containing the values needed to compute the entropy of all the cells.
|
||||
// This struct is updated every time the wave is changed.
|
||||
// p'(pattern) is equal to patterns_frequencies[pattern] if wave.get(cell,
|
||||
// pattern) is set to true, otherwise 0.
|
||||
struct EntropyMemoisation {
|
||||
Vector<double> plogp_sum; // The sum of p'(pattern)// log(p'(pattern)).
|
||||
Vector<double> sum; // The sum of p'(pattern).
|
||||
Vector<double> log_sum; // The log of sum.
|
||||
Vector<uint32_t> nb_patterns; // The number of patterns present
|
||||
Vector<double> entropy; // The entropy of the cell.
|
||||
};
|
||||
|
||||
// Contains the pattern possibilities in every cell.
|
||||
// Also contains information about cell entropy.
|
||||
class Wave {
|
||||
@ -31,7 +19,11 @@ private:
|
||||
// This is used to define the maximum value of the noise.
|
||||
const double min_abs_half_plogp;
|
||||
|
||||
EntropyMemoisation memoisation;
|
||||
Vector<double> memoisation_plogp_sum; // The sum of p'(pattern)// log(p'(pattern)).
|
||||
Vector<double> memoisation_sum; // The sum of p'(pattern).
|
||||
Vector<double> memoisation_log_sum; // The log of sum.
|
||||
Vector<uint32_t> memoisation_nb_patterns; // The number of patterns present
|
||||
Vector<double> memoisation_entropy; // The entropy of the cell.
|
||||
|
||||
// This value is set to true if there is a contradiction in the wave (all elements set to false in a cell).
|
||||
bool is_impossible;
|
||||
|
Loading…
Reference in New Issue
Block a user