def visibility_graph(series):
g = nx.Graph() # convert list of magnitudes into list of tuples that hold the index
tseries = []
n = 0
for magnitude in series:
tseries.append((n, magnitude))
n += 1 '''add nodes'''
for i in range(len(tseries)):
(ta, ya) = tseries[i]
g.add_node(ta, mag=ya) '''add edges'''
for a, b in combinations(tseries, 2):
(ta, ya) = a
(tb, yb) = b
connect = True
if tb - ta > 1:
(tc, yc) = max(tseries[ta + 1:tb]) #我的算法
print(tc,yc)
if (yc > yb + (ya - yb) * ((tb - tc) / (tb - ta))):
connect = False # medium = tseries[ta+1 :tb] #别人的算法
# for tc, yc in medium:
# if yc > yb + (ya - yb) * ((tb - tc) / (tb - ta)):
# connect = False if connect:
g.add_edge(ta, tb) return g

在第22行中,由于tseires 变成了嵌入元组, 所以max(tseries[ta + 1:tb]) 会取下标最大的值, 而非最大的第二个元素.

[(0, 0.19024852355156963),
(1, 0.6660417262541884),
(2, 0.395523497583831),
(3, 0.19024852355156963)]

最新文章

  1. PHP核心技术与最佳实践——全局浏览
  2. 【poj2154】 Color
  3. Go语言实战 - revel框架教程之权限控制
  4. ViewStub的简单用法和说明
  5. COM中的线程模式
  6. 修改PUTTY支持保存密码
  7. springMVC 访问404
  8. 菜鸟学Linux命令:tar命令 压缩与解压缩
  9. devexpress13学习系列(四)PDFViewer(4)
  10. bind 方法实现
  11. Python性能鸡汤
  12. Java实现http服务器(一)
  13. linux之SQL语句简明教程---ORDER BY
  14. swift 创建tableView并实现协议
  15. 免费APP在线測试工具以及其用法
  16. protocol error, got 'n' as reply type byte
  17. MySQL锁与MVCC
  18. html5客户端本地存储之sessionStorage及storage事件
  19. linux下python3调用c代码或者python3调用c++代码
  20. jQuery绑定和解绑点击事件及重复绑定解决办法

热门文章

  1. 有关使用phpstudy搭建sqli-lab环境搭建时发生Uncaught Error: Call to undefined function mysql_connect()错误
  2. Linux配置安装
  3. comTest.json文件中内容,被NewsList.vue文件引入
  4. 输入python -m pip install --upgrade pip更新pip版本失败的解决办法
  5. Python的基本语法和数据类型(简明教程)
  6. caj文件转word
  7. 解决问题:当redis服务端断开的时候`进程会崩溃(转载6哥笔记)
  8. UVA1395 (最苗条的最小生成树)
  9. GNU Radio无线通信嗅探基础
  10. CQOI跳舞(网络流+二分答案)