pub struct Graph {
pub node_features: Array2<f64>,
pub edge_indices: Array2<usize>,
pub edge_features: Option<Array2<f64>>,
pub graph_features: Option<Array1<f64>>,
pub num_nodes: usize,
pub num_edges: usize,
}Expand description
Graph data structure
Fields§
§node_features: Array2<f64>Node features
edge_indices: Array2<usize>Edge indices (source, target pairs)
edge_features: Option<Array2<f64>>Edge features
graph_features: Option<Array1<f64>>Graph-level features
num_nodes: usizeNumber of nodes
num_edges: usizeNumber of edges
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new(
node_features: Array2<f64>,
edge_indices: Array2<usize>,
edge_features: Option<Array2<f64>>,
graph_features: Option<Array1<f64>>,
) -> Self
pub fn new( node_features: Array2<f64>, edge_indices: Array2<usize>, edge_features: Option<Array2<f64>>, graph_features: Option<Array1<f64>>, ) -> Self
Create a new graph
Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 567)
546fn generate_complex_graphs(num_graphs: usize) -> Result<Vec<Graph>> {
547 let mut graphs = Vec::new();
548
549 for graph_idx in 0..num_graphs {
550 let num_nodes = 10 + graph_idx % 20; // 10-30 nodes
551 let num_edges = num_nodes * 2; // Sparse graphs
552
553 // Generate node features
554 let node_features = Array2::from_shape_fn((num_nodes, 64), |(i, j)| {
555 let node_factor = i as f64 * 0.1;
556 let feature_factor = j as f64 * 0.05;
557 fastrand::f64().mul_add(0.1, (node_factor + feature_factor).sin())
558 });
559
560 // Generate edge indices (ensuring valid connections)
561 let mut edge_indices = Array2::zeros((2, num_edges));
562 for edge in 0..num_edges {
563 edge_indices[[0, edge]] = fastrand::usize(..num_nodes);
564 edge_indices[[1, edge]] = fastrand::usize(..num_nodes);
565 }
566
567 let graph = Graph::new(node_features, edge_indices, None, None);
568 graphs.push(graph);
569 }
570
571 Ok(graphs)
572}
573
574fn extract_pde_features_with_qpinn() -> Result<Array1<f64>> {
575 // Simulate PDE feature extraction
576 Ok(Array1::from_shape_fn(20, |i| (i as f64 * 0.2).exp() * 0.1))
577}
578
579fn process_temporal_with_qrc(features: &Array1<f64>) -> Result<Array2<f64>> {
580 // Simulate temporal processing
581 let temporal_length = 10;
582 Ok(Array2::from_shape_fn(
583 (temporal_length, features.len()),
584 |(t, f)| features[f] * (t as f64 * 0.1).cos(),
585 ))
586}
587
588fn create_relationship_graph(patterns: &Array2<f64>) -> Result<Graph> {
589 let num_nodes = patterns.nrows();
590 let node_features = patterns.clone();
591
592 // Create edges based on similarity
593 let mut edges = Vec::new();
594 for i in 0..num_nodes {
595 for j in i + 1..num_nodes {
596 if fastrand::f64() < 0.3 {
597 // 30% connection probability
598 edges.push(i);
599 edges.push(j);
600 }
601 }
602 }
603
604 let num_edges = edges.len() / 2;
605 let edge_indices = Array2::from_shape_vec((2, num_edges), edges)?;
606
607 Ok(Graph::new(node_features, edge_indices, None, None))
608}Sourcepub fn get_neighbors(&self, node: usize) -> Vec<usize>
pub fn get_neighbors(&self, node: usize) -> Vec<usize>
Get neighbors of a node
Sourcepub fn get_adjacency_matrix(&self) -> Array2<f64>
pub fn get_adjacency_matrix(&self) -> Array2<f64>
Get adjacency matrix
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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.