小编use*_*703的帖子

最小化Tensorflow中一个变量的功能

我是Tensorflow的新手,并且想知道是否可以使用Tensorflow最小化一个变量的函数.

例如,我们可以使用Tensorflow使用初始猜测(比如x = 1)来最小化2*x ^ 2 - 5 ^ x + 4吗?

我正在尝试以下方法:

import tensorflow as tf
import numpy as np

X = tf.placeholder(tf.float32, shape = ())
xvar = tf.Variable(np.random.randn())    
f = 2*mul(X,X) - 5*X + 4

opt = tf.train.GradientDescentOptimizer(0.5).minimize(f)

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    y = sess.run(opt, feed_dict = {X : 5.0}) #initial guess = 5.0
    print(y)
Run Code Online (Sandbox Code Playgroud)

但是这会产生以下错误:

ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables
Run Code Online (Sandbox Code Playgroud)

请帮我理解我在这里做错了什么.

python python-2.7 tensorflow

10
推荐指数
2
解决办法
4373
查看次数

将仪表板中的谷歌图表导出为png

我试图通过一个按钮将仪表板中的谷歌图表导出到png图像.但我得到以下错误 -

一个或多个参与者未能绘制()undefined不是一个函数

这是代码:

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the controls package.
      google.load('visualization', '1.0', {'packages':['controls']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawDashboard);

      // Callback that creates and populates a data table,
      // instantiates a dashboard, a range slider and a pie chart,
      // passes in the data and draws it.
      function drawDashboard() {

        // Create our data table.
        var data = …
Run Code Online (Sandbox Code Playgroud)

charts dashboard google-visualization

2
推荐指数
1
解决办法
7421
查看次数