pub struct FactorGraph { /* private fields */ }Expand description
Factor graph representation for PGM.
Implementations§
Source§impl FactorGraph
impl FactorGraph
Sourcepub fn add_variable(&mut self, name: String, domain: String)
pub fn add_variable(&mut self, name: String, domain: String)
Add a variable to the graph.
Sourcepub fn add_variable_with_card(
&mut self,
name: String,
domain: String,
cardinality: usize,
)
pub fn add_variable_with_card( &mut self, name: String, domain: String, cardinality: usize, )
Add a variable with specific cardinality.
Sourcepub fn add_factor(&mut self, factor: Factor) -> Result<()>
pub fn add_factor(&mut self, factor: Factor) -> Result<()>
Add a factor to the graph.
Sourcepub fn add_factor_from_predicate(
&mut self,
name: &str,
var_names: &[String],
) -> Result<()>
pub fn add_factor_from_predicate( &mut self, name: &str, var_names: &[String], ) -> Result<()>
Add a factor from predicate name and variables.
Sourcepub fn get_variable(&self, name: &str) -> Option<&VariableNode>
pub fn get_variable(&self, name: &str) -> Option<&VariableNode>
Get variable node.
Sourcepub fn get_factor(&self, id: &str) -> Option<&Factor>
pub fn get_factor(&self, id: &str) -> Option<&Factor>
Get factor by ID.
Sourcepub fn get_factor_by_name(&self, name: &str) -> Option<&Factor>
pub fn get_factor_by_name(&self, name: &str) -> Option<&Factor>
Get factor by name.
Sourcepub fn get_adjacent_factors(&self, var: &str) -> Option<&Vec<String>>
pub fn get_adjacent_factors(&self, var: &str) -> Option<&Vec<String>>
Get factors connected to a variable.
Sourcepub fn get_adjacent_variables(&self, factor_id: &str) -> Option<&Vec<String>>
pub fn get_adjacent_variables(&self, factor_id: &str) -> Option<&Vec<String>>
Get variables connected to a factor.
Sourcepub fn num_variables(&self) -> usize
pub fn num_variables(&self) -> usize
Get number of variables.
Sourcepub fn num_factors(&self) -> usize
pub fn num_factors(&self) -> usize
Get number of factors.
Sourcepub fn variable_names(&self) -> impl Iterator<Item = &String>
pub fn variable_names(&self) -> impl Iterator<Item = &String>
Get all variable names.
Sourcepub fn factor_ids(&self) -> impl Iterator<Item = &String>
pub fn factor_ids(&self) -> impl Iterator<Item = &String>
Get all factor IDs.
Sourcepub fn variables(&self) -> impl Iterator<Item = (&String, &VariableNode)>
pub fn variables(&self) -> impl Iterator<Item = (&String, &VariableNode)>
Get all variables as an iterator.
Sourcepub fn get_all_factors(&self) -> Vec<&Factor>
pub fn get_all_factors(&self) -> Vec<&Factor>
Get all factors as a vector (for external use).
Trait Implementations§
Source§impl Clone for FactorGraph
impl Clone for FactorGraph
Source§fn clone(&self) -> FactorGraph
fn clone(&self) -> FactorGraph
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FactorGraph
impl Debug for FactorGraph
Source§impl Default for FactorGraph
impl Default for FactorGraph
Source§impl QuantRSModelExport for FactorGraph
impl QuantRSModelExport for FactorGraph
Source§fn to_quantrs_model(&self) -> Result<ModelExport>
fn to_quantrs_model(&self) -> Result<ModelExport>
Export the model to a QuantRS-compatible format.
Source§fn model_stats(&self) -> ModelStatistics
fn model_stats(&self) -> ModelStatistics
Get model statistics for QuantRS integration.
Source§impl QuantumAnnealing for FactorGraph
impl QuantumAnnealing for FactorGraph
Source§fn to_qubo(&self) -> Result<QUBOProblem>
fn to_qubo(&self) -> Result<QUBOProblem>
Convert the factor graph to a QUBO (Quadratic Unconstrained Binary Optimization) problem. Read more
Source§fn anneal(&self, config: &AnnealingConfig) -> Result<QuantumSolution>
fn anneal(&self, config: &AnnealingConfig) -> Result<QuantumSolution>
Run quantum annealing to find the optimal assignment. Read more
Source§fn anneal_multiple(
&self,
config: &AnnealingConfig,
num_runs: usize,
) -> Result<QuantumSolution>
fn anneal_multiple( &self, config: &AnnealingConfig, num_runs: usize, ) -> Result<QuantumSolution>
Run multiple annealing runs and return the best solution. Read more
Source§impl QuantumInference for FactorGraph
impl QuantumInference for FactorGraph
Source§fn solve_qaoa(&self, num_layers: usize) -> Result<HashMap<String, usize>>
fn solve_qaoa(&self, num_layers: usize) -> Result<HashMap<String, usize>>
Solve the optimization problem using QAOA (Quantum Approximate Optimization Algorithm). Read more
Auto Trait Implementations§
impl Freeze for FactorGraph
impl RefUnwindSafe for FactorGraph
impl Send for FactorGraph
impl Sync for FactorGraph
impl Unpin for FactorGraph
impl UnwindSafe for FactorGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.