Documentation
¶
Overview ¶
Package readwrite provides readers and writers for probabilistic model file formats: BIF, XMLBIF, NET, UAI, XDSL, PomdpX, XBN, CSV, JSON, and datascience-native XML.
Index ¶
- Constants
- func ReadBIF(r io.Reader) (*models.BayesianNetwork, error)
- func ReadCSVCPD(r io.Reader) (*factors.TabularCPD, error)
- func ReadCSVStructure(r io.Reader) (*models.BayesianNetwork, error)
- func ReadJSON(r io.Reader) (*models.BayesianNetwork, error)
- func ReadJSONStructure(r io.Reader) (*models.BayesianNetwork, error)
- func ReadJSONStructureWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func ReadJSONWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func ReadNET(r io.Reader) (*models.BayesianNetwork, error)
- func ReadParquet(filename string) (*tabgo.DataFrame, error)
- func ReadPomdpX(r io.Reader) (*models.BayesianNetwork, error)
- func ReadPomdpXWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func ReadUAI(r io.Reader) (*models.BayesianNetwork, error)
- func ReadXBN(r io.Reader) (*models.BayesianNetwork, error)
- func ReadXBNWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func ReadXDSL(r io.Reader) (*models.BayesianNetwork, error)
- func ReadXDSLWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func ReadXLSX(filename string) (*models.BayesianNetwork, error)
- func ReadXMLBIF(r io.Reader) (*models.BayesianNetwork, error)
- func ReadXMLBIFWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func ReadXMLNative(r io.Reader) (*models.BayesianNetwork, error)
- func ReadXMLNativeWithLimit(r io.Reader, maxBytes int) (*models.BayesianNetwork, error)
- func WriteBIF(w io.Writer, bn *models.BayesianNetwork) error
- func WriteCSVCPD(w io.Writer, cpd *factors.TabularCPD) error
- func WriteCSVStructure(w io.Writer, bn *models.BayesianNetwork) error
- func WriteJSON(w io.Writer, bn *models.BayesianNetwork) error
- func WriteNET(w io.Writer, bn *models.BayesianNetwork) error
- func WriteParquet(filename string, df *tabgo.DataFrame) error
- func WritePomdpX(w io.Writer, bn *models.BayesianNetwork) error
- func WriteUAI(w io.Writer, bn *models.BayesianNetwork) error
- func WriteXBN(w io.Writer, bn *models.BayesianNetwork) error
- func WriteXDSL(w io.Writer, bn *models.BayesianNetwork) error
- func WriteXLSX(filename string, bn *models.BayesianNetwork) error
- func WriteXMLBIF(w io.Writer, bn *models.BayesianNetwork) error
- func WriteXMLNative(w io.Writer, bn *models.BayesianNetwork) error
Constants ¶
const MaxInputSize = 1 << 20 // 1 MB
MaxInputSize is the default maximum number of bytes accepted by any reader in this package. Inputs exceeding this limit are rejected to prevent denial-of-service via oversized or maliciously crafted files (e.g., XML bombs). Use the *WithLimit variants (e.g., ReadXMLBIFWithLimit) for larger models.
Variables ¶
This section is empty.
Functions ¶
func ReadBIF ¶
func ReadBIF(r io.Reader) (*models.BayesianNetwork, error)
ReadBIF parses a BIF (Bayesian Interchange Format) file and returns a BayesianNetwork. It handles network, variable, and probability blocks. Lines containing // comments have the comment portion stripped.
func ReadCSVCPD ¶
func ReadCSVCPD(r io.Reader) (*factors.TabularCPD, error)
ReadCSVCPD reads a CPD from a CSV table.
Format:
- Row 0 (header): first cell is the variable name, remaining cells are parent configuration labels (or empty for unconditional).
- Row 1..N: first cell is the state name, remaining cells are probabilities.
For an unconditional CPD (no parents), the header has one cell and each data row has two cells (state, probability).
For a conditional CPD, parent configurations are encoded as "Parent1=state,Parent2=state" in the header cells.
func ReadCSVStructure ¶
func ReadCSVStructure(r io.Reader) (*models.BayesianNetwork, error)
ReadCSVStructure reads an edge-list CSV with "from,to" columns and creates a BayesianNetwork containing only structure (nodes and edges, no CPDs). The first row must be a header with fields "from" and "to" (case-insensitive).
func ReadJSON ¶
func ReadJSON(r io.Reader) (*models.BayesianNetwork, error)
ReadJSON parses a JSON file and returns a fully populated BayesianNetwork, including nodes, edges, states, and CPDs.
func ReadJSONStructure ¶
func ReadJSONStructure(r io.Reader) (*models.BayesianNetwork, error)
ReadJSONStructure parses a JSON file and returns a BayesianNetwork with structure only (nodes, edges, states). CPDs in the JSON are ignored.
func ReadJSONStructureWithLimit ¶ added in v0.1.1
ReadJSONStructureWithLimit is like ReadJSONStructure but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func ReadJSONWithLimit ¶ added in v0.1.1
ReadJSONWithLimit is like ReadJSON but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func ReadNET ¶
func ReadNET(r io.Reader) (*models.BayesianNetwork, error)
ReadNET parses a Hugin NET format file and returns a BayesianNetwork. NET format uses: node X { states = ("s0" "s1"); } and potential (X | Y) { data = ((0.3 0.7)(0.8 0.2)); }
func ReadParquet ¶
ReadParquet reads a DataFrame from a Parquet file. Parquet binary format support is not yet implemented. Use CSV instead.
func ReadPomdpX ¶
func ReadPomdpX(r io.Reader) (*models.BayesianNetwork, error)
ReadPomdpX parses a PomdpX format file and returns a BayesianNetwork. Supports full Variable definitions with ValueEnum, InitialStateBelief for unconditional CPDs, and StateTransitionFunction for conditional CPDs with parent references via Entry instance/probability pairs.
func ReadPomdpXWithLimit ¶ added in v0.1.1
ReadPomdpXWithLimit is like ReadPomdpX but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func ReadXBN ¶
func ReadXBN(r io.Reader) (*models.BayesianNetwork, error)
ReadXBN parses a Microsoft XBN format file and returns a BayesianNetwork. Supports full NODELIST with STATENAME elements, ARCLIST with parent/child arcs, and DISTRIBS with DIST elements containing CONDSET/CONDELEM for parent references and DPIS/DPI with INDEXES attributes for conditional probability distributions.
func ReadXBNWithLimit ¶ added in v0.1.1
ReadXBNWithLimit is like ReadXBN but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func ReadXDSL ¶
func ReadXDSL(r io.Reader) (*models.BayesianNetwork, error)
ReadXDSL parses a GeNIe XDSL format file and returns a BayesianNetwork.
func ReadXDSLWithLimit ¶ added in v0.1.1
ReadXDSLWithLimit is like ReadXDSL but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func ReadXLSX ¶
func ReadXLSX(filename string) (*models.BayesianNetwork, error)
ReadXLSX reads a BayesianNetwork from an XLSX file. XLSX support requires third-party ZIP/XML parsing libraries and is not yet implemented. Use JSON or CSV formats instead.
func ReadXMLBIF ¶
func ReadXMLBIF(r io.Reader) (*models.BayesianNetwork, error)
ReadXMLBIF parses an XMLBIF format file and returns a BayesianNetwork.
func ReadXMLBIFWithLimit ¶ added in v0.1.1
ReadXMLBIFWithLimit is like ReadXMLBIF but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func ReadXMLNative ¶
func ReadXMLNative(r io.Reader) (*models.BayesianNetwork, error)
ReadXMLNative parses a datascience-native XML file and returns a BayesianNetwork.
func ReadXMLNativeWithLimit ¶ added in v0.1.1
ReadXMLNativeWithLimit is like ReadXMLNative but accepts a custom maximum input size in bytes. Use this for models larger than MaxInputSize (1 MB).
func WriteBIF ¶
func WriteBIF(w io.Writer, bn *models.BayesianNetwork) error
WriteBIF serializes a BayesianNetwork to BIF (Bayesian Interchange Format). Variable blocks are written in the order returned by bn.Nodes(), followed by probability blocks in the same order.
func WriteCSVCPD ¶
func WriteCSVCPD(w io.Writer, cpd *factors.TabularCPD) error
WriteCSVCPD writes a TabularCPD as a CSV table.
The output has a header row with the variable name in the first cell, followed by parent configuration labels (or a single empty-label column for unconditional). Each subsequent row is a child state followed by its probability values.
func WriteCSVStructure ¶
func WriteCSVStructure(w io.Writer, bn *models.BayesianNetwork) error
WriteCSVStructure writes the edge list of a BayesianNetwork as CSV with columns "from,to".
func WriteJSON ¶
func WriteJSON(w io.Writer, bn *models.BayesianNetwork) error
WriteJSON serializes a BayesianNetwork to JSON format.
func WriteNET ¶
func WriteNET(w io.Writer, bn *models.BayesianNetwork) error
WriteNET serializes a BayesianNetwork to Hugin NET format.
func WriteParquet ¶
WriteParquet writes a DataFrame to a Parquet file. Parquet binary format support is not yet implemented. Use CSV instead.
func WritePomdpX ¶
func WritePomdpX(w io.Writer, bn *models.BayesianNetwork) error
WritePomdpX serializes a BayesianNetwork to PomdpX format with full conditional probability table support. Unconditional distributions are written in InitialStateBelief; conditional distributions are written in StateTransitionFunction with Entry elements containing Instance tags.
func WriteUAI ¶
func WriteUAI(w io.Writer, bn *models.BayesianNetwork) error
WriteUAI serializes a BayesianNetwork to UAI format.
func WriteXBN ¶
func WriteXBN(w io.Writer, bn *models.BayesianNetwork) error
WriteXBN serializes a BayesianNetwork to Microsoft XBN format with full NODELIST (including STATENAME elements), ARCLIST, and DISTRIBS with CONDSET/CONDELEM and DPI elements with INDEXES attributes.
func WriteXDSL ¶
func WriteXDSL(w io.Writer, bn *models.BayesianNetwork) error
WriteXDSL serializes a BayesianNetwork to GeNIe XDSL format.
func WriteXLSX ¶
func WriteXLSX(filename string, bn *models.BayesianNetwork) error
WriteXLSX writes a BayesianNetwork to an XLSX file. XLSX support requires third-party ZIP/XML parsing libraries and is not yet implemented. Use JSON or CSV formats instead.
func WriteXMLBIF ¶
func WriteXMLBIF(w io.Writer, bn *models.BayesianNetwork) error
WriteXMLBIF serializes a BayesianNetwork to XMLBIF format.
func WriteXMLNative ¶
func WriteXMLNative(w io.Writer, bn *models.BayesianNetwork) error
WriteXMLNative serializes a BayesianNetwork to datascience-native XML format.
Types ¶
This section is empty.