about summary refs log tree commit diff
path: root/var_lib_genenet_bnw
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-12 16:57:28 +0000
committerPjotr <wrk@bosa.lan>2026-11-12 16:57:28 +0000
commit99a92f8060e76da0357a30df746c70081646bd28 (patch)
tree7f66683ea529e6b73b3381642456a0294f44aa34 /var_lib_genenet_bnw
parent84ad4d1e3f96ad45fdf3d72abfbcf516802e4532 (diff)
downloadgn-bnw-main.tar.gz
bin/bnw: headless network learning, and parity with the web application HEAD main
BNW's computation does not need the web application: run.sh drives three C
programs over files in a per-run directory, and everything above that is file
assembly and rendering. bin/bnw does the same pipeline -- network_score, the
k-best search, structure -- in a private working directory, and reports one row
per candidate edge with its posterior and whether it survived the threshold.

The reference for all of it is the running bnw-container, not a memory of it:
its six continuous traits example was run through the web application
(bn_genenet.php -> execute_bn_gom.php) and the resulting files kept as fixtures
in test/golden/. test/parity_check.py compares our continuous_input.txt and
structure_input.txt against those, and the driver's own stdout against the
file. Today: byte-identical, 5 edges.

Four things that run settled, each of which had been guessed wrong or not at
all:

  * continuous_input.txt is header, then a TYPE LINE (1 = continuous, n =
    n-level discrete), then data.  network_score reads the type before the
    data, and the web application's file is one line longer than the matrix
    because of it.  Without the line the first data row shifts and
    network_score segfaults.
  * structure exits with an uninitialised status while writing a correct file.
    The web application ignores the status; the driver now judges it by its
    output and only fails if the file is missing.
  * get_kbest_nets.cc used SGI's <ext/hash_set>, which modern libstdc++ no
    longer has.  It now uses std::unordered_set with an explicit hasher
    (specialising std::hash for a pointer type is not allowed), and build.sh
    compiles the C with -std=gnu89 because the sources predate C99.
  * our run leaves postProbEachEdge.txt with per-edge posteriors; the web
    application's flow leaves none behind, so the posteriors are information
    the endpoint can report that the web app never showed.

Exit codes are part of the contract GN4 will code against: 0 ok, 2 bad input,
3 the computation failed, 77 the binaries are not installed (a conventional
skip, so a test suite can run where BNW is not).

Build output is gitignored. AI plan and status updated in
info_files/gn4-integration-plan.md; README gained a "Headless driver" section.
Diffstat (limited to 'var_lib_genenet_bnw')
-rwxr-xr-xvar_lib_genenet_bnw/build.sh32
-rw-r--r--var_lib_genenet_bnw/k-best/src/get_kbest_nets.cc47
2 files changed, 43 insertions, 36 deletions
diff --git a/var_lib_genenet_bnw/build.sh b/var_lib_genenet_bnw/build.sh
index c2975ff4..4dc345f4 100755
--- a/var_lib_genenet_bnw/build.sh
+++ b/var_lib_genenet_bnw/build.sh
@@ -1,6 +1,32 @@
 #!/bin/bash
-gcc ./localscore/network_score.c $(pkgconf --libs libRmath) -lm -o network_score
-gcc ./print_structure/structure.c -lm -o structure
+# Build the four C/C++ programs the structure-learning pipeline needs.
+#
+# The sources predate C99 and C++11: network_score and structure rely on
+# implicit int and fall off the end of main(), and get_kbest_nets used SGI's
+# <ext/hash_set>.  -std=gnu89 keeps the C compiling on a modern gcc, and
+# get_kbest_nets.cc was ported to std::unordered_set (see the comment at its
+# hash-set block) so no compatibility flag is needed there.
+#
+# network_score needs R's standalone math library:
+#   guix shell rmath-standalone gcc-toolchain -- ./build.sh
+set -e
+CFLAGS=${CFLAGS:--O2 -std=gnu89 -w}
+
+RMATH_PREFIX=${RMATH_PREFIX:-}
+if [ -z "$RMATH_PREFIX" ]; then
+    # ask pkgconf if it is around, else fall back to $R_HOME / the usual names
+    if command -v pkgconf >/dev/null 2>&1; then
+        RMATH_LIBS=$(pkgconf --libs libRmath)
+    fi
+    RMATH_PREFIX=$(dirname "$(dirname "$(command -v R 2>/dev/null || echo /usr/lib/R/bin/R)")")
+fi
+
+gcc $CFLAGS ${RMATH_PREFIX:+-I$RMATH_PREFIX/include} \
+    ./localscore/network_score.c ${RMATH_LIBS:-${RMATH_PREFIX:+-L$RMATH_PREFIX/lib -lRmath}} -lm \
+    -o network_score
+gcc $CFLAGS ./print_structure/structure.c -lm -o structure
 
 cd ./k-best/src/
-sh buildk_poster.sh
+D=${CXX:-g++}
+$D -w -O2 -o get_kbest_parents get_kbest_parents.cc
+$D -w -O2 -o get_kbest_nets get_kbest_nets.cc
diff --git a/var_lib_genenet_bnw/k-best/src/get_kbest_nets.cc b/var_lib_genenet_bnw/k-best/src/get_kbest_nets.cc
index 2ee35265..d0911cf0 100644
--- a/var_lib_genenet_bnw/k-best/src/get_kbest_nets.cc
+++ b/var_lib_genenet_bnw/k-best/src/get_kbest_nets.cc
@@ -16,24 +16,13 @@
 
 
 //HR: Add for hash_set
-#if __GNUC__ < 3 && __GNUC__ >= 2 && __GNUC_MINOR__ >= 95
-# include <hash_set>
-# include <functional>
-# define gnu_namespace std
-#elif __GNUC__ >= 3
-# include <ext/hash_set>
-# if __GNUC_MINOR__ == 0
-# include <functional>
-# define gnu_namespace std
-# else
-# include <ext/functional>
-# define gnu_namespace __gnu_cxx
-# endif
-#else
-# include <hash_set.h>
-# include <functional.h>
-# define gnu_namespace std
-#endif
+// Upstream this was a maze of #ifdefs for <hash_set>/<ext/hash_set>, which
+// C++11 and later dropped.  The set is a std::unordered_set with an explicit
+// hasher; naming the hasher (rather than specialising std::hash for a pointer
+// type, which is not allowed) is the whole portability fix.
+#include <unordered_set>
+#include <functional>
+#define gnu_namespace std
 using namespace gnu_namespace;
 #include <set>
 //
@@ -609,21 +598,13 @@ void insert_vec(list<node>* v,node s, int k){
 
 //===================================================================//
 //HR: Add hash_set to store net_set (i.e. (net, score) pair
-namespace gnu_namespace {
-	
-	template<>
+struct net_set_hash {
+	std::hash<unsigned> hasher_ns;
 
-	struct hash<const net_set*> {
-	
-		hash<unsigned> hasher_ns;
-		
-		size_t operator()(const net_set* ns) const {
-			return hasher_ns((unsigned) roundl(- ns->score*10)); // wrong hash function??
-		}
-
-	}; //end of struct
-
-} //end of namespace
+	size_t operator()(const net_set* ns) const {
+		return hasher_ns((unsigned) roundl(- ns->score*10)); // wrong hash function??
+	}
+}; //end of struct
 
 
 
@@ -635,7 +616,7 @@ struct eqNetScore{
 
 
 
-typedef hash_set<const net_set *, hash<const net_set *>, eqNetScore> NetScoreHashSet;
+typedef std::unordered_set<const net_set *, net_set_hash, eqNetScore> NetScoreHashSet;
 
 NetScoreHashSet knets;