Skip to content

Commit

Permalink
fix some linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-wisiol committed Jan 31, 2018
1 parent 0454fbb commit 174dbc3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pypuf/learner/evolution_strategies/reliability_based_cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class ReliabilityBasedCMAES(Learner):
CONST_EPSILON = 0.1
FREQ_ABORTION_CHECK = 50
FREQ_LOGGING = 1
APPROX_CHALLENGE_NUM = 10000
THRESHOLD_DIST = 0.25

# Semi-constant :-)
approx_challenge_num = 10000

def __init__(self, training_set, k, n, transform, combiner,
pop_size, limit_stag, limit_iter, random_seed, logger):
"""Initialize a Reliability based CMAES Learner for the specified LTF array
Expand Down Expand Up @@ -59,8 +61,8 @@ def __init__(self, training_set, k, n, transform, combiner,
self.num_learned = 0
self.logger = logger

if 2**n < self.APPROX_CHALLENGE_NUM:
self.APPROX_CHALLENGE_NUM = 2 ** n
if 2**n < self.approx_challenge_num:
self.approx_challenge_num = 2 ** n

def learn(self):
"""Compute a model according to the given LTF Array parameters and training set
Expand Down Expand Up @@ -163,7 +165,7 @@ def avoid_printing():
@staticmethod
def create_fitness_function(challenges, measured_rels, epsilon, transform, combiner):
"""Return a fitness function on a fixed set of challenges and corresponding reliabilities"""
this = __class__
this = ReliabilityBasedCMAES

def fitness(individual):
"""Return individuals sorted by their correlation coefficient as fitness"""
Expand All @@ -189,7 +191,7 @@ def calc_corr(reliabilities, measured_rels):
@staticmethod
def create_abortion_function(chains_learned, num_learned, transform, combiner, threshold):
"""Return an abortion function on a fixed set of challenges and LTFs"""
this = __class__
this = ReliabilityBasedCMAES
weight_arrays = chains_learned[:num_learned, :]
learned_ltf_arrays = list(this.build_individual_ltf_arrays(weight_arrays, transform, combiner))

Expand All @@ -199,7 +201,7 @@ def is_same_solution(solution):
return False
new_ltf_array = LTFArray(solution[np.newaxis, :], transform, combiner)
for current_ltf_array in learned_ltf_arrays:
dist = tools.approx_dist(current_ltf_array, new_ltf_array, this.APPROX_CHALLENGE_NUM)
dist = tools.approx_dist(current_ltf_array, new_ltf_array, this.approx_challenge_num)
if dist < threshold or dist > (1 - threshold):
return True
return False
Expand Down

0 comments on commit 174dbc3

Please sign in to comment.