my bug of VG algorithm
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)]
my bug of VG algorithm的更多相关文章
- [poj2492]A Bug's Life(并查集+补集)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 34678 Accepted: 11339 D ...
- POJ 2492 A Bug's Life
传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- hdu A Bug's Life
题目意思:给定一系列数对,例如a和b,表示a和b不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况. 例如给定: 1 2 3 4 1 3 那这里就是说1和2不是同种性别 ...
- 给MySQL官方提交的bug report备忘
1. Bug #72215 When LOCK_plugin conflicts very much, one uninstall-audit-plugin operation crash htt ...
- How to implement an algorithm from a scientific paper
Author: Emmanuel Goossaert 翻译 This article is a short guide to implementing an algorithm from a scie ...
- POJ2492 A Bug's Life
Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 33833 Accepted: 11078 Description Ba ...
- POJ2586Y2K Accounting Bug(贪心 + 不好想)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12251 Accepted: 62 ...
- HNU 12833 Omar’s Bug(分情况讨论)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12833&courseid=268 解题报告:有个11个 ...
随机推荐
- VMware与Centos系统安装之重置root密码
VMware与Centos系统安装之重置root密码 今日任务 1.Linux发行版的选择 2.vmware创建一个虚拟机(centos) 3.安装配置centos7 4.xshell配置连接虚拟 ...
- kubernetes安装-二进制
主要参考https://github.com/opsnull/follow-me-install-kubernetes-cluster,采用Flanel和docker 系统信息 角色 系统 CPU C ...
- 剑指offer-面试题53_2-0~n-1中缺失的数字-二分查找
/* 题目: 寻找递增数组0~n-1中缺失的数字. */ /* 思路: 变形二分法. */ #include<iostream> #include<cstring> #incl ...
- opencv —— 在 VS 中的配置
添加一个新的 .cpp 文件到工程中 打开菜单栏视图中的属性管理器 选择 Debug|x64 ...
- Linux网络课程学习第五天
学习心得: 通过本章节课学习收获很多,不仅学会了使用vim编辑器以及编写简单的shell脚本.从一个从未接触过Linux系统的我一下学会并掌握了这么多自我感觉进步还是挺大的.但是还是要坚持学下去,毕竟 ...
- Uva1640(统计数字出现的次数)
题意: 统计两个整数a,b之间各个数字(0~9)出现的次数,如1024和1032,他们之间的数字有1024 1025 1026 1027 1028 1029 1030 1031 1032 总共有10个 ...
- ng-项目结构
ng启动过程 目录结构 . ├── e2e 端到端测试(暂且不关心) ├── node_modules npm安装的第三方包 ├── src 存放业务源码 ├── .angular-cli.json ...
- [HNOI2015]接水果[整体二分]
[HNOI2015]接水果 给出一个树上路径集合\(S\) 多次询问\(x,y\)中的\(k\)小值 如果你问我数列上那么我会 树上的话 树上差分了吧直接?- 令 \(st_x<st_y\) 1 ...
- 递归查询 start with connect by prior
1.语法:start with 子节点ID='...' connect by prior 子节点ID = 父节点ID 含义:查询结果我所有的后代节点(包括我) 例子: select id,parent ...
- layui radio手动选择失效的问题
var radio_types = document.getElementsByName("radio_type"); for (var i = 0; i < radio_t ...