[英]how can i solve this sigmoid function in coursera?
我該如何解決這個問題?
2.2 - 計算 Sigmoid 驚人。 您剛剛實現了一個線性 function。 TensorFlow 提供了多種常用的神經網絡函數,如 tf.sigmoid 和 tf.softmax,用於本練習。 計算 z 的 sigmoid。
在本練習中,您將: 使用 tf.cast 將您的張量類型轉換為 float32,然后使用 tf.keras.activations.sigmoid 計算 sigmoid。
練習 2 - sigmoid實現下面的 sigmoid function。 您應該使用以下內容:
tf.cast("...", tf.float32)
tf.keras.activations.sigmoid("...")
# GRADED FUNCTION: sigmoid
def sigmoid(z):
"""
Computes the sigmoid of z
Arguments:
z -- input value, scalar or vector
Returns:
a -- (tf.float32) the sigmoid of z
"""
# tf.keras.activations.sigmoid requires float16, float32, float64, complex64, or complex128.
# (approx. 2 lines)
# z = ...
# a = ...
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
return a
這非常簡單只需谷歌搜索,否則請參閱下面的代碼,它可能對您的問題有所幫助。
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import math
def sigmoid(z):
return 1 / (1 + math.exp(-z))
print(sigmoid(0.5))
好吧,你應該自己弄清楚你的任務..但它是寫在任務中的:
tf.cast("...", tf.float32) tf.keras.activations.sigmoid("...")
他們通過這條線告訴你一切。 所以解決方案看起來幾乎是這樣的:
def sigmoid(z):
"""
Computes the sigmoid of z
Arguments:
z -- input value, scalar or vector
Returns:
a -- (tf.float32) the sigmoid of z
"""
# tf.keras.activations.sigmoid requires float16, float32, float64, complex64, or complex128.
# (approx. 2 lines)
# z = ...
# a = ...
# YOUR CODE STARTS HERE
z = tf.cast(z, tf.float32)
a = tf.keras.activations.sigmoid(INSERT Z VARIABLE HERE)
# YOUR CODE ENDS HERE
return a
您需要對代碼進行一些小的調整,希望您能找到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.