开发者

Chi-Square Test algorithm

开发者 https://www.devze.com 2023-01-22 14:29 出处:网络
I\'m randomly selecting nodes from a Binary Tree and I have to build a black-box test that proves all nodes have the nearly the same probability of being selected.

I'm randomly selecting nodes from a Binary Tree and I have to build a black-box test that proves all nodes have the nearly the same probability of being selected.

I'm adapting the Chi-Square test algorithm based on this article http://en.wikibooks.org/wiki/Algorithm_Implementation/Pseudorandom_Numbers/Chi-Square_Test but I'm a bit confused about 开发者_如何转开发what 'r' should be.

Just as a side question, do you think this is an appropriate algorithm to prove randomness in a set of results?

Thank you, Diogo


The answer is right there in the citation. Scroll down to the javadocs:

* @param  r           upper bound for the random range

It sounds to me like r ought to be the number of nodes in the tree. Do you agree?

I'm randomly selecting nodes from a Binary Tree and I have to build a black-box test that proves all nodes have the nearly the same probability of being selected.

I don't understand this. Do you? It seems less a test of the tree data structure and more about the random algorithm you use to choose a node to be selected. What does this outcome prove?

Walk me through what you're doing, please. Here's what I'm imagining:

  1. You have a list of nodes in your tree.
  2. You use a random algorithm somehow to choose a node to select from your tree.
  3. You iterate through your tree to find that node.

If there are r nodes in your tree, each one should have 1/r probability of being selected. It's a multi-dimensional, r-sided coin or die. Right?

The tree could bring another element into the mix: the probabilities are changed if the chances of being selected depend on where you are in the tree and whether or not you're allowed to backtrack. If that's the case, the chances of being selected are different at each node. Starting at the root means you can get to all child nodes. Being on the first level and not being able to backtrack eliminates the root and all other first level nodes from consideration, and so on.

Which problem are you trying to solve?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号