gpt4 book ai didi

r - 获取R中一组点的上凸包

转载 作者:行者123 更新时间:2023-12-05 03:26:10 26 4
gpt4 key购买 nike

我试图在 R 中获取与生产力数据相关的一组点的上凸包。我希望它是一个规模 yield 递减的函数,输入是工时,输出是对完成工作的衡量。我想要上凸包,因为这能让我获得效率边界。

我搜索并找到了 R 中的 chull 方法,但这给出了整个包络中的点集,而不仅仅是上船体点。有没有办法自动选择 R 中的上船体点?

举个例子,我们可以找到在一个圆上生成的点的上壳

library(ggplot2)
# Generate random uniformly spaced points in the square space between (0,0) and (1,1)
x <- runif(10000, min = 0, max = 1)
y <- runif(10000, min = 0, max = 1)
df <- tibble(x,y)
# Filter out the points that don't lie inside a circle of radius 1
df %>% filter(!(x^2+y^2>1)) -> df
# Plot all the points in the above dataframe
ggplot(df, aes(x=x, y=y)) + geom_point()
# Compute the convex hull of the above points
newdf <- df[chull(df$x, df$y),]
# Plot the convex hull
ggplot(newdf, aes(x=x, y=y)) + geom_point()

完整的剧情是这样的 All the points within a circle

凸包看起来像这样 Conve Hull of above points

在这个例子中,upper hull 应该只给我圆的弯曲部分而不是轴

最佳答案

这里有一种方法是使用将x轴切割成小块的方法,然后为每个 block 计算mean(x)和max(y)...可以增加/减少 block 的数量,以获得更平滑(或更详细)的线条。

library(tidyverse)
df %>%
mutate(bin = cut(x, 10)) %>% # !! <-- increase/decrease value
group_by(bin) %>%
summarise(max_y = max(y, na.rm = TRUE),
x_max_y = mean(x, na.rm = TRUE)) %>%
ggplot(aes(x = x_max_y, y = max_y)) + geom_point()

enter image description here

n = 50 个 bin

enter image description here

关于r - 获取R中一组点的上凸包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71823980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com