def unfringe(self, alpha=0.05):
"""
This method decides whether to expand the suffix trie onto the fringe.
It does this by constructing a distribution of the utilities of all the current states and from one
that includes the current state as well fringe nodes that are on the unofficial leaf of the tree.
If the two distributions are sufficiently different then the state space is expanded to include all leaf nodes
currently in the tree. The distribution comparison is performed using a KS test.
"""
all_leaves = self.tree_leaves()
all_leaves_dist = list(map(lambda leaf: self.utility(leaf), all_leaves))
print(all_leaves_dist)
current_leaves = self.get_states()
current_dist = list(map(lambda leaf: self.utility(leaf), current_leaves))
print(current_dist)
D, p_value = test_result = ks_2samp(all_leaves_dist, current_dist)
print(D)
print(p_value)
if p_value < alpha or alpha < D:
for leaf in all_leaves:
if leaf.is_fringe:
leaf.set_fringe(False)
self._correct_fringe(leaf)
return True
else:
return False
评论列表
文章目录