my bug of VG algorithm
2024-10-08 11:12:01
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)]
最新文章
- PHP核心技术与最佳实践——全局浏览
- 【poj2154】 Color
- Go语言实战 - revel框架教程之权限控制
- ViewStub的简单用法和说明
- COM中的线程模式
- 修改PUTTY支持保存密码
- springMVC 访问404
- 菜鸟学Linux命令:tar命令 压缩与解压缩
- devexpress13学习系列(四)PDFViewer(4)
- bind 方法实现
- Python性能鸡汤
- Java实现http服务器(一)
- linux之SQL语句简明教程---ORDER BY
- swift 创建tableView并实现协议
- 免费APP在线測试工具以及其用法
- protocol error, got 'n' as reply type byte
- MySQL锁与MVCC
- html5客户端本地存储之sessionStorage及storage事件
- linux下python3调用c代码或者python3调用c++代码
- jQuery绑定和解绑点击事件及重复绑定解决办法
热门文章
- 有关使用phpstudy搭建sqli-lab环境搭建时发生Uncaught Error: Call to undefined function mysql_connect()错误
- Linux配置安装
- comTest.json文件中内容,被NewsList.vue文件引入
- 输入python -m pip install --upgrade pip更新pip版本失败的解决办法
- Python的基本语法和数据类型(简明教程)
- caj文件转word
- 解决问题:当redis服务端断开的时候`进程会崩溃(转载6哥笔记)
- UVA1395 (最苗条的最小生成树)
- GNU Radio无线通信嗅探基础
- CQOI跳舞(网络流+二分答案)