简体   繁体   English

我如何在coursera中解决这个sigmoid function?

[英]how can i solve this sigmoid function in coursera?

how can i solve this?我该如何解决这个问题?

2.2 - Computing the Sigmoid Amazing. 2.2 - 计算 Sigmoid 惊人。 You just implemented a linear function.您刚刚实现了一个线性 function。 TensorFlow offers a variety of commonly used neural network functions like tf.sigmoid and tf.softmax, For this exercise. TensorFlow 提供了多种常用的神经网络函数,如 tf.sigmoid 和 tf.softmax,用于本练习。 compute the sigmoid of z.计算 z 的 sigmoid。

In this exercise, you will: Cast your tensor to type float32 using tf.cast, then compute the sigmoid using tf.keras.activations.sigmoid.在本练习中,您将: 使用 tf.cast 将您的张量类型转换为 float32,然后使用 tf.keras.activations.sigmoid 计算 sigmoid。

Exercise 2 - sigmoid Implement the sigmoid function below.练习 2 - sigmoid实现下面的 sigmoid function。 You should use the following:您应该使用以下内容:

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

This very easy Just google it otherwise See this below code it might help in your problem.这非常简单只需谷歌搜索,否则请参阅下面的代码,它可能对您的问题有所帮助。

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))

Well, you should figure out your assignment by yourself.. But it is written in the task:好吧,你应该自己弄清楚你的任务..但它是写在任务中的:

tf.cast("...", tf.float32) tf.keras.activations.sigmoid("...") tf.cast("...", tf.float32) tf.keras.activations.sigmoid("...")

They tell you everything by this line.他们通过这条线告诉你一切。 So the solution looks almost like this:所以解决方案看起来几乎是这样的:

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

You need to make small adjustment to the code, hope you will find it.您需要对代码进行一些小的调整,希望您能找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM