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:
|
||||
|
||||
def __init__(self, inputLayerSize, *layerSizes):
|
||||
if type(inputLayerSize) != int:
|
||||
raise TypeError("The input layer size must be an int!")
|
||||
|
||||
self.weights = []
|
||||
self.inputLayerSize = inputLayerSize
|
||||
self.oldLayerSize = inputLayerSize
|
||||
@ -10,40 +13,26 @@ class network:
|
||||
self.weights.append( np.random.default_rng(42).random((self.oldLayerSize, layerSize)) )
|
||||
self.oldLayerSize = layerSize
|
||||
self.biases = [[0]*layerSize for layerSize in layerSizes]
|
||||
self.weights = np.array(self.weights)
|
||||
self.biases = np.array(self.biases)
|
||||
self.weights = np.array(self.weights, dtype=object)
|
||||
self.biases = np.array(self.biases, dtype=object)
|
||||
|
||||
def reLu(value):
|
||||
return max(0, value)
|
||||
|
||||
def process(self, input):
|
||||
if type(input) != np.ndarray:
|
||||
print("non")
|
||||
raise TypeError("The input must be a vector!")
|
||||
if input.size != self.inputLayerSize:
|
||||
print("vite")
|
||||
raise ValueError("The input vector has the wrong size!")
|
||||
if input.dtype != np.float64:
|
||||
print("aaa")
|
||||
for layer, bias in zip(self.weights, self.biases):
|
||||
print("---------------------")
|
||||
print(input)
|
||||
print(layer)
|
||||
print(bias)
|
||||
input = np.matmul(input, layer)
|
||||
raise TypeError("The input vector must contain floats!")
|
||||
|
||||
for layerWeights, bias in zip(self.weights, self.biases):
|
||||
input = np.matmul(input, layerWeights)
|
||||
input = np.add(input, bias)
|
||||
#reLu application
|
||||
with np.nditer(input, op_flags=['readwrite']) as layer:
|
||||
for neuron in layer:
|
||||
neuron = network.reLu(neuron)
|
||||
|
||||
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