Collection of my machine-learning stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
machinelearning/rgbAI/main.py

54 lines
1.4 KiB

4 years ago
#!/usr/bin/env python
import numpy as np
import lib.ailib as ai
class rgb(object):
4 years ago
def __init__(self, loadedWeights: np.matrix=None, loadedBias: np.matrix=None):
4 years ago
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, 8), ai.genRandomMatrix(8, 8), ai.genRandomMatrix(8, 3) ] # array of matrices of weights
4 years ago
# 3 input neurons -> 8 hidden neurons -> 8 hidden neurons -> 3 output neurons
4 years ago
# Generate the biases
self.bias = [ ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 8), ai.genRandomMatrix(1, 3) ]
4 years ago
# This doesn't look very good, but it works so...
4 years ago
self.learningrate = 0.01 # the learning rate of this ai
4 years ago
print( self.weights )
print( self.bias )
4 years ago
else: # if we want to load our progress from before then this would do it
self.weights = loadedWeights
self.bias = loadedBias
4 years ago
def calcError( self, inp:np.array, out:np.array ):
cost = ai.calcCost( inp, out )
# Cost needs to get to 0, we can figure out this with backpropagation
return cost
4 years ago
def learn( self ):
ai.learn( 3, 0.0001, self, 0.001 )
4 years ago
def think( self, inp:np.array ):
print("\n-Input-")
print(inp)
4 years ago
res = ai.think( inp, self )
4 years ago
print("\n-Output-")
print(res)
return res
def init():
4 years ago
bot = rgb()
bot.learn()
4 years ago
4 years ago
inpArr = np.asarray([1.0, 1.0, 1.0])
res = bot.think( inpArr )
err = bot.calcError( inpArr, res )
print(err)
4 years ago
init()