Skip to content

Commit

Permalink
Resolve build warnings, add trailing newlines, fix markdown (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattxwang committed Jul 13, 2023
1 parent 9edf93e commit a3ad51b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ path = "src/lib.rs"
[dependencies]
clap = { version = "3.2.14", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.82"
serde_json = "1.0.82"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

A small library for importing Bayesian networks into Rust

# Usage
## Usage

## Converter
### Converter

The `converter` directory contains a `bif_to_json.py` file that converts an
arbitrary `bif` file into the JSON format that can be read by the library.
arbitrary `bif` file into the JSON format that can be read by the library.
To use it, first install the `pgmpy` python package. Then, it can be invoked as:

```
python bif_to_json.py input.bif > output.json
```

## rsgm
### rsgm

The RSGM library contains tools for parsing and manipulating Bayesian networks
from a JSON representation.
13 changes: 6 additions & 7 deletions src/bayesian_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::collections::{HashMap, BTreeMap};

use serde::{Serialize, Deserialize};
use serde_json::{Result, Value};

/// maps each variable name to a CPT table
/// - rows are indexed by the current variable's possible values
Expand All @@ -23,19 +22,19 @@ use serde_json::{Result, Value};
/// says Pr(c=c1 | a=a1, b=b1) = 0.1
/// Pr(c=c1 | a=a2, b=b1) = 0.4
/// Pr(c=c1 | a=a1, b=b3) = 0.3
type cpt = HashMap<String, Vec<Vec<f64>>>;
type CPT = HashMap<String, Vec<Vec<f64>>>;
/// maps each variable name to a list of that variable's possible values
type states = HashMap<String, Vec<String>>;
type States = HashMap<String, Vec<String>>;
/// maps each variable name to a list of that variable's parents
type parents = HashMap<String, Vec<String>>;
type Parents = HashMap<String, Vec<String>>;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct BayesianNetwork {
network: String,
variables: Vec<String>,
cpts: cpt,
states: states,
parents: parents
cpts: CPT,
states: States,
parents: Parents
}

impl BayesianNetwork {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod bayesian_network;
pub mod bayesian_network;
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate serde;
extern crate clap;
extern crate serde_json;
use std::{fs, collections::HashMap};
use std::{fs};

use clap::Parser;

Expand All @@ -22,7 +22,7 @@ fn main() {
let network = bayesian_network::BayesianNetwork::from_string(&str);
println!("bn: {:?}", network);
// println!("topo sort: {:?}", network.topological_sort());
// let parent_assgn = HashMap::from([ (String::from("Erk"), String::from("HIGH")),
// let parent_assgn = HashMap::from([ (String::from("Erk"), String::from("HIGH")),
// (String::from("PKA"), String::from("HIGH")) ]);
// println!("conditional prob: {:?}", network.get_conditional_prob(&String::from("Akt"), &String::from("LOW"), &parent_assgn));
}

0 comments on commit a3ad51b

Please sign in to comment.