python-2.7 - TensorVariable to Array
问题描述
I'm trying to evaluate a theano TensorValue expression:
import pymc3
import numpy as np
with pymc3.Model():
growth = pymc3.Normal('growth_%s' % 'some_name', 0, 10)
x = np.arange(4)
(x * growth).eval()
but get the error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/graph.py", line 522, in eval
self._fn_cache[inputs] = theano.function(inputs, self)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function.py", line 317, in function
output_keys=output_keys)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/pfunc.py", line 486, in pfunc
output_keys=output_keys)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 1839, in orig_function
name=name)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 1487, in __init__
accept_inplace)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 181, in std_fgraph
update_mapping=update_mapping)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 175, in __init__
self.__import_r__(output, reason="init")
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 346, in __import_r__
self.__import__(variable.owner, reason=reason)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 391, in __import__
raise MissingInputError(error_msg, variable=r)
theano.gof.fg.MissingInputError: Input 0 of the graph (indices start from 0), used to compute InplaceDimShuffle{x}(growth_some_name), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
I tried Can someone please help me see what the theano variables actually output? Thank you! I'm using Python 2.7 and theano 1.0.3
解决方案
虽然 PyMC3 分布是TensorVariable
对象,但它们在技术上没有任何值可以在采样之外进行评估。如果你想要值,你必须至少在模型上运行采样:
with pymc3.Model():
growth = pymc3.Normal('growth', 0, 10)
trace = pymc3.sample(10)
x = np.arange(4)
x[:, np.newaxis]*trace['growth']
如果要在采样期间查看节点值,则需要使用theano.tensor.printing.Print
对象。有关详细信息,请参阅PyMC3 调试提示。
推荐阅读
- android - ViewPager2 崩溃
- swiftui - 如何将 .onHover 应用于 SwiftUI 中的单个元素
- html - DOCX首页的不同边距
- python - ValueError:name_scope 的名称必须是字符串
- bouncycastle - 在 fuse esb 中添加 bouncycastle 提供程序
- vb.net - 在 wordwrap 为真的 Richtextbox 中查找每一行的宽度
- python - 从 PHP 文件运行 python 脚本
- python - 使用命名正则表达式在 pyspark 中格式化结构化的 Kafka 流
- r - 按 r 中的月份名称对向量进行排序
- authentication - NestJs 使用 jwt 和私钥和公钥进行身份验证