1
1
import numpy as np
2
2
3
-
4
3
class RadialBasisFunctionNeuralNetwork :
5
4
"""
6
5
A simple implementation of a Radial Basis Function Neural Network (RBFNN).
@@ -32,11 +31,11 @@ def __init__(self, num_centers: int, spread: float) -> None:
32
31
33
32
def _gaussian_rbf (self , input_vector : np .ndarray , center : np .ndarray ) -> float :
34
33
"""
35
- Calculate the Gaussian radial basis function output for a given input vector and center.
34
+ Calculate Gaussian radial basis function output for input vector and center.
36
35
37
36
Args:
38
- input_vector (np.ndarray): The input vector for which to calculate the RBF output.
39
- center (np.ndarray): The center of the radial basis function.
37
+ input_vector (np.ndarray): Input vector for which to calculate the RBF output.
38
+ center (np.ndarray): Center of the radial basis function.
40
39
41
40
Returns:
42
41
float: The output of the radial basis function evaluated at the input vector.
@@ -48,7 +47,7 @@ def _gaussian_rbf(self, input_vector: np.ndarray, center: np.ndarray) -> float:
48
47
0.1353352832366127
49
48
"""
50
49
return np .exp (
51
- - (np .linalg .norm (input_vector - center ) ** 2 ) / (2 * self .spread ** 2 )
50
+ - (np .linalg .norm (input_vector - center ) ** 2 ) / (2 * self .spread ** 2 )
52
51
)
53
52
54
53
def _compute_rbf_outputs (self , input_data : np .ndarray ) -> np .ndarray :
@@ -59,7 +58,7 @@ def _compute_rbf_outputs(self, input_data: np.ndarray) -> np.ndarray:
59
58
input_data (np.ndarray): Input data matrix (num_samples x num_features).
60
59
61
60
Returns:
62
- np.ndarray: A matrix of shape (num_samples x num_centers) containing the RBF outputs.
61
+ np.ndarray: A matrix of shape (num_samples x num_centers) with RBF outputs.
63
62
64
63
Examples:
65
64
>>> rbf_nn = RadialBasisFunctionNeuralNetwork(num_centers=2, spread=1.0)
@@ -83,7 +82,7 @@ def fit(self, input_data: np.ndarray, target_values: np.ndarray) -> None:
83
82
target_values (np.ndarray): Target values (num_samples x output_dim).
84
83
85
84
Raises:
86
- ValueError: If the number of samples in input_data and target_values do not match.
85
+ ValueError: If number of samples in input_data and target_values not match.
87
86
88
87
Examples:
89
88
>>> rbf_nn = RadialBasisFunctionNeuralNetwork(num_centers=2, spread=1.0)
@@ -136,7 +135,6 @@ def predict(self, input_data: np.ndarray) -> np.ndarray:
136
135
# Example Usage
137
136
if __name__ == "__main__" :
138
137
import doctest
139
-
140
138
doctest .testmod ()
141
139
142
140
# Sample dataset for XOR problem
0 commit comments