def approx_stabilities(instance, num, reps, random_instance=RandomState()):
"""
This function approximates the stability of the given `instance` for
`num` challenges evaluating it `reps` times per challenge. The stability
is the probability that the instance gives the correct response when
evaluated.
:param instance: pypuf.simulation.base.Simulation
The instance for the stability approximation
:param num: int
Amount of challenges to be evaluated
:param reps: int
Amount of repetitions per challenge
:return: array of float
Array of the stabilities for each challenge
"""
challenges = sample_inputs(instance.n, num, random_instance)
responses = zeros((reps, num))
for i in range(reps):
challenges, unpacked_challenges = itertools.tee(challenges)
responses[i, :] = instance.eval(array(list(unpacked_challenges)))
return 0.5 + 0.5 * np_abs(np_sum(responses, axis=0)) / reps
评论列表
文章目录