我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用theano.tensor.power()。
def get_eval_fn(model, in3D=False, use_dice=False): """Compile the evaluation function of the model.""" if use_dice: insec = T.sum(model.trg * model.output, axis=1) tmp = 1 - 2.0 * insec/(T.sum(model.trg, axis=1) + T.sum(model.output, axis=1)) error = T.mean(tmp) else: error = T.mean(T.mean(T.power(model.output - model.trg, 2), axis=1)) if in3D: x = T.tensor4('x') else: x = T.fmatrix("x") y = T.fmatrix("y") theano_arg_vl = [x, y] output_fn_vl = [error, model.output] eval_fn = theano.function( theano_arg_vl, output_fn_vl, givens={model.x: x, model.trg: y}) return eval_fn
def _generate_conv(self): input = T.tensor4(name='input') if self.pooling == 'squareroot': conv_out = Pool.pool_2d( T.power(input,2), ds=(self.spatial[0], self.spatial[1]), ignore_border=self.ignore_border, mode='sum', padding=self.pad, st=None if self.stride is None else (self.stride, self.stride)) conv_out = T.sqrt(conv_out) else: conv_out = Pool.pool_2d( input, ds=(self.spatial[0], self.spatial[1]), ignore_border=self.ignore_border, mode=self.pooling, padding=self.pad, st=None if self.stride is None else (self.stride, self.stride)) if self.activation_fct is None: output = conv_out else: output = self.activation_fct(conv_out) self.conv = theano.function([input], output)
def pow(self, l, r): return T.power(l, r)
def __get_loss(self, use_dropout, iteration_number=0): node_encoding1, _, extra_loss1 = self.__rnn.get_encoding(use_dropout, iteration_number) node_encoding1 /= node_encoding1.norm(2) copy_rnn = self.__rnn.copy_full() node_encoding2, _, extra_loss2 = copy_rnn.get_encoding(use_dropout, iteration_number) node_encoding2 /= node_encoding2.norm(2) distance = (node_encoding1 - node_encoding2).norm(2) are_non_equivalent = self.__rnn.get_input_variables().eq_symbol - copy_rnn.get_input_variables().eq_symbol margin = self.__hyperparameters['dissimilar_margin'] siamese_loss = -T.power(T.switch(are_non_equivalent, T.nnet.relu(margin - distance), distance), 2) return siamese_loss + extra_loss1 + extra_loss2, copy_rnn
def power(x, a): return T.power(x, a)