- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有大量与重要性因素配对的 3d 点。
每个用户都有六分。例如:查理有 6 个点:(22,44,55) 是他的第一个点,重要性因子为 3,(10,0,0) 是他的第二个向量,重要性因子为 2.8,一直到他的第六点是 (100,300,200),重要性因子为 0.4。
我想做的是找到与查理最相似的人,而不是遍历所有其他人。基本上为每个用户最小化此功能(即,将该用户的正确六个点与查理匹配):
pythagoras(point, point2) * max(importance_factor, importance_factor2) * (abs(importance_factor - importance_factor2) + 1)
然后通过选择成本最低的用户来找到与查理最相似的用户。我现在已经以愚蠢的方式编写了代码(通过执行大量循环),但我正在寻找一种方法来正确处理存在多个点和重要性因素的事实。
我开始研究空间索引,但我认为它们不会起作用,因为我有多个点,但也许我可以将这些点展开到更高维度的点中?所以我可以在 18 维中有 1 个点,而不是 3 个维度中的 6 个点?仍然无法处理重要性因素,但总比没有好。
不幸的是,我不能在这里使用向量和余弦,因为 (1,1,1) 和 (400,400,400) 是非常相反的事物。
有什么想法吗?
最佳答案
既然你还没有得到任何答案,我想我至少会贡献一些想法。我使用了 python k-d 树模块来快速搜索最近邻点:
http://code.google.com/p/python-kdtree/downloads/detail?name=kdtree.py
只要它们的大小相同,它就可以采用任意点长度。
我不确定你想如何应用“重要性”的权重,但这里只是关于如何使用 kdtree 模块至少让最接近的“人”到给定的每个点的头脑 Storm 人设:
import numpy
from kdtree import KDTree
from itertools import chain
class PersonPoint(object):
def __init__(self, person, point, factor):
self.person = person
self.point = point
self.factor = factor
def __repr__(self):
return '<%s: %s, %0.2f>' % (self.person,
['%0.2f' % p for p in self.point], self.factor)
def __iter__(self):
return self.point
def __len__(self):
return len(self.point)
def __getitem__(self, i):
return self.point[i]
people = {}
for name in ('bill', 'john', 'mary', 'jenny', 'phil', 'george'):
factors = numpy.random.rand(6)
points = numpy.random.rand(6, 3).tolist()
people[name] = [PersonPoint(name, p, f) for p,f in zip(points, factors)]
bill_points = people['bill']
others = list(chain(*[people[name] for name in people if name != 'bill']))
tree = KDTree.construct_from_data(others)
for point in bill_points:
# t=1 means only return the 1 closest.
# You could set it higher to return more.
print point, "=>", tree.query(point, t=1)[0]
结果:
<bill: ['0.22', '0.64', '0.14'], 0.07> =>
<phil: ['0.23', '0.54', '0.11'], 0.90>
<bill: ['0.31', '0.87', '0.16'], 0.88> =>
<phil: ['0.36', '0.80', '0.14'], 0.40>
<bill: ['0.34', '0.64', '0.25'], 0.65> =>
<jenny: ['0.29', '0.77', '0.28'], 0.40>
<bill: ['0.24', '0.90', '0.23'], 0.53> =>
<jenny: ['0.29', '0.77', '0.28'], 0.40>
<bill: ['0.50', '0.69', '0.06'], 0.68> =>
<phil: ['0.36', '0.80', '0.14'], 0.40>
<bill: ['0.13', '0.67', '0.93'], 0.54> =>
<jenny: ['0.05', '0.62', '0.94'], 0.84>
我想出了这个结果,你可以看看最频繁匹配的“人”,或者再考虑权重。或者,也许您可以汇总结果中的重要因素,然后选择评分最高的因素。那样的话,如果 mary 只匹配一次但有 10 个因子,而 phil 有 3 个匹配但总计只有 5 个,mary 可能更相关?
我知道您有更强大的功能来创建索引,但它需要遍历集合中的每个点。
关于python - 需要一个合适的数据结构或索引,以便根据 3d 点和重要性因素快速查找用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555511/
如何更改循环中变量的名称?比如 number1 、 number2 、 number3 、 number4 ? var array = [2,4,6,8] func ap ( number1: Int
我想设置 View 的背景颜色并在一定延迟后将其更改为另一种颜色。这是我的尝试方式: print("setting color 1") self.view.backgroundColor = UICo
我在使用 express-session 时遇到问题。 session 数据不会在请求之间持续存在。 正如您在下面的代码中看到的那样,/join 路由设置了一些 session 属性,但是当 /sur
我试图从叶渲染器获得一个非常简单的结果,用于快速 Steam 的 for 循环。 我正在上传叶文件 HTML,因为它不接受此处格式正确的代码 - 下面的pizza.swift代码- import
你们中有人有什么好的链接可以与我分享吗?我正在寻找一个 FAST 程序员编辑器,它可以非常快速地打开包含超过 100, 000 行代码的文件?我目前正在使用记事本自动取款机,打开一个 29000 行长
我现在正在处理眼动追踪数据,因此拥有一个巨大的数据集(想想数百万行),因此希望有一种快速的方法来完成此任务。这是它的简化版本。 数据告诉您眼睛在每个时间点正在查看的位置以及我们正在查看的每个文件。 X
我是新手,想为计时器或其他设备选择提示音。 如何打开此列表,以选择其中一种声音? Alert sound list 最佳答案 您将无法在应用中使用系统声音。 但是,您可以包括自己的声音文件,并将其显示
我编写了以下代码来构建具有顺序字符串的数组。 它的工作方式与我预期的一样,但我希望它能更快地运行。有没有更有效的方法在PowerShell中产生我想要的结果? 我是PowerShell的新手,非常感谢
我有一个包含一些非唯一行的矩阵,例如: x 尝试 y <- rle(apply(x, 1, paste, collapse = " ")) # y$lengths is the vector con
我的函数“keyboardWillShown”有问题。所以我想要的是菜单打开时,菜单正好出现在键盘上方。它可以在Iphone 8 plus,8、7、6上完美运行。但是,当我在模拟器上运行Iphone
我正在尝试通过Swift 5中的HTTP get方法从API提取数据。它在启动时成功加载了数据,但是当我刷新页面时,它说“索引超出范围”,这是因为数据是不再会在我的日志中读取,因此索引中没有任何内容。
我想做什么: 从我的数据库中获取时间戳并将其转换为用户的时区。 我的代码: let tryItNow = "\(model.timestampName)" let format = D
给定字体名称和字体大小,如何查找字符串的宽度(CGFloat)? (目标是将UIView的宽度设置为足以容纳字符串的宽度。) 我有两个字符串:一个重复“1”,重复36次,另一个重复“M”,重复36次。
我正在尝试解析此JSON ["Items": ( { AccountBalance = 0; AlphabetType = 3; Description = "\U0631\U
我在UINavigationBar内放置了一个UILabel。 我想根据navigationBar的高度增加该标签的字体大小。当navigationBar很大时,我希望字体大小更大;当滚动并缩小nav
我想将用户输入限制为仅有效数字并使用以下内容: func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, rep
目前我有一个包含超过 100.000 张图像的数据库,它们大小不一或类似,但我想为我的公司制作以下内容: 我插入/上传一张图片,系统返回最有可能相同的图片。我不知道使用什么算法,但它需要快速。我可以预
在我的 swift 项目中,我有一个按钮,我想在标签上打印按下该按钮的时间。 如何解决这个问题? 最佳答案 添加到DHEERAJ的答案中,您只需在func press(sender: UIButton
我必须发表评论,尝试在解析中导入数组。然而,有一个问题。 当我尝试从 Parse 加载数组时,我的输出是 ("Blah","Blah","Blah")这是一个元组...而不是一个数组 TT... 如何
我的应用程序有一个名为 MyDevice 的类,我用它来与硬件通信。该硬件是可选的,实例变量也是可选的: var theDevice:MyDevice = nil 然后,在应用程序中,我必须初始化设备
我是一名优秀的程序员,十分优秀!