我的目标是找到与道路(边缘)相关的给定城市(顶点)之间的最短路径(最低成本).每条道路和每个城市都有进入该道路/城市之前必须支付的费用(成本).
如果那将是完整的任务,我将使用Dijkstra算法来找到最短路径(并将城市成本添加到之前连接的道路的成本).
但是:
城市有类似合伙协议的东西 - 当你访问并支付其中一个时,在这个特殊合作关系中进入其他城市是免费的.
因此,顶点(在它之前连接的边)的成本取决于已经遍历的顶点.
这种问题有算法吗?
谢谢.
我有一些测试可以使用图形和会话.我还想用热切模式编写一些小测试来轻松测试一些功能.例如:
def test_normal_execution():
matrix_2x4 = np.array([[1, 2, 3, 4], [6, 7, 8, 9]])
dataset = tf.data.Dataset.from_tensor_slices(matrix_2x4)
iterator = dataset.make_one_shot_iterator()
first_elem = iterator.get_next()
with tf.Session() as sess:
result = sess.run(first_elem)
assert (result == [1, 2, 3, 4]).all()
sess.close()
Run Code Online (Sandbox Code Playgroud)
在另一个文件中:
def test_eager_execution():
matrix_2x4 = np.array([[1, 2, 3, 4], [6, 7, 8, 9]])
tf.enable_eager_execution()
dataset = tf.data.Dataset.from_tensor_slices(matrix_2x4)
iterator = dataset.__iter__()
first_elem = iterator.next()
assert (first_elem.numpy() == [1, 2, 3, 4]).all()
Run Code Online (Sandbox Code Playgroud)
有办法吗?ValueError: tf.enable_eager_execution must be called at program startup.当我试图急切地执行测试时,我得到了.我正在使用pytest我的测试.
编辑 …
我无法弄清楚Tensorlow的API路径模式是什么.我知道它可以在设置 - >工具 - > Python外部文档中的PyCharm中设置,但我不知道这个Tensorflow API的结构如何; 例如tensorflow.contrib.data.python.ops.dataset_ops.Dataset是在https://www.tensorflow.org/api_docs/python/tf/contrib/data/Dataset.有关API路径的一些约定吗?
鱼壳相当于什么mkdir -p foo/bar/baz/quux && cd $_?
我知道$history[1],但在这里我只需要上一个命令的最后一个参数。
在我的代码中,我想检查返回的对象类型是否为EagerTensor:
import tensorflow as tf
import inspect
if __name__ == '__main__':
tf.enable_eager_execution()
iterator = tf.data.Dataset.from_tensor_slices([[1, 2], [3, 4]]).__iter__()
elem = iterator.next()
print(type(elem))
print(inspect.getmodule(elem))
assert type(elem) == tf.python.framework.ops.EagerTensor
Run Code Online (Sandbox Code Playgroud)
但结果是:
<class 'EagerTensor'>
<module 'tensorflow.python.framework.ops' from '/home/antek/anaconda3/envs/mnist_identification/lib/python3.6/site-packages/tensorflow/python/framework/ops.py'>
Traceback (most recent call last):
File "/home/antek/.PyCharm2018.1/config/scratches/scratch_4.py", line 11, in <module>
assert type(elem) == tf.python.framework.ops.EagerTensor
AttributeError: module 'tensorflow' has no attribute 'python'
Run Code Online (Sandbox Code Playgroud)
这里:AttributeError: module 'tensorflow' has no attribute 'python'我发现 tensorflow 故意删除了它对 python 模块的引用。那么如何检查我的对象是否是 EagerTensor 实例?