Chain-Load: generate statistics report

...test and fix the statistics computation...
This commit is contained in:
Fischlurch 2023-11-28 16:25:22 +01:00
parent c3bef6d344
commit 852a86bbda
3 changed files with 110 additions and 35 deletions

View file

@ -239,7 +239,8 @@ namespace test {
graph.expansionRule(graph.rule().probability(0.8).maxVal(1))
.pruningRule(graph.rule().probability(0.6))
.buildToplolgy()
.printTopologyDOT();
.printTopologyDOT()
.printTopologyStatistics();
}

View file

@ -90,6 +90,7 @@
//#include "lib/meta/function.hpp"
//#include "lib/wrapper.hpp"
#include "lib/iter-explorer.hpp"
#include "lib/format-string.hpp"
#include "lib/format-cout.hpp"
#include "lib/random-draw.hpp"
#include "lib/dot-gen.hpp"
@ -104,7 +105,6 @@
#include <memory>
#include <string>
#include <array>
#include <map>
namespace vault{
@ -118,6 +118,7 @@ namespace test {
// using lib::time::FSecs;
// using lib::time::Offset;
// using lib::meta::RebindVariadic;
using util::_Fmt;
using util::min;
using util::max;
using util::isnil;
@ -544,6 +545,7 @@ namespace test {
Statistic computeGraphStatistics();
TestChainLoad&& printTopologyStatistics();
private:
};
@ -648,6 +650,8 @@ namespace test {
/* ========= Graph Statistics Evaluation ========= */
const string STAT_SEED{"seed"}; ///< seed node
const string STAT_EXIT{"exit"}; ///< exit node
const string STAT_INNR{"innr"}; ///< inner node
@ -662,7 +666,7 @@ namespace test {
namespace {
template<class NOD>
inline auto
buildEvaluations()
prepareEvaluaions()
{
return std::array<std::function<uint(NOD&)>, CAT>
{ [](NOD& n){ return isStart(n);}
@ -676,7 +680,7 @@ namespace test {
}
}
using VecU = std::vector<uint>;
using VecU = std::vector<uint>;
using LevelSums = std::array<uint, CAT>;
/**
@ -689,21 +693,22 @@ namespace test {
VecU data{};
uint cnt{0}; ///< global sum over all levels
double frac{0}; ///< fraction of all nodes
double pL{0}; ///< average per level
double pL {0}; ///< average per level
double pLW{0}; ///< average per level and level-width
double cL{0}; ///< weight centre level for this indicator
double cL {0}; ///< weight centre level for this indicator
double cLW{0}; ///< weight centre level width-reduced
void
addPoint (uint level, uint width, uint items)
addPoint (uint levelID, uint width, uint items)
{
REQUIRE (level == data.size());
REQUIRE (levelID == data.size()); // ID is zero based
REQUIRE (width > 0);
data.push_back (items);
cnt += items;
pL += items;
pLW += items / double(width);
cL += level * items;
cLW += level * items/double(width);
cL += levelID * items;
cLW += levelID * items/double(width);
}
void
@ -712,8 +717,8 @@ namespace test {
uint levels = data.size();
REQUIRE (levels > 0);
frac = cnt / double(nodes);
cL /= pL; // weighted averages: normalise to weight sum
cLW /= pLW;
cL = pL? cL/pL :0; // weighted averages: normalise to weight sum
cLW = pLW? cLW/pLW :0;
pL /= levels; // simple averages : normalise to number of levels
pLW /= levels;
}
@ -728,14 +733,14 @@ namespace test {
uint levels{0};
VecU width{};
std::map<const string, Indicator> indicators;
std::array<Indicator, CAT> indicators;
explicit
Statistic (uint lvls)
: nodes{0}
, levels{lvls}
, levels{0}
{
reserve (levels);
reserve (lvls);
}
void
@ -745,38 +750,52 @@ namespace test {
nodes += levelWidth;
width.push_back (levelWidth);
ASSERT (levels == width.size());
ASSERT (0 < levels);
ASSERT (0 < levelWidth);
for (uint i=0; i< CAT; ++i)
indicators[KEYS[i]].addPoint (levels, levelWidth, particulars[i]);
indicators[i].addPoint (levels-1, levelWidth, particulars[i]);
}
void
closeAverages()
{
for (auto& KEY : KEYS)
indicators[KEY].closeAverages (nodes);
for (uint i=0; i< CAT; ++i)
indicators[i].closeAverages (nodes);
}
private:
void
reserve (uint levels)
reserve (uint lvls)
{
width.reserve (levels);
for (auto& KEY : KEYS)
width.reserve (lvls);
for (uint i=0; i< CAT; ++i)
{
indicators[KEY] = Indicator{};
indicators[KEY].data.reserve(levels);
indicators[i] = Indicator{};
indicators[i].data.reserve(lvls);
}
}
};
/**
* Operator on TestChainLoad to evaluate current graph connectivity.
* In a pass over the internal storage, all nodes are classified
* and accounted into a set of categories, thereby evaluating
* - the overall number of nodes and levels generated
* - the number of nodes in each level (termed _level width_)
* - the fraction of overall nodes falling into each category
* - the average number of category members over the levels
* - the density of members, normalised over level width
* - the weight centre of this category members
* - the weight centre of according to density
*/
template<size_t numNodes, size_t maxFan>
inline Statistic
TestChainLoad<numNodes,maxFan>::computeGraphStatistics()
{
auto totalLevels = uint(topLevel());
auto classify = buildEvaluations<Node>();
auto classify = prepareEvaluaions<Node>();
Statistic stat(totalLevels);
LevelSums particulars{0};
size_t level{0};
@ -784,10 +803,6 @@ namespace test {
for (Node& node : allNodes())
{
++width;
for (uint i=0; i<CAT; ++i)
particulars[i] += classify[i](node);
if (level != node.level)
{ // record statistics for previous level
stat.addPoint (width, particulars);
@ -797,13 +812,42 @@ namespace test {
particulars = LevelSums{0};
width = 0;
}
// classify and account..
++width;
for (uint i=0; i<CAT; ++i)
particulars[i] += classify[i](node);
}
ENSURE (level = topLevel());
stat.addPoint (width, particulars);
stat.closeAverages();
return stat;
}
template<size_t numNodes, size_t maxFan>
inline TestChainLoad<numNodes,maxFan>&&
TestChainLoad<numNodes,maxFan>::printTopologyStatistics()
{
cout << "INDI cnt frac ∅pL ∅pLW γL γLW\n";
_Fmt line{"%s %3d %3.0f%% %4.2f %4.2f %5.1f %5.1f\n"};
Statistic stat = computeGraphStatistics();
for (uint i=0; i< CAT; ++i)
{
Indicator& indi = stat.indicators[i];
cout << line % KEYS[i]
% indi.cnt
% (indi.frac*100)
% indi.pL
% indi.pLW
% indi.cL
% indi.cLW
;
}
cout << "───═══───═══───═══───═══───═══───═══───═══───═══───═══───═══───"
<< endl;
return move(*this);
}

View file

@ -99570,16 +99570,32 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1701126927102" ID="ID_1692039562" MODIFIED="1701127026960" TEXT="Map mit String-Key"/>
<node CREATED="1701127027572" ID="ID_554934189" MODIFIED="1701127035511" TEXT="Vector mit ENUM-index"/>
<node CREATED="1701127055028" ID="ID_544320843" MODIFIED="1701127068922" TEXT="Sub-Objekte mit member-ptr"/>
<node CREATED="1701127099690" ID="ID_1150088226" MODIFIED="1701127117708" TEXT="ist im Grunde egal &#x27f9; Map mit String-Key">
<node COLOR="#5b280f" CREATED="1701127099690" ID="ID_1150088226" MODIFIED="1701181195395" TEXT="ist im Grunde egal &#x27f9; Map mit String-Key">
<icon BUILTIN="button_cancel"/>
<node COLOR="#5b280f" CREATED="1701181099023" ID="ID_655755151" MODIFIED="1701181120346" TEXT="immer noch zu komplisiert">
<icon BUILTIN="stop-sign"/>
</node>
<node COLOR="#435e98" CREATED="1701181139849" ID="ID_138263114" MODIFIED="1701181151504" TEXT="geht noch KISSiger">
<font NAME="SansSerif" SIZE="11"/>
<icon BUILTIN="ksmiletris"/>
</node>
</node>
<node CREATED="1701181154476" ID="ID_1678400125" MODIFIED="1701181190273" TEXT="feste Index-Folge und alles in std::array">
<icon BUILTIN="yes"/>
<node CREATED="1701181210002" ID="ID_1679700560" MODIFIED="1701181218067" TEXT="und zwar als im Header definierte Konstanten"/>
<node CREATED="1701181262856" ID="ID_793524141" MODIFIED="1701181284833" TEXT="STAT_* : Kategorie-Bezeichner (human-readable)"/>
<node CREATED="1701181225838" ID="ID_704708703" MODIFIED="1701181290625" TEXT="KEYS : ein array mit den Kategorie-Bezeichnern"/>
<node CREATED="1701181298668" ID="ID_1143111821" MODIFIED="1701181305790" TEXT="CAT = KEYS.size()"/>
<node CREATED="1701181311114" ID="ID_1052500553" MODIFIED="1701181371657" TEXT="evaluations: ein array mit Klassifikations-&#x3bb;"/>
<node CREATED="1701181338943" ID="ID_1835182207" MODIFIED="1701181366087" TEXT="Statistic::indicators : ein array mit den Indicator-records f&#xfc;r jede Kategorie"/>
</node>
</node>
<node CREATED="1701127237104" ID="ID_627445638" MODIFIED="1701127280398" TEXT="Sub-Objekt...">
<node CREATED="1701127280727" ID="ID_211987609" MODIFIED="1701127280727" TEXT="enth&#xe4;lt einen data-Vector"/>
<node CREATED="1701127286949" ID="ID_113578279" MODIFIED="1701127312993" TEXT="ggfs sp&#xe4;ter weitere Tabellen (MA, lokaler Trend)"/>
<node CREATED="1701127339746" ID="ID_552079211" MODIFIED="1701127349436" TEXT="sowie feste Datenfelder f&#xfc;r die Kennzahlen"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1701127401298" ID="ID_1356798063" MODIFIED="1701140125631" TEXT="Berechnung-1">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1701127401298" ID="ID_1356798063" MODIFIED="1701184821866" TEXT="Berechnung-1">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1701127405705" ID="ID_1717640247" MODIFIED="1701140156044" TEXT="ein Datenpunkt + Breite">
<icon BUILTIN="button_ok"/>
</node>
@ -99589,6 +99605,10 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node COLOR="#338800" CREATED="1701127520281" ID="ID_327297411" MODIFIED="1701140158553" TEXT="Abschlu&#xdf;: Gesamtzahl &#x27fc; &#x2205;">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1701184912655" ID="ID_283973311" MODIFIED="1701184946768" TEXT="Zerlegung in Teilgraphen ber&#xfc;cksichtigen">
<linktarget COLOR="#7327b4" DESTINATION="ID_283973311" ENDARROW="Default" ENDINCLINATION="-138;8;" ID="Arrow_ID_468448911" SOURCE="ID_1190320888" STARTARROW="None" STARTINCLINATION="124;-10;"/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1701127540653" ID="ID_838754026" MODIFIED="1701127562922" TEXT="Berechnung-2">
<icon BUILTIN="hourglass"/>
@ -99612,11 +99632,21 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1701016792372" ID="ID_1251453714" MODIFIED="1701016798575" TEXT="Darstellung">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1701125319870" ID="ID_1457245227" MODIFIED="1701125329516" TEXT="Statistik-Report bereitstellen">
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1701016792372" ID="ID_1251453714" MODIFIED="1701184833970" TEXT="Darstellung">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1701125319870" ID="ID_1457245227" MODIFIED="1701184853119" TEXT="Statistik-Report bereitstellen">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1701184854447" ID="ID_1823077805" MODIFIED="1701184862006" TEXT="Auswertungen pro Kategorie">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1701184862856" ID="ID_85653289" MODIFIED="1701184866502" TEXT="Gesamtsummen">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1701184867453" ID="ID_1190320888" MODIFIED="1701184954043" TEXT="Teilgraphen ber&#xfc;cksichtigen">
<arrowlink COLOR="#7327b4" DESTINATION="ID_283973311" ENDARROW="Default" ENDINCLINATION="-138;8;" ID="Arrow_ID_468448911" STARTARROW="None" STARTINCLINATION="124;-10;"/>
<icon BUILTIN="flag-pink"/>
</node>
</node>
</node>
</node>
</node>