pub struct ArchitectureKnowledgeGraph { /* private fields */ }Expand description
A graph of architectures and their relationships.
Stores nodes contiguously in insertion order and indexes outgoing edges
via an adjacency map for O(deg) neighbour lookups. The map is
reconstructed from the edge list whenever the graph is loaded from JSON.
Implementations§
Source§impl ArchitectureKnowledgeGraph
impl ArchitectureKnowledgeGraph
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Construct an empty graph pre-allocating storage for n nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges in the graph.
Sourcepub fn add_architecture(
&mut self,
arch_id: impl Into<String>,
embedding: Vec<f64>,
domain: impl Into<String>,
) -> NodeId
pub fn add_architecture( &mut self, arch_id: impl Into<String>, embedding: Vec<f64>, domain: impl Into<String>, ) -> NodeId
Insert a new architecture into the graph and return its NodeId.
Sourcepub fn set_performance(
&mut self,
node: NodeId,
record: PerformanceRecord,
) -> Result<()>
pub fn set_performance( &mut self, node: NodeId, record: PerformanceRecord, ) -> Result<()>
Attach a performance record to an existing node.
Sourcepub fn add_edge(
&mut self,
from: NodeId,
to: NodeId,
relation: RelationType,
weight: f64,
) -> Result<()>
pub fn add_edge( &mut self, from: NodeId, to: NodeId, relation: RelationType, weight: f64, ) -> Result<()>
Add a typed weighted edge between two existing nodes.
Rejects edges that reference unknown nodes, that carry a non-finite
weight, or whose weight is outside [-1, 1] for Similar edges.
Sourcepub fn node(&self, id: NodeId) -> Option<&ArchKnowledgeNode>
pub fn node(&self, id: NodeId) -> Option<&ArchKnowledgeNode>
Borrow a node by id (returns None if it does not exist).
Sourcepub fn nodes(&self) -> &[ArchKnowledgeNode]
pub fn nodes(&self) -> &[ArchKnowledgeNode]
Borrow all nodes in insertion order.
Sourcepub fn neighbors(&self, id: NodeId) -> Vec<(NodeId, RelationType, f64)>
pub fn neighbors(&self, id: NodeId) -> Vec<(NodeId, RelationType, f64)>
Outgoing neighbours of id, returned as (target, relation, weight).
Returns an empty vector for nodes with no outgoing edges or for unknown ids.
Sourcepub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
pub fn cosine_similarity(a: &[f64], b: &[f64]) -> f64
Cosine similarity between two vectors.
Returns 0.0 when either vector is the zero vector, when the lengths
differ, or when any element is non-finite. This is safer than
returning NaN for downstream ranking code.
Sourcepub fn find_similar(
&self,
query_embedding: &[f64],
k: usize,
) -> Vec<(NodeId, f64)>
pub fn find_similar( &self, query_embedding: &[f64], k: usize, ) -> Vec<(NodeId, f64)>
Top-k nodes by cosine similarity to query_embedding, descending.
Nodes whose embeddings are not comparable (mismatched length or
zero-norm) are silently skipped. If k is zero or the graph is
empty, returns an empty vector.
Sourcepub fn auto_add_similar_edges(&mut self, threshold: f64) -> usize
pub fn auto_add_similar_edges(&mut self, threshold: f64) -> usize
Add Similar edges between every distinct pair of nodes whose
cosine similarity meets threshold. Returns the number of edges
added.
Only one directed edge (i -> j) with i < j is added per pair to
avoid duplicates and self-loops. Edges are skipped when an identical
(from, to, Similar) triple already exists.
Sourcepub fn propagate_knowledge(
&self,
start: NodeId,
decay: f64,
depth: usize,
) -> Result<HashMap<NodeId, f64>>
pub fn propagate_knowledge( &self, start: NodeId, decay: f64, depth: usize, ) -> Result<HashMap<NodeId, f64>>
Random-walk-with-restart from start.
At each of depth iterations every node redistributes decay × score
to its outgoing neighbours (weighted by |weight| and normalised to
sum to one). The remaining 1 - decay mass restarts at start.
Dangling nodes — those without outgoing edges — return all their
mass to start, and groups of neighbours whose weights sum to zero
share the mass uniformly.
Sourcepub fn extract_top_k_transferable(
&self,
target_domain: &str,
query_embedding: &[f64],
k: usize,
) -> Vec<(NodeId, f64)>
pub fn extract_top_k_transferable( &self, target_domain: &str, query_embedding: &[f64], k: usize, ) -> Vec<(NodeId, f64)>
Find up to k transferable architectures for target_domain.
A node is considered transferable if its own domain matches
target_domain, or if any of its outgoing Transfers edges points
to a node whose domain matches, or if it is itself the target of a
Transfers edge from a node whose domain matches. Among the
transferable nodes, the top-k by cosine similarity to
query_embedding are returned (descending).
Trait Implementations§
Source§impl Clone for ArchitectureKnowledgeGraph
impl Clone for ArchitectureKnowledgeGraph
Source§impl Debug for ArchitectureKnowledgeGraph
impl Debug for ArchitectureKnowledgeGraph
Source§impl Default for ArchitectureKnowledgeGraph
impl Default for ArchitectureKnowledgeGraph
Source§impl<'de> Deserialize<'de> for ArchitectureKnowledgeGraph
impl<'de> Deserialize<'de> for ArchitectureKnowledgeGraph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ArchitectureKnowledgeGraph
impl RefUnwindSafe for ArchitectureKnowledgeGraph
impl Send for ArchitectureKnowledgeGraph
impl Sync for ArchitectureKnowledgeGraph
impl Unpin for ArchitectureKnowledgeGraph
impl UnsafeUnpin for ArchitectureKnowledgeGraph
impl UnwindSafe for ArchitectureKnowledgeGraph
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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 more