Python

Using A multi-layer neural network to solve a 2x2 rubik's cube!

fork
loading
Files
  • main.py
  • cube.py
main.py
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
37
#I need a neural network with the shape of:
#[8(input layer), 30, 30, 30, 30, 19(output layer)]

import numpy as np

class Network():
  def __init__(self):
    self.layer1w = np.random.rand(8, 30)
    self.layer2w = np.random.rand(30,30)
    self.layer3w = np.random.rand(30,30)
    self.layer4w = np.random.rand(30,30)
    self.layer5w = np.random.rand(30, 19).T

    self.layer1d = np.empty([8,30])
    self.layer2d = np.empty([30,30])
    self.layer3d = np.empty([30,30])
    self.layer4d = np.empty([30,30])
    self.layer5d = np.empty([30,19])

    self.layer1o = np.empty(30)
    self.layer2o = np.empty(30)
    self.layer3o = np.empty(30)
    self.layer4o = np.empty(30)
    self.layer5o = np.empty(19)

  def sigmoid(self, inp):
    return 1 / (np.add(1, 2.718 ** (np.subtract(1, inp))))
  
  def sigmoid_prime(self, inp):
    return inp * (np.subtract(1, inp))

  def Think(self, inp):
    self.layer1o = self.sigmoid(self.layer1w * inp.T)
    self.layer2o = self.sigmoid(self.layer1o * self.layer2w)
    self.layer3o = self.sigmoid(self.layer3w * self.layer2o)
    self.layer4o = self.sigmoid(self.layer4w * self.layer3o)
    self.layer5o = self.sigmoid(self.layer5w * self.layer4o)