-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkolmogorov_arnold_network.py
More file actions
36 lines (27 loc) · 1.06 KB
/
Copy pathkolmogorov_arnold_network.py
File metadata and controls
36 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
def phi(x):
""" A simple nonlinear function used in the network. """
return np.sin(x)
def kolmogorov_arnold_network(x, V, W):
"""
Kolmogorov-Arnold representation of a function.
:param x: Input vector (numpy array).
:param V: Matrix of weights for combining inputs (numpy array).
:param W: Weights for combining single-variable functions (numpy array).
:return: Output of the network (float).
"""
# Apply V to inputs to generate terms for phi
z = np.dot(V, x)
# Apply the nonlinear function phi to each component
phi_z = phi(z)
# Sum up all the transformed components using weights W
output = np.dot(W, phi_z)
return output
# Example input
x = np.array([0.5, -1.2, 0.3])
# Random weights for demonstration (usually needs careful initialization)
V = np.random.rand(3, 3) # 3 inputs, 3 transformed features
W = np.random.rand(3) # Weights for combining the outputs of phi
# Compute the output
output = kolmogorov_arnold_network(x, V, W)
print("Output of the network:", output)