コード例 #1
0
hardestSudoku_fixed = [[True, False, False, False, False, False, False, False, False],
                       [False, False, True, True, False, False, False, False, False],
                       [False, True, False, False, True, False, True, False, False],
                       [False, True, False, False, False, True, False, False, False],
                       [False, False, False, False, True, True, True, False, False],
                       [False, False, False, True, False, False, False, True, False],
                       [False, False, True, False, False, False, False, True, True],
                       [False, False, True, True, False, False, False, True, False],
                       [False, True, False, False, False, False, True, False, False]]

def one_hot(array):
    targets = np.array(np.asarray(array).reshape(-1))
    one_hot = np.eye(10)[targets]
    return one_hot

reducer = SolvedSudoku(hardestSudoku, hardestSudoku_fixed)

nodes1 = 1
nodes2 = 1

x = tf.placeholder("float32", [1, 810], name = "reducedBoards")
y = tf.placeholder("float32", [1, 810], name = "solutions")

def nnmodel(data):
    hl1 = {'weights' : tf.Variable(tf.random_normal([810, nodes1])),
           'biases' : tf.Variable(tf.random_normal([nodes1]))}
    
    hl2 = {'weights' : tf.Variable(tf.random_normal([nodes1, nodes2])),
           'biases' : tf.Variable(tf.random_normal([nodes2]))}
    
    output_layer = {'weights' : tf.Variable(tf.random_normal([nodes2, 810])),
コード例 #2
0
#                  [2, 8, 7, 1, 6, 9, 5, 3, 4],
#                  [5, 2, 1, 9, 7, 4, 3, 6, 8],
#                  [4, 3, 8, 5, 2, 6, 9, 1, 7],
#                  [7, 9, 6, 3, 1, 8, 4, 5, 2]]
#
# hardestSudoku_fixed = [[True, False, False, False, False, False, False, False, False],
#                        [False, False, True, True, False, False, False, False, False],
#                        [False, True, False, False, True, False, True, False, False],
#                        [False, True, False, False, False, True, False, False, False],
#                        [False, False, False, False, True, True, True, False, False],
#                        [False, False, False, True, False, False, False, True, False],
#                        [False, False, True, False, False, False, False, True, True],
#                        [False, False, True, True, False, False, False, True, False],
#                        [False, True, False, False, False, False, True, False, False]]

reducer = SolvedSudoku(2000)
test_reducer = SolvedSudoku(2000)
numbers_to_predict = 10
batch_size = 128

sess = tf.InteractiveSession()

x = tf.placeholder("float32", [None, 810], name="reducedBoards")
y = tf.placeholder("float32", [None, numbers_to_predict * 10],
                   name="solutions")

x_board = tf.reshape(x, [-1, 9, 90, 1], name="x_board")


def one_hot(array):
    targets = np.array(np.asarray(array).reshape(-1))
コード例 #3
0
                 [2, 8, 7, 1, 6, 9, 5 ,3, 4],
                 [5, 2, 1, 9, 7, 4, 3, 6, 8],
                 [4, 3, 8, 5, 2, 6, 9, 1, 7],
                 [7, 9, 6, 3, 1, 8, 4, 5, 2]]

hardestSudoku_fixed = [[True, False, False, False, False, False, False, False, False],
                       [False, False, True, True, False, False, False, False, False],
                       [False, True, False, False, True, False, True, False, False],
                       [False, True, False, False, False, True, False, False, False],
                       [False, False, False, False, True, True, True, False, False],
                       [False, False, False, True, False, False, False, True, False],
                       [False, False, True, False, False, False, False, True, True],
                       [False, False, True, True, False, False, False, True, False],
                       [False, True, False, False, False, False, True, False, False]]

reducer = SolvedSudoku(hardestSudoku, hardestSudoku_fixed)

learning_rate = 0.01
training_iteration = 10000
batch_size = 1
display_step = 500

x = tf.placeholder("float", [None, 81], name = "reducedBoards")
y = tf.placeholder("float", name = "solutions")

W = tf.Variable(tf.zeros([81,81]))
b = tf.Variable(tf.zeros([81]))

with tf.name_scope("Wx_b") as scope:
    model = tf.nn.softmax(tf.matmul(x, W) + b)
    
コード例 #4
0
#                  [5, 2, 1, 9, 7, 4, 3, 6, 8],
#                  [4, 3, 8, 5, 2, 6, 9, 1, 7],
#                  [7, 9, 6, 3, 1, 8, 4, 5, 2]]
#
# hardestSudoku_fixed = [[True, False, False, False, False, False, False, False, False],
#                        [False, False, True, True, False, False, False, False, False],
#                        [False, True, False, False, True, False, True, False, False],
#                        [False, True, False, False, False, True, False, False, False],
#                        [False, False, False, False, True, True, True, False, False],
#                        [False, False, False, True, False, False, False, True, False],
#                        [False, False, True, False, False, False, False, True, True],
#                        [False, False, True, True, False, False, False, True, False],
#                        [False, True, False, False, False, False, True, False, False]]

num_sudokus = 2000
reducer = SolvedSudoku(num_sudokus)
test_reducer = SolvedSudoku(num_sudokus//2)
numbers_to_predict = 10
batch_size = 128

sess = tf.InteractiveSession()

x = tf.placeholder("float32", [None, 810], name="reducedBoards")
y = tf.placeholder("float32", [None, numbers_to_predict*10], name="solutions")

x_board = tf.reshape(x, [-1, 9, 90, 1], name="x_board")

def one_hot(array):
    targets = np.array(np.asarray(array).reshape(-1))
    one_hot = np.eye(10)[targets]
    return one_hot
コード例 #5
0
import tensorflow as tf
import numpy as np
from Sudoku import SolvedSudoku

reducer = SolvedSudoku(1)
test_reducer = SolvedSudoku(1)
numbers_to_predict = 10
batch_size = 128

sess = tf.InteractiveSession()

x = tf.placeholder("float32", [None, 810], name="reducedBoards")
y = tf.placeholder("float32", [None, numbers_to_predict * 10],
                   name="solutions")

x_board = tf.reshape(x, [-1, 9, 90, 1], name="x_board")


def one_hot(array):
    targets = np.array(np.asarray(array).reshape(-1))
    one_hot = np.eye(10)[targets]
    return one_hot


def prepare_data(x, reshape_num):
    ohx = one_hot(x)
    x_reshaped = np.reshape(ohx, reshape_num)
    x_final = np.asarray(x_reshaped)

    return x_final