ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
shapley.cpp File Reference

SQL functions for Shapley and Banzhaf power-index computation. More...

#include "postgres.h"
#include "fmgr.h"
#include "catalog/pg_type.h"
#include "utils/uuid.h"
#include "executor/spi.h"
#include "provsql_shmem.h"
#include "provsql_utils.h"
#include "c_cpp_compatibility.h"
#include "BooleanCircuit.h"
#include "Circuit.hpp"
#include "provsql_utils_cpp.h"
#include "dDNNFTreeDecompositionBuilder.h"
#include "CircuitFromMMap.h"
#include <fstream>
Include dependency graph for shapley.cpp:

Go to the source code of this file.

Functions

static double shapley_internal (pg_uuid_t token, pg_uuid_t variable, const std::string &method, const std::string &args, bool banzhaf)
 Core implementation for Shapley and Banzhaf index computation.
 
Datum shapley (PG_FUNCTION_ARGS)
 PostgreSQL-callable wrapper for shapley() and banzhaf().
 
Datum shapley_all_vars (PG_FUNCTION_ARGS)
 PostgreSQL-callable wrapper for shapley_all_vars() set-returning function.
 

Detailed Description

SQL functions for Shapley and Banzhaf power-index computation.

Implements two SQL-callable functions:

  • provsql.shapley(token, variable, method, args): Shapley value of a given input gate (tuple) in the provenance circuit rooted at token.
  • provsql.shapley_all_vars(token, method, args): Shapley values for all input gates simultaneously (more efficient than calling shapley() once per variable).

The method argument selects the computation algorithm:

  • "tree-decomposition": exact, polynomial if treewidth ≤ MAX_TREEWIDTH.
  • "monte-carlo": approximate via random sampling.
  • Any external d-DNNF compiler name ("d4", "c2d", etc.).

Banzhaf power index computation is exposed via the same internal helper (shapley_internal with banzhaf=true), called by the provsql.banzhaf() SQL function defined in the SQL layer.

Definition in file shapley.cpp.

Function Documentation

◆ shapley()

Datum shapley ( PG_FUNCTION_ARGS  )

PostgreSQL-callable wrapper for shapley() and banzhaf().

Definition at line 81 of file shapley.cpp.

Here is the call graph for this function:

◆ shapley_all_vars()

Datum shapley_all_vars ( PG_FUNCTION_ARGS  )

PostgreSQL-callable wrapper for shapley_all_vars() set-returning function.

Definition at line 118 of file shapley.cpp.

Here is the call graph for this function:

◆ shapley_internal()

static double shapley_internal ( pg_uuid_t  token,
pg_uuid_t  variable,
const std::string &  method,
const std::string &  args,
bool  banzhaf 
)
static

Core implementation for Shapley and Banzhaf index computation.

Parameters
tokenUUID of the root provenance gate.
variableUUID of the input gate whose index is to be computed.
methodd-DNNF compilation method.
argsAdditional arguments for the compilation method.
banzhafIf true, compute the Banzhaf index instead of Shapley.
Returns
The Shapley (or Banzhaf) value of variable.

Definition at line 53 of file shapley.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: