Python tensorflow.neg() Examples
The following are 14
code examples of tensorflow.neg().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow
, or try the search function
.
Example #1
Source File: subscribe_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testSideEffect(self): a = tf.constant(1) b = tf.constant(1) c = tf.add(a, b) with tf.control_dependencies([c]): d = tf.constant(42) n = tf.neg(c) shared = [] def sub(t): shared.append(t) return t c = subscribe.subscribe(c, lambda t: tf.py_func(sub, [t], [t.dtype])) with self.test_session() as sess: c_out = sess.run([c]) n_out = sess.run([n]) d_out = sess.run([d]) self.assertEquals(n_out, [-2]) self.assertEquals(c_out, [2]) self.assertEquals(d_out, [42]) self.assertEquals(shared, [2, 2, 2])
Example #2
Source File: ddpg_cartpole.py From cartpoleplusplus with MIT License | 6 votes |
def init_ops_for_training(self, critic): # actors gradients are the gradients for it's output w.r.t it's vars using initial # gradients provided by critic. this requires that critic was init'd with an # input_action = actor.output_action (which is natural anyway) # we wrap the optimiser in namespace since we don't want this as part of copy to # target networks. # note that we negate the gradients from critic since we are trying to maximise # the q values (not minimise like a loss) with tf.variable_scope("optimiser"): gradients = tf.gradients(self.output_action, self.trainable_model_vars(), tf.neg(critic.q_gradients_wrt_actions())) gradients = zip(gradients, self.trainable_model_vars()) # potentially clip and wrap with debugging gradients = util.clip_and_debug_gradients(gradients, opts) # apply optimiser = tf.train.GradientDescentOptimizer(opts.actor_learning_rate) self.train_op = optimiser.apply_gradients(gradients)
Example #3
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testFloatBasic(self): x = np.arange(-3, 3).reshape(1, 3, 2).astype(np.float32) y = (x + .5).astype(np.float32) # no zero z = (x + 15.5).astype(np.float32) # all positive k = np.arange(-0.90, 0.90, 0.25).astype(np.float32) # between -1 and 1 self._compareBoth(x, np.abs, tf.abs) self._compareBoth(x, np.abs, _ABS) self._compareBoth(x, np.negative, tf.neg) self._compareBoth(x, np.negative, _NEG) self._compareBoth(y, self._inv, tf.inv) self._compareBoth(x, np.square, tf.square) self._compareBoth(z, np.sqrt, tf.sqrt) self._compareBoth(z, self._rsqrt, tf.rsqrt) self._compareBoth(x, np.exp, tf.exp) self._compareBoth(z, np.log, tf.log) self._compareBoth(z, np.log1p, tf.log1p) self._compareBoth(x, np.tanh, tf.tanh) self._compareBoth(x, self._sigmoid, tf.sigmoid) self._compareBoth(y, np.sign, tf.sign) self._compareBoth(x, np.sin, tf.sin) self._compareBoth(x, np.cos, tf.cos) self._compareBoth(k, np.arcsin, tf.asin) self._compareBoth(k, np.arccos, tf.acos) self._compareBoth(x, np.arctan, tf.atan) self._compareBoth(x, np.tan, tf.tan) self._compareBoth( y, np.vectorize(self._replace_domain_error_with_inf(math.lgamma)), tf.lgamma) self._compareBoth(x, np.vectorize(math.erf), tf.erf) self._compareBoth(x, np.vectorize(math.erfc), tf.erfc) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(z, np.sqrt, tf.sqrt, tol=1e-3) self._compareBothSparse(x, np.tanh, tf.tanh) self._compareBothSparse(y, np.sign, tf.sign) self._compareBothSparse(x, np.vectorize(math.erf), tf.erf)
Example #4
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testFloatEmpty(self): x = np.empty((2, 0, 5), dtype=np.float32) self._compareBoth(x, np.abs, tf.abs) self._compareBoth(x, np.abs, _ABS) self._compareBoth(x, np.negative, tf.neg) self._compareBoth(x, np.negative, _NEG) self._compareBoth(x, self._inv, tf.inv) self._compareBoth(x, np.square, tf.square) self._compareBoth(x, np.sqrt, tf.sqrt) self._compareBoth(x, self._rsqrt, tf.rsqrt) self._compareBoth(x, np.exp, tf.exp) self._compareBoth(x, np.log, tf.log) self._compareBoth(x, np.log1p, tf.log1p) self._compareBoth(x, np.tanh, tf.tanh) self._compareBoth(x, self._sigmoid, tf.sigmoid) self._compareBoth(x, np.sign, tf.sign) self._compareBoth(x, np.sin, tf.sin) self._compareBoth(x, np.cos, tf.cos) # Can't use vectorize below, so just use some arbitrary function self._compareBoth(x, np.sign, tf.lgamma) self._compareBoth(x, np.sign, tf.erf) self._compareBoth(x, np.sign, tf.erfc) self._compareBoth(x, np.tan, tf.tan) self._compareBoth(x, np.arcsin, tf.asin) self._compareBoth(x, np.arccos, tf.acos) self._compareBoth(x, np.arctan, tf.atan) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(x, np.sqrt, tf.sqrt, tol=1e-3) self._compareBothSparse(x, np.tanh, tf.tanh) self._compareBothSparse(x, np.sign, tf.sign) self._compareBothSparse(x, np.sign, tf.erf)
Example #5
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testDoubleBasic(self): x = np.arange(-3, 3).reshape(1, 3, 2).astype(np.float64) y = (x + .5).astype(np.float64) # no zero z = (x + 15.5).astype(np.float64) # all positive k = np.arange(-0.90, 0.90, 0.35).reshape(1, 3, 2).astype(np.float64) # between -1 and 1 self._compareBoth(x, np.abs, tf.abs) self._compareBoth(x, np.abs, _ABS) self._compareBoth(x, np.negative, tf.neg) self._compareBoth(x, np.negative, _NEG) self._compareBoth(y, self._inv, tf.inv) self._compareBoth(x, np.square, tf.square) self._compareBoth(z, np.sqrt, tf.sqrt) self._compareBoth(z, self._rsqrt, tf.rsqrt) self._compareBoth(x, np.exp, tf.exp) self._compareBoth(z, np.log, tf.log) self._compareBoth(z, np.log1p, tf.log1p) self._compareBoth(x, np.tanh, tf.tanh) self._compareBoth(x, self._sigmoid, tf.sigmoid) self._compareBoth(y, np.sign, tf.sign) self._compareBoth(x, np.sin, tf.sin) self._compareBoth(x, np.cos, tf.cos) self._compareBoth( y, np.vectorize(self._replace_domain_error_with_inf(math.lgamma)), tf.lgamma) self._compareBoth(x, np.vectorize(math.erf), tf.erf) self._compareBoth(x, np.vectorize(math.erfc), tf.erfc) self._compareBoth(x, np.arctan, tf.atan) self._compareBoth(k, np.arcsin, tf.asin) self._compareBoth(k, np.arccos, tf.acos) self._compareBoth(k, np.tan, tf.tan) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(z, np.sqrt, tf.sqrt, tol=1e-3) self._compareBothSparse(x, np.tanh, tf.tanh) self._compareBothSparse(y, np.sign, tf.sign) self._compareBothSparse(x, np.vectorize(math.erf), tf.erf)
Example #6
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testHalfBasic(self): x = np.arange(-3, 3).reshape(1, 3, 2).astype(np.float16) y = (x + .5).astype(np.float16) # no zero z = (x + 15.5).astype(np.float16) # all positive self._compareBoth(x, np.abs, tf.abs) self._compareBoth(x, np.abs, _ABS) self._compareBoth(x, np.negative, tf.neg) self._compareBoth(x, np.negative, _NEG) self._compareBoth(y, self._inv, tf.inv) self._compareBoth(x, np.square, tf.square) self._compareBoth(z, np.sqrt, tf.sqrt) self._compareBoth(z, self._rsqrt, tf.rsqrt) self._compareBoth(x, np.exp, tf.exp) self._compareBoth(z, np.log, tf.log) self._compareBoth(z, np.log1p, tf.log1p) self._compareBoth(x, np.tanh, tf.tanh) self._compareBoth(x, self._sigmoid, tf.sigmoid) self._compareBoth(y, np.sign, tf.sign) self._compareBoth(x, np.sin, tf.sin) self._compareBoth(x, np.cos, tf.cos) self._compareBoth( y, np.vectorize(self._replace_domain_error_with_inf(math.lgamma)), tf.lgamma) self._compareBoth(x, np.vectorize(math.erf), tf.erf) self._compareBoth(x, np.vectorize(math.erfc), tf.erfc) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(z, np.sqrt, tf.sqrt, tol=1e-3) self._compareBothSparse(x, np.tanh, tf.tanh) self._compareBothSparse(y, np.sign, tf.sign) self._compareBothSparse(x, np.vectorize(math.erf), tf.erf, tol=1e-3)
Example #7
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testInt32Basic(self): x = np.arange(-6, 6, 2).reshape(1, 3, 2).astype(np.int32) self._compareCpu(x, np.abs, tf.abs) self._compareCpu(x, np.abs, _ABS) self._compareBoth(x, np.negative, tf.neg) self._compareBoth(x, np.negative, _NEG) self._compareBoth(x, np.square, tf.square) self._compareCpu(x, np.sign, tf.sign) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(x, np.sign, tf.sign)
Example #8
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testComplex64Basic(self): x = np.complex(1, 1) * np.arange(-3, 3).reshape(1, 3, 2).astype( np.complex64) y = x + 0.5 # no zeros self._compareCpu(x, np.abs, tf.complex_abs) self._compareCpu(x, np.abs, _ABS) self._compareCpu(x, np.negative, tf.neg) self._compareCpu(x, np.negative, _NEG) self._compareCpu(y, self._inv, tf.inv) self._compareCpu(x, np.square, tf.square) self._compareCpu(y, np.sqrt, tf.sqrt) self._compareCpu(y, self._rsqrt, tf.rsqrt) self._compareCpu(x, np.exp, tf.exp) self._compareCpu(y, np.log, tf.log) self._compareCpu(y, np.log1p, tf.log1p) self._compareCpu(x, np.tanh, tf.tanh) self._compareCpu(x, self._sigmoid, tf.sigmoid) self._compareCpu(x, np.sin, tf.sin) self._compareCpu(x, np.cos, tf.cos) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(x, np.sqrt, tf.sqrt, 1e-3) self._compareBothSparse(x, np.tanh, tf.tanh) # Numpy uses an incorrect definition of sign; use the right one instead. def complex_sign(x): return x / np.abs(x) self._compareCpu(y, complex_sign, tf.sign) self._compareBothSparse(y, complex_sign, tf.sign)
Example #9
Source File: cwise_ops_test.py From deep_image_model with Apache License 2.0 | 5 votes |
def testComplex128Basic(self): x = np.complex(1, 1) * np.arange(-3, 3).reshape(1, 3, 2).astype( np.complex128) y = x + 0.5 # no zeros self._compareCpu(x, np.abs, tf.abs) self._compareCpu(x, np.abs, _ABS) self._compareCpu(x, np.negative, tf.neg) self._compareCpu(x, np.negative, _NEG) self._compareCpu(y, self._inv, tf.inv) self._compareCpu(x, np.square, tf.square) self._compareCpu(y, np.sqrt, tf.sqrt) self._compareCpu(y, self._rsqrt, tf.rsqrt) self._compareCpu(x, np.exp, tf.exp) self._compareCpu(y, np.log, tf.log) self._compareCpu(y, np.log1p, tf.log1p) self._compareCpu(x, np.tanh, tf.tanh) self._compareCpu(x, self._sigmoid, tf.sigmoid) self._compareCpu(x, np.sin, tf.sin) self._compareCpu(x, np.cos, tf.cos) self._compareBothSparse(x, np.abs, tf.abs) self._compareBothSparse(x, np.negative, tf.neg) self._compareBothSparse(x, np.square, tf.square) self._compareBothSparse(x, np.sqrt, tf.sqrt, 1e-3) self._compareBothSparse(x, np.tanh, tf.tanh) # Numpy uses an incorrect definition of sign; use the right one instead. def complex_sign(x): return x / np.abs(x) self._compareCpu(y, complex_sign, tf.sign) self._compareBothSparse(y, complex_sign, tf.sign)
Example #10
Source File: model.py From tensorflow_tmva with GNU General Public License v2.0 | 5 votes |
def activation(type, synapse): """Chooses the activation function to use.""" if type == "sigmoid": return tf.sigmoid(synapse) elif type == "linear": return synapse elif type == "tanh": return tf.tanh(synapse) elif type == "radial": return tf.sqrt(tf.exp(tf.neg(tf.square(synapse))))
Example #11
Source File: svm.py From tensorflow_tmva with GNU General Public License v2.0 | 5 votes |
def gaussian_kernel(tensor_a, a_inputs, tensor_b, b_inputs, gamma): """Returns the Gaussian kernel matrix of two matrices of vectors element-wise.""" cross = cross_matrices(tensor_a, a_inputs, tensor_b, b_inputs) kernel = tf.exp(tf.mul(tf.reduce_sum(tf.square( tf.sub(cross[0], cross[1])), reduction_indices=2), tf.neg(tf.constant(gamma, dtype=tf.float32)))) return kernel
Example #12
Source File: tf_distributions.py From MJHMC with GNU General Public License v2.0 | 5 votes |
def build_energy_op(self): with self.graph.as_default(), tf.device(self.energy_device): # [1, nbatch] e_x_0 = tf.neg((self.state_pl[0, :] ** 2) / (self.scale ** 2), name='E_x_0') # [ndims - 1, nbatch] e_x_k = tf.neg((self.state_pl[1:, :] ** 2) / tf.exp(self.state_pl[0, :]), name='E_x_k') # [nbatch] self.energy_op = tf.reduce_sum(tf.add(e_x_0, e_x_k), 0, name='energy_op')
Example #13
Source File: flip_gradient.py From active_learning_coreset with MIT License | 5 votes |
def __call__(self, x, l=1.0): grad_name = "FlipGradient%d" % self.num_calls @ops.RegisterGradient(grad_name) def _flip_gradients(op, grad): return [tf.neg(grad) * l] g = tf.get_default_graph() with g.gradient_override_map({"Identity": grad_name}): y = tf.identity(x) self.num_calls += 1 return y
Example #14
Source File: triplet_clustering.py From active_learning_coreset with MIT License | 5 votes |
def loss_function(self): pos_diff = self.anchor - self.positive neg_diff = self.anchor - self.negative pos_dist = tf.reduce_sum(tf.mul(pos_diff, pos_diff), 1) neg_dist = tf.reduce_sum(tf.mul(neg_diff, neg_diff), 1) triplet = tf.add(self.ALPHA, tf.add(pos_dist, tf.neg(neg_dist))) return tf.reduce_sum(tf.nn.relu(triplet))