嵌套类访问封闭类的私有数据成员(Nested class' access to enclosing class' private data members)
我在实现一个嵌套类的时候遇到了麻烦,它的构造函数是用一些封闭类的私有数据成员初始化的。
例:
Header File: class Enclosing { //...Public members //...Private members int x, int y class Inner; // Declaration for nested class }; Impl. File: // Stuff... class Enclosing::Inner { explicit Inner() : foo(x), bar(y) // foo and bar are data members of Inner //... };
我得到了
invalid use of non-static data member
错误的invalid use of non-static data member
。 当涉及到嵌套类访问其封闭类的成员时,是否有某些我错过了?I'm having trouble implementing a nested class who's constructor is initialized with some of the enclosing class' private data members.
Example:
Header File: class Enclosing { //...Public members //...Private members int x, int y class Inner; // Declaration for nested class }; Impl. File: // Stuff... class Enclosing::Inner { explicit Inner() : foo(x), bar(y) // foo and bar are data members of Inner //... };
I get an
invalid use of non-static data member
error. Is there something I'm missing when it comes to nested class access to its enclosing class' members?
原文:https://stackoverflow.com/questions/1604853
最满意答案
那么,它主要取决于你的特定实现和数据集。
一棵平衡不良的树意味着你必须搜索比你需要的更多的数据。 确保你的树木结构健全。
这也可能取决于你如何找到k个邻居。 如果你的算法搜索最近邻居的树并存储它,然后搜索第二个最近的邻居并存储它等,那么你不会非常有效地进行搜索。 相反,当您找到更近的遍历树的列表时,请将列表中的k个最近邻居列表和碰撞点列表从列表中移出。 这样你搜索一次,而不是k次。
无论哪种方式,这听起来像你正在做这个课程。 尝试与你的教授,助教或同学交谈,看看你的结果是否典型。
Well, it primarily depends on your particular implementation and data set.
A poorly balanced tree will mean you have to search way more data than you need to. Make sure that your tree construction is sane.
It could also depend on how you find the k neighbors. If your algorithm searches the tree for the closest neighbor and stores it, then searches for the second closest and stores it etc, then you're not doing the search very efficiently. Instead keep a running list of the k nearest neighbors and bump points out of the list as you find closer ones traversing the tree. This way you search once, instead of k times.
Either way, it sounds like you're doing this for a course. Try talking to your professor, TAs, or classmates to see if your results are typical.
相关问答
更多-
那么,它主要取决于你的特定实现和数据集。 一棵平衡不良的树意味着你必须搜索比你需要的更多的数据。 确保你的树木结构健全。 这也可能取决于你如何找到k个邻居。 如果你的算法搜索最近邻居的树并存储它,然后搜索第二个最近的邻居并存储它等,那么你不会非常有效地进行搜索。 相反,当您找到更近的遍历树的列表时,请将列表中的k个最近邻居列表和碰撞点列表从列表中移出。 这样你搜索一次,而不是k次。 无论哪种方式,这听起来像你正在做这个课程。 尝试与你的教授,助教或同学交谈,看看你的结果是否典型。 Well, it prim ...
-
我如何扩展这个SQL查询来查找k个最近的邻居?(How can I extend this SQL query to find the k nearest neighbors?)[2022-05-02]
如果从内部查询中删除TOP (1) WITH TIES ,并将外部查询设置为返回前k行,会发生什么情况? 我也很想知道这个修正案是否有帮助。 它应该比使用TOP更高效: DECLARE @start FLOAT = 1000 ,@k INT = 20 ,@p FLOAT = 2; WITH NearestPoints AS ( SELECT * ,T.g.STDistance(@x) AS dist ,ROW_NUM ... -
省略进口...我没有你的数据,所以我必须伪造一些... In [40]: x = np.random.random(100) In [41]: y = np.random.random(100) In [42]: z = np.random.random(100) In [43]: p = np.random.random(3) In [44]: p Out[44]: array([ 0.60515083, 0.39263392, 0.36129813]) 即三个坐标阵列和我将 ...
-
k是数据的维数 ,而n是数据集中的点数 。 因此,如果您的数据集包含1000万个点,并且每个点有3个维度,则k为3, n为1000万。 kd树不适合在高维度上找到最近邻居的原因与所谓的维度诅咒有关 。 kd树反复使用沿着单个维度的分割,但是当处理高维数据时,在一个维度上知道关于(欧几里得)距离的某些东西对于整个空间中的距离几乎没有说明。 想要超过2 k的数据集的原因非常直观:我们将数据集沿着每个维度分成两半大小相等的数据集。 如果我们的数据点少于2 k ,过了一段时间就没有更多的数据需要拆分了! 例如,如果 ...
-
使用pdist2 : A = rand(20,5); %// This is your 11795 x 88 B = A([1, 12, 4, 8], :); %// This is your n-by-88 subset, i.e. n=4 in this case n = size(B,1); D = pdist2(A,B); [~, ind] = sort(D); kneighbours = ind(2:2+k, :); 现在你可以使用kneighbours来索引A的 ...
-
我们在之前的项目中使用了一个宝石: https://rubygems.org/gems/kdtree 它还有一个线程安全的分支: https://rubygems.org/gems/tupalo-kdtree 也许在实现自己之前先看一下。 There's a gem that we used in a previous project: https://rubygems.org/gems/kdtree There's also a thread-safe fork of it: https://rubyge ...
-
我将建议使用具有KNeighborsClassifier的python库sklearn ,一旦适合,您可以检索您正在寻找的最近邻居: 试试这个: # Import from sklearn.neighbors import KNeighborsClassifier # Instanciate your classifier neigh = KNeighborsClassifier(n_neighbors=4) #k=4 or whatever you want # Fit your classifier ...
-
使用LineCollection一次绘制所有边,而不是逐个绘制它们: import numpy as np from scipy.spatial.distance import pdist, squareform from matplotlib import pyplot as plt from matplotlib.collections import LineCollection N = 250 X = np.random.rand(250,2) k = 4 # matrix of pairwise ...
-
R中的Knn回归(Knn Regression in R)[2022-02-27]
您只需在绘制线条之前对x值进行排序。 plot(x,y) ORD = order(grid2$x) lines(grid2$x[ORD],knn10$pred[ORD]) You just need to sort the x values before plotting the lines. plot(x,y) ORD = order(grid2$x) lines(grid2$x[ORD],knn10$pred[ORD]) -
在Matlab中为KNN选择k(Choosing k for KNN in Matlab)[2022-04-15]
你在这里有一个典型的模型选择问题。 你想要的是选择k ,它可以为你的数据提供最低的整体错误。 较大的k值更好地概括,较小的值可能倾向于过度拟合。 因此,交叉验证是选择此参数的好方法,我发现了这篇文章 ,这似乎是一种合理的方法。 What you have here is a typical model selection problem. What you want is to pick the k that gives you the lowest overall error on your data. ...