A Rust library for performing zero-lookahead belief propagation on bipartite graphs with noisy-OR models, optimized for large-scale biological data analysis.
This repository contains:
src/: The core Rust code implementing belief propagation algorithms.benchmark_code/: Example code for benchmarking the library's performance.input_data/: Sample GraphML files for testing and demonstration.
- Zero-lookahead belief propagation for factor graphs
- Convolution tree optimization for high-degree nodes
- Support for noisy-OR factor tables and prior beliefs
In your Cargo.toml:
[dependencies]
nori_inference = "1.0.0"Clone the repository, then point to it from your Cargo.toml:
git clone <repository-url>[dependencies]
nori_inference = { path = "../NORI" }The benchmark_code/ crate provides an example benchmark that executes NORI over several parameter combinations.
From the repository root:
cd benchmark_code
cargo run --releaseThe benchmark reads the GraphML file at ../input_data/iPRG2016/peptide_protein_B.graphml and prints progress information for each parameter combination.
use nori::{load_factor_graph, zero_lookahead_bp_from_graph};
let graphs = load_factor_graph(graphml_string)?;
let result = zero_lookahead_bp_from_graph(&mut graphs, alpha, beta, regularized, prior, max_iter, tolerance)?;graphs: Mutable reference to a vector ofCTFactorGraphobjects (loaded viaload_factor_graph).alpha:f32- Noisy-OR alpha parameter (probability of correct detection, e.g., 0.9).beta:f32- Noisy-OR beta parameter (noise level, e.g., 0.1).regularized:bool- Iftrue, regularizes factor tables to penalize high-degree nodes.prior:f32- Prior probability for output nodes (e.g., 0.5 for uniform).max_iter:Option<u32>- Maximum iterations (default 10,000 ifNone).tolerance:Option<f32>- Convergence tolerance for messages (default 0.006 ifNone).
The function returns a CSV string with columns: [node_name, belief_array].
Graphs are provided as GraphML strings representing a bipartite graph with input and output nodes, and edges indicating noisy-OR relationships.
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns">
<key id="type" for="node"/>
<key id="belief" for="node"/>
<graph edgedefault="undirected">
<node id="input_1">
<data key="type">input</data>
<data key="belief">[0.001, 0.999]</data>
</node>
<node id="output_1">
<data key="type">output</data>
</node>
<edge source="input_1" target="output_1"/>
</graph>
</graphml>- Nodes:
inputnodes have an ID and initial belief probabilities[P(not_present), P(present)].outputnodes have an ID and no belief (priors set via thepriorparameter).
- Edges: Undirected edges connect proteins to peptides they may produce.