# Module Example
# Abraham Oliver, 2016
# Reverse Learning

import tensorflow as tf
import numpy as np
from Network import Network
import json
from random import randint

f = open('../DataSets/WineQuality/winequality-red.json')
data = json.load(f)
f.close()

def newSet(data, size):
    xs = []     # Data
    ys = []     # Labels
    # Make data subset of size 'size'
    columns = ["fixed acidity", "volatile acidity", "citric acid", "residual sugar",
               "chlorides", "free sulfur dioxide", "total sulfur dioxide", "density",
               "pH", "sulphates", "alcohol"]
    for i in range(size):
        index = randint(0, 1598)
        d = data[index]     # Data point being extracted
        ins = []        # Input container to be filled
        # Turn named inputs into un-named input vectors
        for j in columns:
            ins.append(d[j])  # Map column values
        # Add newly separated data to dataset
        xs.append(ins)

        # Create one-hot for label
        id = int(d["quality"])
        f = [0 for i in range(10)]  # One-hot from zero to 10
        f[id] = 1
        ys.append(f)
    return (xs, ys)

n = Network([11, 10, 10])
n.initWeights(mode="zeros")
n.train(newSet(data, 100), epochs = 20001, learn_rate = .01,
        debug = True, debug_interval = 10000)

p = newSet(data, 1)
a = n.feed(p[0]).eval(session = n._session)
print p[0]
print [float(i) for i in p[1][0]]
print [round(i, 1) for i in a[0]]

# Test

@@ -252,16 +252,229 @@
 lose()%0A%0A
+columns = %5B%22fixed acidity%22, %22volatile acidity%22, %22citric acid%22, %22residual sugar%22,%0A               %22chlorides%22, %22free sulfur dioxide%22, %22total sulfur dioxide%22, %22density%22,%0A               %22pH%22, %22sulphates%22, %22alcohol%22%5D%0A%0A
 def newS
@@ -791,16 +791,17 @@
 cohol%22%5D%0A
+%0A
     for 
@@ -1373,12 +1373,8 @@
 %5B11,
- 10,
  10%5D
@@ -1424,17 +1424,17 @@
 t(data, 
-1
+2
 00), epo
@@ -1439,17 +1439,17 @@
 pochs = 
-2
+4
 0001, le
@@ -1463,10 +1463,8 @@
 e = 
-.0
 1,%0A 
@@ -1482,11 +1482,12 @@
 g = 
-Tru
+Fals
 e, d
@@ -1574,16 +1574,25 @@
 ession)%0A
+print %22%22%0A
 print p%5B
@@ -1669,9 +1669,596 @@
 %0A%0A# Test
-%0A
+ all data%0Aprint %22%5CnTESTING%22%0Acorrect = 0%0Aerrors = 0%0Afor i in data%5B:100%5D:%0A    x = %5B%5Bi%5Bkey%5D for key in columns%5D%5D%0A    # Create one-hot for label%0A    id = int(i%5B%22quality%22%5D)%0A    y_ = %5B0 for i in range(10)%5D  # One-hot from zero to 10%0A    y_%5Bid%5D = 1%0A    y = n.feed(x).eval(session = n._session)%0A    if tf.argmax(y_, 0).eval(session = n._session) == tf.argmax(y%5B0%5D, 0).eval(session = n._session):%0A        correct += 1%0A    else:%0A        errors += 1%0A%0Aprint %22%5CnCORRECT  :: %7B0%7D%22.format(correct)%0Aprint %22ERRORS   :: %7B0%7D%22.format(errors)%0Aprint %22ACCURACY :: %7B0%7D%22.format(float(correct) / (correct + errors))

Add testing for Wine example