pub struct GraphNeuralNetwork<S = Untrained> { /* private fields */ }Expand description
Graph Neural Network for Structured Output Prediction
A graph neural network implementation for multi-output prediction tasks where the outputs have structural relationships represented as a graph. This method can leverage node features, edge information, and graph topology to make predictions that respect the underlying graph structure.
§Examples
use sklears_multioutput::{GraphNeuralNetwork, MessagePassingVariant, AggregationFunction};
use sklears_core::traits::{Predict, Fit};
// Use SciRS2-Core for arrays and random number generation (SciRS2 Policy)
use scirs2_core::ndarray::array;
// Node features and adjacency matrix
let node_features = array![[1.0, 2.0], [2.0, 3.0], [3.0, 1.0], [4.0, 4.0], [1.0, 3.0]];
let adjacency = array![[0, 1, 1, 0, 0], [1, 0, 1, 1, 0], [1, 1, 0, 0, 1],
[0, 1, 0, 0, 1], [0, 0, 1, 1, 0]];
let node_labels = array![[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1], [1, 0, 0]];
let gnn = GraphNeuralNetwork::new()
.hidden_dim(16)
.num_layers(2)
.message_passing_variant(MessagePassingVariant::GCN)
.aggregation_function(AggregationFunction::Mean);
let trained_gnn = gnn.fit_graph(&adjacency.view(), &node_features.view(), &node_labels).unwrap();
let predictions = trained_gnn.predict_graph(&adjacency.view(), &node_features.view()).unwrap();Implementations§
Source§impl GraphNeuralNetwork<Untrained>
impl GraphNeuralNetwork<Untrained>
Set the hidden dimension
Sourcepub fn num_layers(self, num_layers: usize) -> Self
pub fn num_layers(self, num_layers: usize) -> Self
Set the number of layers
Sourcepub fn message_passing_variant(self, variant: MessagePassingVariant) -> Self
pub fn message_passing_variant(self, variant: MessagePassingVariant) -> Self
Set the message passing variant
Sourcepub fn aggregation_function(self, function: AggregationFunction) -> Self
pub fn aggregation_function(self, function: AggregationFunction) -> Self
Set the aggregation function
Sourcepub fn learning_rate(self, learning_rate: Float) -> Self
pub fn learning_rate(self, learning_rate: Float) -> Self
Set the learning rate
Sourcepub fn dropout_rate(self, dropout_rate: Float) -> Self
pub fn dropout_rate(self, dropout_rate: Float) -> Self
Set the dropout rate
Sourcepub fn random_state(self, random_state: u64) -> Self
pub fn random_state(self, random_state: u64) -> Self
Set random state for reproducible results
Source§impl GraphNeuralNetwork<Untrained>
Fit method for Graph Neural Networks with graph structure
impl GraphNeuralNetwork<Untrained>
Fit method for Graph Neural Networks with graph structure
Sourcepub fn fit_graph(
self,
adjacency: &ArrayView2<'_, i32>,
node_features: &ArrayView2<'_, Float>,
node_labels: &Array2<i32>,
) -> SklResult<GraphNeuralNetwork<GraphNeuralNetworkTrained>>
pub fn fit_graph( self, adjacency: &ArrayView2<'_, i32>, node_features: &ArrayView2<'_, Float>, node_labels: &Array2<i32>, ) -> SklResult<GraphNeuralNetwork<GraphNeuralNetworkTrained>>
Fit the GNN using graph structure, node features, and node labels
Source§impl GraphNeuralNetwork<GraphNeuralNetworkTrained>
impl GraphNeuralNetwork<GraphNeuralNetworkTrained>
Sourcepub fn predict_graph(
&self,
adjacency: &ArrayView2<'_, i32>,
node_features: &ArrayView2<'_, Float>,
) -> SklResult<Array2<i32>>
pub fn predict_graph( &self, adjacency: &ArrayView2<'_, i32>, node_features: &ArrayView2<'_, Float>, ) -> SklResult<Array2<i32>>
Predict node labels using the trained GNN
Get the hidden dimension
Sourcepub fn num_layers(&self) -> usize
pub fn num_layers(&self) -> usize
Get the number of layers
Trait Implementations§
Source§impl<S: Clone> Clone for GraphNeuralNetwork<S>
impl<S: Clone> Clone for GraphNeuralNetwork<S>
Source§fn clone(&self) -> GraphNeuralNetwork<S>
fn clone(&self) -> GraphNeuralNetwork<S>
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<S: Debug> Debug for GraphNeuralNetwork<S>
impl<S: Debug> Debug for GraphNeuralNetwork<S>
Source§impl Default for GraphNeuralNetwork<Untrained>
impl Default for GraphNeuralNetwork<Untrained>
Source§impl Estimator for GraphNeuralNetwork<Untrained>
impl Estimator for GraphNeuralNetwork<Untrained>
Source§type Error = SklearsError
type Error = SklearsError
Error type for the estimator
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Validate estimator configuration with detailed error context
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Check if estimator is compatible with given data dimensions
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Get estimator metadata
Auto Trait Implementations§
impl<S> Freeze for GraphNeuralNetwork<S>where
S: Freeze,
impl<S> RefUnwindSafe for GraphNeuralNetwork<S>where
S: RefUnwindSafe,
impl<S> Send for GraphNeuralNetwork<S>where
S: Send,
impl<S> Sync for GraphNeuralNetwork<S>where
S: Sync,
impl<S> Unpin for GraphNeuralNetwork<S>where
S: Unpin,
impl<S> UnwindSafe for GraphNeuralNetwork<S>where
S: UnwindSafe,
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<T> StableApi for Twhere
T: Estimator,
impl<T> StableApi for Twhere
T: Estimator,
Source§const STABLE_SINCE: &'static str = "0.1.0"
const STABLE_SINCE: &'static str = "0.1.0"
API version this type was stabilized in
Source§const HAS_EXPERIMENTAL_FEATURES: bool = false
const HAS_EXPERIMENTAL_FEATURES: bool = false
Whether this API has any experimental features