coeffs = 4 * np.random.random(n) - 2 splineSpace = len(coeffs) coeffs = np.array([coeffs]) knots = np.zeros(n + p + 1) knots[:p + 1] = 0 knots[-p - 1:] = n - p knots[p + 1:-p - 1] = np.sort( np.random.random(len(knots[p + 1:-p - 1])) * (knots[-1] - knots[0])) + knots[0] sampleStep = int((epochs - 1) / (samples - 1)) x = tf.placeholder(tf.float32, [None, 1]) z = tf.placeholder(tf.float32, [None, 1]) tz, c = splineParameters(nodes, splineSpace, p, [knots[0], knots[-1]]) t = sortKnot(tz, p) y = spline(x, t, c, p) loss = tf.reduce_mean((y - z)**2) optimizer = tf.train.AdamOptimizer(2e-3).minimize(loss) config = tf.ConfigProto() config.intra_op_parallelism_threads = 12 config.inter_op_parallelism_threads = 12 tees = np.empty([samples, len(knots)]) cees = np.empty([samples, len(coeffs.T)]) tzees = np.empty([samples, len(knots)]) errors = np.empty(samples)
except: p = 3 samples = 15 for sample in range(samples): #Neural network architecture x = tf.placeholder(tf.float32, [None, inputSize]) t = tf.placeholder(tf.float32, [None, 1]) W1 = randomVariable([inputSize, hiddenSize]) b1 = randomVariable([hiddenSize]) W2 = randomVariable([hiddenSize, outputSize]) b2 = randomVariable([outputSize]) t1, c1 = splineParameters(hiddenSize, splineSize, p, [-2, 2]) t2, c2 = splineParameters(outputSize, splineSize, p, [-2, 2]) h = spline(tf.matmul(x, W1) + b1, t1, c1, p) y = spline(tf.matmul(h, W2) + b2, t2, c2, p) # y = tf.matmul(h, W2) + b2 cost = tf.sqrt(tf.losses.mean_squared_error(t, y)) _, var = tf.nn.moments(t, axes = [0]) nrmse = tf.sqrt(tf.losses.mean_squared_error(t, y)/var[0]) optimizer = tf.train.AdamOptimizer(1e-3).minimize(cost) minError = 1e6 with tf.Session() as sess: sess.run(tf.global_variables_initializer())
tf.random_uniform(shape=tf.shape(x), minval=0, maxval=2, dtype=tf.int32), tf.float32)) learningRateAE = 1e-3 learningRateFT = 1e-4 lossFunction = tf.losses.mean_squared_error displayImages = mnist.validation.images[[3, 5, 7, 9, 0, 66, 71, 85, 4]] x = tf.placeholder(tf.float32, [None, inputSize]) target = tf.placeholder(tf.float32, [None, outSize]) tz1, C1 = splineParameters(hidden1, splineSpaceSize, p, [-5, 5], name="spline1") tz2, C2 = splineParameters(hidden2, splineSpaceSize, p, [-5, 5], name="spline2") tz3, C3 = splineParameters(outSize, splineSpaceSize, p, [-5, 5], name="spline3") _, C1T = splineParameters(inputSize, splineSpaceSize, p, [-5, 5], name="spline1T") _, C2T = splineParameters(hidden1, splineSpaceSize,