elbow 求拐点
distancePointLine <- function(x, y, slope, intercept) {
## x, y is the point to test.
## slope, intercept is the line to check distance.
##
## Returns distance from the line.
##
## Returns 9999 on 0 denominator conditions.
x1 <- x-10
x2 <- x+10
y1 <- x1*slope+intercept
y2 <- x2*slope+intercept
distancePointSegment(x,y, x1,y1, x2,y2)
}
distancePointSegment <- function(px, py, x1, y1, x2, y2) {
## px,py is the point to test.
## x1,y1,x2,y2 is the line to check distance.
##
## Returns distance from the line, or if the intersecting point on the line nearest
## the point tested is outside the endpoints of the line, the distance to the
## nearest endpoint.
##
## Returns 9999 on 0 denominator conditions.
lineMagnitude <- function(x1, y1, x2, y2) sqrt((x2-x1)^2+(y2-y1)^2)
ans <- NULL
ix <- iy <- 0 # intersecting point
lineMag <- lineMagnitude(x1, y1, x2, y2)
if( lineMag < 0.00000001) {
warning("short segment")
return(9999)
}
u <- (((px - x1) * (x2 - x1)) + ((py - y1) * (y2 - y1)))
u <- u / (lineMag * lineMag)
if((u < 0.00001) || (u > 1)) {
## closest point does not fall within the line segment, take the shorter distance
## to an endpoint
ix <- lineMagnitude(px, py, x1, y1)
iy <- lineMagnitude(px, py, x2, y2)
if(ix > iy) ans <- iy
else ans <- ix
} else {
## Intersecting point is on the line, use the formula
ix <- x1 + u * (x2 - x1)
iy <- y1 + u * (y2 - y1)
ans <- lineMagnitude(px, py, ix, iy)
}
ans
}
###############################################
mydata = read.table('clipboard',header = T)
##########################
#mydata=cbind(c(1:15),wss)
#########################
datanumber = nrow(mydata)
mydist = c()
for(i in c(1:datanumber)){
d = as.numeric(c(mydata[i,],mydata[1,],mydata[datanumber,]))
mydist[i] = distancePointSegment(d[1],d[2],d[3],d[4],d[5],d[6])
}
mydist
max(mydist)
###############
#filternew = filter(mydist,filter = c(rep(1/datanumber,3)))
#plot(filternew)
################
elbowpoints = which(mydist==max(mydist))
plot(mydist)
abline(v=elbowpoints,lty=2,col='red')
plot(x=mydata[,1],y=mydata[,2],type='l')
elbowp = mydata[elbowpoints,1]
elbowp
abline(v=elbowp,lty=2,col='red')
elbow 求拐点的更多相关文章
- MT【293】拐点处切线
(2018浙江高考压轴题)已知函数$f(x)=\sqrt{x}-\ln x.$(2)若$a\le 3-4\ln 2,$证明:对于任意$k>0$,直线$y=kx+a$ 与曲线$y=f(x)$有唯一 ...
- [LeetCode] The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- Java for LeetCode 218 The Skyline Problem【HARD】
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- 【贪心】Vijos P1615 旅行
题目链接: https://vijos.org/p/1615 题目大意: N条路,路的高度给你,走一条路的耗费体力是从上一条路的高度到当前路高度的绝对值差. 可以改变一条路的高度,耗费的体力等于改变前 ...
- bzoj3393 [Usaco2009 Jan]Laserphones 激光通讯
Description Input 第1行输入w和H,之后W行H列输入地图,图上符号意义如题目描述. Output 最少的对角镜数量. Sample Input 7 8 ....... ...... ...
- 【模拟赛·polyline】
Input file: polyline.in Output file: polyline.out Time limit: 1s Memory limit: 128M 有若⼲个类似于下⾯的函数: 定义 ...
- 汕头市队赛 SRM 06 B 起伏的排名
B 起伏的排名 SRM 06 背景&&描述 天才麻将少女KPM立志要在日麻界闯出一番名堂. 在上个星期她打了n场麻将,每场麻将都有n名玩家.KPM自然记得自己的n次排名. ...
- noip2013 提高组
T1 转圈游戏 题目传送门 果不其然 第一题还是模拟题 一波快速幂解决问题 #include<cstdio> #include<cstring> #include<alg ...
- 花匠(codevs 3289)
题目描述 Description 花匠栋栋种了一排花,每株花都有自己的高度.花儿越长越大,也越来越挤.栋栋决定把这排中的一部分花移走,将剩下的留在原地,使得剩下的花能有空间长大,同时,栋栋希望剩下的花 ...
随机推荐
- Springboot的2种启动方式
sprigboot既可以直接通过main方法启动,也可以在tomcat里启动,在main方法里启动很简单,直接run启动类的main方法就可以了. 在tomcat里启动是需要配置一下的,需要实现以下S ...
- Telerik UI for ASP.NET AJAX控件汉化方法
Telerik UI for ASP.NET AJAX控件功能十分强大,但原版是英文界面的,不方便一些用户使用. 和.NET的其他控件一样,可以通过资源文件来制作多语言版本. 下面看看安装完成后原始的 ...
- day17 十七、时间模块
一.时间模块 import time print(time) # <module 'time' (built-in)> import time print('暂停开始') secs = t ...
- SQL Server 索引自动组织维护
公司的一个产品中的数据库,几个热点表因为主键和索引设计不合理,造成索引碎片过大,影响性能. 我尝试新建了一个索引碎片整理的定时任务,用于维护索引锁片和统计信息. 具体的过程如下: 本文原创,转发请表明 ...
- git diff 结果分析
git diff 的5个使用场景: 1.staging area和working area的文件 (无其他参数时) git diff 2.master分支和working area的文件 (用ma ...
- RoR - Expressing Database Relationships
One-to-One Association: *一个person只对应一个personal_info *一个personal_info只属于一个person *belongs to用foreign ...
- caffe编译报错 cudnn.hpp:127:41: error: too few arguments to function ‘cudnnStatus_t cudnnSetPooling2dDescriptor
转载自: https://blog.csdn.net/u011070171/article/details/52292680 这是因为当前版本的caffe的cudnn实现与系统所安装的cudnn的版本 ...
- vue 之 筛选功能实现
要实现的效果如下:根据输入框里面输入的内容筛选下面列表: 推荐实现代码如下:其中 allProductData 就是用来下拉列表的数据,allProductList 为从获取的所有列表的数据:
- 接口测试工具-Jmeter使用笔记(七:用户定义的变量)
使用场景:一组API根据业务流程制作成测试脚本,想要移植到其他测试环境时,由于数据库发生了变更,有些初始化数据也相应发生了变化,例如环境地址.请求路径等等.博主甚至把服务器地址和接口的部分共同请求路径 ...
- SpringMVC整合mybatis基于纯注解配置
Mybatis整合Spring配置 第一部分:配置Spring框架 配置SpringMVC的步骤 配置流程图 导入包(哪些包,基本包5个,1日志依赖包,2webmvc支持包)SpringMVC配置 & ...