import tensorflow as tf import numpy as np from command_line_args import arg_parser from data import data_from_args from model_helpers import build_model, init_weights, set_seeds args = arg_parser.parse_args() data = data_from_args(args) NUM_HIDDEN = args.num_hidden or 100 set_seeds(123) # Initialize the weights. w_h = init_weights([data.num_inputs, NUM_HIDDEN]) w_o = init_weights([NUM_HIDDEN, 4]) b_h = init_weights([NUM_HIDDEN]) b_o = init_weights([4]) def model(X, w_h, w_o, b_h, b_o): h = tf.nn.relu(tf.matmul(X, w_h) + b_h) return tf.matmul(h, w_o) + b_o py_x = model(data.X, w_h, w_o, b_h, b_o) cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(py_x, data.Y)) train_op = tf.train.RMSPropOptimizer(learning_rate=0.0008, decay=0.8, momentum=0.4).minimize(cost) predict_op = tf.argmax(py_x, 1)
import numpy as np from command_line_args import arg_parser from data import data_from_args from model_helpers import build_model, init_weights, set_seeds args = arg_parser.parse_args() data = data_from_args(args) NUM_HIDDEN1 = args.num_hidden or 100 NUM_HIDDEN2 = args.num_hidden2 or 100 set_seeds(123) # Initialize the weights. w_h1 = init_weights([data.num_inputs, NUM_HIDDEN1]) w_h2 = init_weights([NUM_HIDDEN1, NUM_HIDDEN2]) w_o = init_weights([NUM_HIDDEN2, 4]) b_h1 = init_weights([NUM_HIDDEN1]) b_h2 = init_weights([NUM_HIDDEN2]) b_o = init_weights([4]) def model(X, w_h1, w_h2, w_o, b_h1, b_h2, b_o, keep_prob): h1 = tf.nn.dropout(tf.nn.relu(tf.matmul(X, w_h1) + b_h1), keep_prob) h2 = tf.nn.relu(tf.matmul(h1, w_h2) + b_h2) return tf.matmul(h2, w_o) + b_o def py_x(keep_prob):
import numpy as np from command_line_args import arg_parser from data import data_from_args from model_helpers import build_model, init_weights, set_seeds args = arg_parser.parse_args() data = data_from_args(args) NUM_HIDDEN1 = args.num_hidden or 100 NUM_HIDDEN2 = args.num_hidden2 or 100 set_seeds(123) # Initialize the weights. w_h1 = init_weights([data.num_inputs, NUM_HIDDEN1]) w_h2 = init_weights([NUM_HIDDEN1, NUM_HIDDEN2]) w_o = init_weights([NUM_HIDDEN2, 4]) b_h1 = init_weights([NUM_HIDDEN1]) b_h2 = init_weights([NUM_HIDDEN2]) b_o = init_weights([4]) def model(X, w_h1, w_h2, w_o, b_h1, b_h2, b_o, keep_prob): if keep_prob < 1.0: h1 = tf.nn.dropout(tf.nn.relu(tf.matmul(X, w_h1) + b_h1), keep_prob) else: h1 = tf.nn.relu(tf.matmul(X, w_h1) + b_h1) h2 = tf.nn.relu(tf.matmul(h1, w_h2) + b_h2) return tf.matmul(h2, w_o) + b_o
# logistic regression model # https://en.wikipedia.org/wiki/Logistic_regression import tensorflow as tf import numpy as np from command_line_args import arg_parser from data import data_from_args from model_helpers import build_model, init_weights, set_seeds set_seeds(123) args = arg_parser.parse_args() data = data_from_args(args) w = init_weights([data.num_inputs, 4]) b = init_weights([4]) def model(X, w, b): return tf.matmul(X, w) + b # Predict y given x using the model. py_x = model(data.X, w, b) # We'll train our model by minimizing a cost function. cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(py_x, data.Y)) train_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # And we'll make predictions by choosing the largest output.
# Linear Regression model # https://en.wikipedia.org/wiki/Linear_regression import tensorflow as tf import numpy as np from command_line_args import arg_parser from data import data_from_args from model_helpers import build_model, init_weights, set_seeds, make_output set_seeds(123) args = arg_parser.parse_args() data = data_from_args(args) w = init_weights([data.num_inputs, 4]) b = init_weights([4]) def model(X, w, b): return tf.matmul(X, w) + b # Predict y given x using the model. py_x = model(data.X, w, b) # We'll train our model by minimizing a cost function. cost = tf.reduce_mean(tf.pow(py_x - data.Y, 2)) train_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost) # And we'll make predictions by choosing the largest output. predict_op = tf.argmax(py_x, 1)