parent
d26c6042a0
commit
ba5662b371
@ -1,29 +1,34 @@ |
|||||||
#!/usr/bin/env python |
#!/usr/bin/env python |
||||||
|
import numpy as np |
||||||
from lib.func import AIlib as ai |
from lib.func import AIlib as ai |
||||||
|
|
||||||
class rgb(object): |
class rgb(object): |
||||||
def __init__(self, loadedWeights = None, loadedBias = None): |
def __init__(self, loadedWeights: np.matrix=None, loadedBias: np.matrix=None): |
||||||
|
|
||||||
if( not loadedWeights or not loadedBias ): |
if( not loadedWeights or not loadedBias ): # if one is null (None) then just generate new ones |
||||||
|
print("Generating weights and biases...") |
||||||
self.weights = [ ai.genRandomMatrix(3, 4), ai.genRandomMatrix(4, 4), ai.genRandomMatrix(4, 3) ] # array of matrices of weights |
self.weights = [ ai.genRandomMatrix(3, 4), ai.genRandomMatrix(4, 4), ai.genRandomMatrix(4, 3) ] # array of matrices of weights |
||||||
# 3 input neurons -> 4 hidden neurons -> 4 hidden neurons -> 3 output neurons |
# 3 input neurons -> 4 hidden neurons -> 4 hidden neurons -> 3 output neurons |
||||||
|
|
||||||
# Will be needing biases too |
# Generate the biases |
||||||
self.bias = [ ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 3) ] |
self.bias = [ ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 4), ai.genRandomMatrix(1, 3) ] |
||||||
# This doesn't look very good, but it works so... |
# This doesn't look very good, but it works so... |
||||||
# This is all we need |
|
||||||
else: # if we want to load our progress from before then this would do it |
else: # if we want to load our progress from before then this would do it |
||||||
print("Loading neural net...") |
|
||||||
self.weights = loadedWeights |
self.weights = loadedWeights |
||||||
self.bias = loadedBias |
self.bias = loadedBias |
||||||
|
|
||||||
def think(self, inputMatrix): |
def learn(): |
||||||
print(self.weights) |
print("learn") |
||||||
print(self.bias) |
|
||||||
|
def think(self, inp:np.array): |
||||||
|
res = ai.think( np.asmatrix(inp), self.weights, self.bias ) |
||||||
|
print(res) |
||||||
|
# print(self.weights) |
||||||
|
# print(self.bias) |
||||||
|
|
||||||
def init(): # init func |
def init(): # init func |
||||||
bot = rgb() |
bot = rgb() |
||||||
|
bot.think( np.array([0.2, 0.4, 0.8]) ) |
||||||
bot.think(1) |
|
||||||
|
|
||||||
init() |
init() |
||||||
|
Loading…
Reference in new issue