From bb5aaa21245964ea8eaf0333d6cdba3c8f58dc93 Mon Sep 17 00:00:00 2001 From: Marek Jacob Date: Tue, 17 May 2016 15:59:02 +0200 Subject: [PATCH] Compare strings using the `==` operator. Checking for equal strings using `is` is not save. See https://stackoverflow.com/questions/2988017/string-comparison-in-python-is-vs Or play around with: ```python for i in xrange(10): print i, 'a'*i is 'a'*i ``` which gives me: ``` 0 False 1 True 2 False 3 False 4 False 5 False 6 False 7 False 8 False 9 False ``` --- pyKriging/krige.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyKriging/krige.py b/pyKriging/krige.py index 72a4bf3..77ebf73 100644 --- a/pyKriging/krige.py +++ b/pyKriging/krige.py @@ -366,7 +366,7 @@ def train(self, optimizer='pso'): rand.seed(int(time())) # If the optimizer option is PSO, run the PSO algorithm - if optimizer is 'pso': + if optimizer == 'pso': ea = inspyred.swarm.PSO(Random()) ea.terminator = self.no_improvement_termination ea.topology = inspyred.swarm.topologies.ring_topology @@ -383,7 +383,7 @@ def train(self, optimizer='pso'): final_pop.sort(reverse=True) # If not using a PSO search, run the GA - elif optimizer is 'ga': + elif optimizer == 'ga': ea = inspyred.ec.GA(Random()) ea.terminator = self.no_improvement_termination final_pop = ea.evolve(generator=self.generate_population, @@ -720,4 +720,4 @@ def adjrsquares(self, rsquared, obs): def chisquared(self, actual, observed): actual = np.array(actual) observed = np.array(observed) - return np.sum( np.abs( np.power( (observed-actual) ,2)/actual ) ) \ No newline at end of file + return np.sum( np.abs( np.power( (observed-actual) ,2)/actual ) )