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个 ...
随机推荐
- Html介绍,如何用代码展示我制作的第一个网页?
一般来说,第一次制作个人网页的朋友们,首句基本都是你好,全世界hello world 代码展示如下: <!DOCTYPE HTML> <html> <head> & ...
- windows2016_x64搭建ELK(datasource->filebeat->logstash->elasticsearch->kibana)
windows2016_x64搭建ELK(datasource->filebeat->logstash->elasticsearch->kibana) 本文示例日志程序基于as ...
- Win10的Cortana小娜反应慢?试试这个方法
https://www.ithome.com/html/win10/158466.htm Win10语音助手Cortana小娜可以为用户提供全面的搜索服务,不管是本地还是在线,都可以轻松找到结果.不过 ...
- 【笔记】机器学习 - 李宏毅 - 3 - Bias & Variance
A more complex model does not always lead to better performance on testing data. Because error due t ...
- Uva1213(线性筛模板+dp)
题意: 把n拆成k个不同素数的和,有多少种拆法. 解法: 打表后dp即可,这个dp的问题可以归纳为:在n个数中选k个数,使得和m的方案数 #include<cstdio> #include ...
- java Graphics2D绘制文字 本地正常服务器乱码问题
先贴关键代码: 用Graphics2D画文字到图片,再生成图片文件,在本地运行正常,一部署到服务器就不正常,变成了正方框如下图 解决问题思路: 1.部署服务器的编码问题. 2.代码问题. 以上两点一直 ...
- 项目在UAP可以直接启动,但是在eclipse上面不能直接启动
上面两个eclipse都是用友的开发人员给我的,左边是驻场开发给我的,但是没有教我怎么用和哪里好用,所以一直用UAP来做开发.右边的eclipse是提ISM问题,北京用友远程调试问题时给我的,而且终于 ...
- ES6 class(基本语法+方法)
静态属性与静态方法 1. 不会被类实例所拥有的属性与方法 只是类自身拥有2. 只能通过类调用 静态方法与普通方法重名,不会冲突static 关键字(静态方法) 静态属性类名.属性名 = 属性值; 1. ...
- Vue(三)--循环语句
v-for: v-for 指令需要以 site in sites 形式的特殊语法, sites 是源数据数组并且 site 是数组元素迭代的别名. demo1. <!DOCTYPE html&g ...
- 二分类模型之logistic
liner classifiers 逻辑回归用在2分类问题上居多.它是一个非线性的回归模型,其最大的好处恰恰是可以解决二元类问题,目前在金融行业,基本都是使用Logistic回归来预判一个用户是否为好 ...