legere corrections
This commit is contained in:
parent
47e31258cf
commit
b844d10347
0
sobek/__init.py__
Normal file
0
sobek/__init.py__
Normal file
@ -3,6 +3,9 @@ import numpy as np
|
|||||||
class network:
|
class network:
|
||||||
|
|
||||||
def __init__(self, inputLayerSize, *layerSizes):
|
def __init__(self, inputLayerSize, *layerSizes):
|
||||||
|
if type(inputLayerSize) != int:
|
||||||
|
raise TypeError("The input layer size must be an int!")
|
||||||
|
|
||||||
self.weights = []
|
self.weights = []
|
||||||
self.inputLayerSize = inputLayerSize
|
self.inputLayerSize = inputLayerSize
|
||||||
self.oldLayerSize = inputLayerSize
|
self.oldLayerSize = inputLayerSize
|
||||||
@ -10,40 +13,26 @@ class network:
|
|||||||
self.weights.append( np.random.default_rng(42).random((self.oldLayerSize, layerSize)) )
|
self.weights.append( np.random.default_rng(42).random((self.oldLayerSize, layerSize)) )
|
||||||
self.oldLayerSize = layerSize
|
self.oldLayerSize = layerSize
|
||||||
self.biases = [[0]*layerSize for layerSize in layerSizes]
|
self.biases = [[0]*layerSize for layerSize in layerSizes]
|
||||||
self.weights = np.array(self.weights)
|
self.weights = np.array(self.weights, dtype=object)
|
||||||
self.biases = np.array(self.biases)
|
self.biases = np.array(self.biases, dtype=object)
|
||||||
|
|
||||||
def reLu(value):
|
def reLu(value):
|
||||||
return max(0, value)
|
return max(0, value)
|
||||||
|
|
||||||
def process(self, input):
|
def process(self, input):
|
||||||
if type(input) != np.ndarray:
|
if type(input) != np.ndarray:
|
||||||
print("non")
|
raise TypeError("The input must be a vector!")
|
||||||
if input.size != self.inputLayerSize:
|
if input.size != self.inputLayerSize:
|
||||||
print("vite")
|
raise ValueError("The input vector has the wrong size!")
|
||||||
if input.dtype != np.float64:
|
if input.dtype != np.float64:
|
||||||
print("aaa")
|
raise TypeError("The input vector must contain floats!")
|
||||||
for layer, bias in zip(self.weights, self.biases):
|
|
||||||
print("---------------------")
|
for layerWeights, bias in zip(self.weights, self.biases):
|
||||||
print(input)
|
input = np.matmul(input, layerWeights)
|
||||||
print(layer)
|
|
||||||
print(bias)
|
|
||||||
input = np.matmul(input, layer)
|
|
||||||
input = np.add(input, bias)
|
input = np.add(input, bias)
|
||||||
|
#reLu application
|
||||||
with np.nditer(input, op_flags=['readwrite']) as layer:
|
with np.nditer(input, op_flags=['readwrite']) as layer:
|
||||||
for neuron in layer:
|
for neuron in layer:
|
||||||
neuron = network.reLu(neuron)
|
neuron = network.reLu(neuron)
|
||||||
|
|
||||||
return input
|
return input
|
||||||
|
|
||||||
|
|
||||||
test = network(16, 16, 8, 4)
|
|
||||||
|
|
||||||
for y in test.weights:
|
|
||||||
print(y, end="\n\n")
|
|
||||||
|
|
||||||
for y in test.biases:
|
|
||||||
print(y, end="\n\n")
|
|
||||||
|
|
||||||
print(network.reLu(8))
|
|
||||||
|
|
||||||
print(test.process(np.random.default_rng(42).random((16))))
|
|
14
test.py
Normal file
14
test.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import numpy as np
|
||||||
|
from sobek.network import network
|
||||||
|
|
||||||
|
test = network(16, 16, 8, 4)
|
||||||
|
"""
|
||||||
|
for y in test.weights:
|
||||||
|
print(y, end="\n\n")
|
||||||
|
|
||||||
|
for y in test.biases:
|
||||||
|
print(y, end="\n\n")"""
|
||||||
|
|
||||||
|
print(network.reLu(8))
|
||||||
|
|
||||||
|
print(test.process(np.random.default_rng(42).random((16))))
|
Loading…
Reference in New Issue
Block a user