當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.tanh方法代碼示例

本文整理匯總了Python中numpy.tanh方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.tanh方法的具體用法?Python numpy.tanh怎麽用?Python numpy.tanh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.tanh方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def __init__(self, choice="sigmoid"):
        """
        :param choice: Which activation function you want, must be in self.available
        """
        if choice not in self.available:
            msg = "Choice of activation (" + choice + ") not available!"
            log.out.error(msg)
            raise ValueError(msg)
        elif choice == "tanh":
            self.function = self._tanh
        elif choice == "tanhpos":
            self.function = self._tanhpos
        elif choice == "sigmoid":
            self.function = self._sigmoid
        elif choice == "softplus":
            self.function = self._softplus
        elif choice == "relu":
            self.function = self._relu
        elif choice == "leakyrelu":
            self.function = self._leakyrelu 
開發者ID:uptake,項目名稱:numpynet,代碼行數:22,代碼來源:common.py

示例2: _check_success

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def _check_success(self):
        """
        Returns True if task has been completed.
        """

        # remember objects that are on the correct pegs
        gripper_site_pos = self.sim.data.site_xpos[self.eef_site_id]
        for i in range(len(self.ob_inits)):
            obj_str = str(self.item_names[i]) + "0"
            obj_pos = self.sim.data.body_xpos[self.obj_body_id[obj_str]]
            dist = np.linalg.norm(gripper_site_pos - obj_pos)
            r_reach = 1 - np.tanh(10.0 * dist)
            self.objects_on_pegs[i] = int(self.on_peg(obj_pos, i) and r_reach < 0.6)

        if self.single_object_mode > 0:
            return np.sum(self.objects_on_pegs) > 0  # need one object on peg

        # returns True if all objects are on correct pegs
        return np.sum(self.objects_on_pegs) == len(self.ob_inits) 
開發者ID:StanfordVL,項目名稱:robosuite,代碼行數:21,代碼來源:panda_nut_assembly.py

示例3: _check_success

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def _check_success(self):
        """
        Returns True if task has been completed.
        """

        # remember objects that are in the correct bins
        gripper_site_pos = self.sim.data.site_xpos[self.eef_site_id]
        for i in range(len(self.ob_inits)):
            obj_str = str(self.item_names[i]) + "0"
            obj_pos = self.sim.data.body_xpos[self.obj_body_id[obj_str]]
            dist = np.linalg.norm(gripper_site_pos - obj_pos)
            r_reach = 1 - np.tanh(10.0 * dist)
            self.objects_in_bins[i] = int(
                (not self.not_in_bin(obj_pos, i)) and r_reach < 0.6
            )

        # returns True if a single object is in the correct bin
        if self.single_object_mode == 1 or self.single_object_mode == 2:
            return np.sum(self.objects_in_bins) > 0

        # returns True if all objects are in correct bins
        return np.sum(self.objects_in_bins) == len(self.ob_inits) 
開發者ID:StanfordVL,項目名稱:robosuite,代碼行數:24,代碼來源:sawyer_pick_place.py

示例4: draw_value_reward_score

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def draw_value_reward_score(self, img, value, reward, score):
    img = img.copy()
    # Average with 0.5 for semi-transparent background
    img[:14] = img[:14] * 0.5 + 0.25
    img[50:] = img[50:] * 0.5 + 0.25
    if self.cfg.gan == 'ls':
      red = -np.tanh(float(score) / 1) * 0.5 + 0.5
    else:
      red = -np.tanh(float(score) / 10.0) * 0.5 + 0.5
    top = '%+.2f %+.2f' % (value, reward)
    cv2.putText(img, top, (3, 7), cv2.FONT_HERSHEY_SIMPLEX, 0.25,
                (1.0, 1.0 - red, 1.0 - red))
    score = '%+.3f' % score
    cv2.putText(img, score, (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.35,
                (1.0, 1.0 - red, 1.0 - red))
    return img 
開發者ID:yuanming-hu,項目名稱:exposure,代碼行數:18,代碼來源:net.py

示例5: forward

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def forward(self, inputs, context=None):
        mask_right = (inputs > self.cut_point)
        mask_left = (inputs < -self.cut_point)
        mask_middle = ~(mask_right | mask_left)

        outputs = torch.zeros_like(inputs)
        outputs[mask_middle] = torch.tanh(inputs[mask_middle])
        outputs[mask_right] = self.alpha * torch.log(self.beta * inputs[mask_right])
        outputs[mask_left] = self.alpha * -torch.log(-self.beta * inputs[mask_left])

        logabsdet = torch.zeros_like(inputs)
        logabsdet[mask_middle] = torch.log(1 - outputs[mask_middle] ** 2)
        logabsdet[mask_right] = torch.log(self.alpha / inputs[mask_right])
        logabsdet[mask_left] = torch.log(-self.alpha / inputs[mask_left])
        logabsdet = utils.sum_except_batch(logabsdet, num_batch_dims=1)

        return outputs, logabsdet 
開發者ID:bayesiains,項目名稱:nsf,代碼行數:19,代碼來源:nonlinearities.py

示例6: invert_bfgs

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def invert_bfgs(gen_model, invert_model, ftr_model, im, z_predict=None, npx=64):
    _f, z = invert_model
    nz = gen_model.nz
    if z_predict is None:
        z_predict = np_rng.uniform(-1., 1., size=(1, nz))
    else:
        z_predict = floatX(z_predict)
    z_predict = np.arctanh(z_predict)
    im_t = gen_model.transform(im)
    ftr = ftr_model(im_t)

    prob = optimize.minimize(f_bfgs, z_predict, args=(_f, im_t, ftr),
                             tol=1e-6, jac=True, method='L-BFGS-B', options={'maxiter': 200})
    print('n_iters = %3d, f = %.3f' % (prob.nit, prob.fun))
    z_opt = prob.x
    z_opt_n = floatX(z_opt[np.newaxis, :])
    [f_opt, g, gx] = _f(z_opt_n, im_t, ftr)
    gx = gen_model.inverse_transform(gx, npx=npx)
    z_opt = np.tanh(z_opt)
    return gx, z_opt, f_opt 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:22,代碼來源:iGAN_predict.py

示例7: expand

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def expand(self, X):
    """Binarize features.

    Parameters:
    ----------
    X: np.ndarray
      Features

    Returns:
    -------
    X: np.ndarray
      Binarized features

    """
    Xexp = []
    for i in range(X.shape[1]):
      for k in np.arange(0, self.max[i] + self.step, self.step):
        Xexp += [np.tanh((X[:, i] - k) / self.step)]
    return np.array(Xexp).T 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:21,代碼來源:transformers.py

示例8: sum_of_squares_error

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def sum_of_squares_error(xlist, tlist, w1, w2):
    """二乗誤差和を計算する"""
    error = 0.0
    for n in range(N):
        z = np.zeros(NUM_HIDDEN)
        y = np.zeros(NUM_OUTPUT)
        # バイアスの1を先頭に挿入
        x = np.insert(xlist[n], 0, 1)
        # 順伝播で出力を計算
        for j in range(NUM_HIDDEN):
            a = np.zeros(NUM_HIDDEN)
            for i in range(NUM_INPUT):
                a[j] += w1[j, i] * x[i]
            z[j] = np.tanh(a[j])

        for k in range(NUM_OUTPUT):
            for j in range(NUM_HIDDEN):
                y[k] += w2[k, j] * z[j]
        # 二乗誤差を計算
        for k in range(NUM_OUTPUT):
            error += 0.5 * (y[k] - tlist[n, k]) * (y[k] - tlist[n, k])
    return error 
開發者ID:aidiary,項目名稱:PRML,代碼行數:24,代碼來源:function_approximation.py

示例9: output

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def output(x, w1, w2):
    """xを入力したときのニューラルネットワークの出力を計算
    隠れユニットの出力も一緒に返す"""
    # 配列に変換して先頭にバイアスの1を挿入
    x = np.insert(x, 0, 1)
    z = np.zeros(NUM_HIDDEN)
    y = np.zeros(NUM_OUTPUT)
    # 順伝播で出力を計算
    for j in range(NUM_HIDDEN):
        a = np.zeros(NUM_HIDDEN)
        for i in range(NUM_INPUT):
            a[j] += w1[j, i] * x[i]
        z[j] = np.tanh(a[j])
    for k in range(NUM_OUTPUT):
        for j in range(NUM_HIDDEN):
            y[k] += w2[k, j] * z[j]
    return y, z 
開發者ID:aidiary,項目名稱:PRML,代碼行數:19,代碼來源:function_approximation.py

示例10: sum_of_squares_error

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def sum_of_squares_error(xlist, tlist, w1, w2):
    """二乗誤差和を計算する"""
    error = 0.0
    for n in range(N):
        z = np.zeros(NUM_HIDDEN)
        y = np.zeros(NUM_OUTPUT)
        # バイアスの1を先頭に挿入
        x = np.insert(xlist[n], 0, 1)
        # 順伝播で出力を計算
        for j in range(NUM_HIDDEN):
            a = np.zeros(NUM_HIDDEN)
            a[j] = np.dot(w1[j, :], x)
            z[j] = np.tanh(a[j])
        for k in range(NUM_OUTPUT):
            y[k] = np.dot(w2[k, :], z)
        # 二乗誤差を計算
        for k in range(NUM_OUTPUT):
            error += 0.5 * (y[k] - tlist[n, k]) * (y[k] - tlist[n, k])
    return error 
開發者ID:aidiary,項目名稱:PRML,代碼行數:21,代碼來源:animation.py

示例11: faster_call2

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def faster_call2(self, h, x):
        r_z_h_x = self.W_r_z_h(x)

        r_z_h = self.U_r_z(h)

        r_x, z_x, h_x = split_axis(r_z_h_x, (self.n_units, self.n_units * 2), axis=1)
        assert r_x.data.shape[1] == self.n_units
        assert z_x.data.shape[1] == self.n_units
        assert h_x.data.shape[1] == self.n_units

        r_h, z_h = split_axis(r_z_h, (self.n_units,), axis=1)
#         r = sigmoid.sigmoid(r_x + r_h)
#         z = sigmoid.sigmoid(z_x + z_h)
#         h_bar = tanh.tanh(h_x + self.U(sigm_a_plus_b_by_h(r_x, r_h, h)))
#         h_new = (1 - z) * h + z * h_bar
#         return h_new

        return compute_output_GRU(z_x, z_h, h_x, h, self.U(sigm_a_plus_b_by_h_fast(r_x, r_h, h))) 
開發者ID:fabiencro,項目名稱:knmt,代碼行數:20,代碼來源:faster_gru.py

示例12: run

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def run(gens_file, theshold=None, flip_r_e1=False):
    model = pickle.load(open("ckbc-demo/Bilinear_cetrainSize300frac1.0dSize200relSize150acti0.001.1e-05.800.RAND.tanh.txt19.pickle",  "r"))

    Rel = model['rel']
    We = model['embeddings']
    Weight = model['weight']
    Offset = model['bias']
    words = model['words_name']
    rel = model['rel_name']

    results = []

    if type(gens_file) == list:
        gens = []
        for file_name in gens_file:
            gens += open(file_name, "r").read().split("\n")
    else:
        gens = open(gens_file, "r").read().split("\n")

    formatted_gens = [tuple(i.split("\t")[:4]) for i in gens if i]

    for i, gen in enumerate(formatted_gens):
        if gen == ('s', 'r', 'o', 'minED'):
            continue
        if flip_r_e1:
            relation = "_".join(gen[1].split(" "))
            subject_ = "_".join(gen[0].split(" "))
        else:
            relation = "_".join(gen[0].split(" "))
            subject_ = "_".join(gen[1].split(" "))
        object_ = "_".join(gen[2].split(" "))
        result = score(subject_, object_, words, We, rel, Rel, Weight, Offset, relation)

        results.append((gen, result))

    return results 
開發者ID:atcbosselut,項目名稱:comet-commonsense,代碼行數:38,代碼來源:demo_bilinear.py

示例13: tanh

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def tanh(x):
    return np.tanh(x) 
開發者ID:wdxtub,項目名稱:deep-learning-note,代碼行數:4,代碼來源:13_weight_init_activation_histogram.py

示例14: score_function

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def score_function(self, x, W):

        y_predict = x[1:]
        for i in range(0, len(W), 1):
            y_predict = np.tanh(np.dot(np.hstack((1, y_predict)), W[i]))

        score = y_predict[0]

        return score 
開發者ID:fukuball,項目名稱:fuku-ml,代碼行數:11,代碼來源:NeuralNetwork.py

示例15: forward_process

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import tanh [as 別名]
def forward_process(self, x, y, W):
        forward_output = []
        pre_x = x
        for i in range(len(W)):
            pre_x = np.tanh(np.dot(pre_x, W[i]))
            forward_output.append(pre_x)
            pre_x = np.hstack((1, pre_x))
        return forward_output 
開發者ID:fukuball,項目名稱:fuku-ml,代碼行數:10,代碼來源:NeuralNetwork.py


注:本文中的numpy.tanh方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。