Skip to content

Commit a85e6a1

Browse files
committed
black
1 parent ae844dd commit a85e6a1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

causal_testing/estimation/genetic_programming_regression_fitter.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,14 @@ def fitness(self, expression: gp.PrimitiveTree) -> float:
284284

285285
# Create model, fit (run) it, give estimates from it]
286286
func = gp.compile(expression, self.pset)
287-
y_estimates = pd.Series([func(**x) for _, x in self.df[self.features].iterrows()], index=self.df.index)
287+
y_estimates = pd.Series(
288+
[func(**x) for _, x in self.df[self.features].iterrows()],
289+
index=self.df.index,
290+
)
288291

289292
# Calculate errors using root mean square error
290293
sqerrors = (self.df[self.outcome] - y_estimates) ** 2
291-
nrmse = np.sqrt(sqerrors.sum()/len(self.df))/(self.df[self.outcome].max() - self.df[self.outcome].min())
292-
294+
nrmse = np.sqrt(sqerrors.sum() / len(self.df)) / (self.df[self.outcome].max() - self.df[self.outcome].min())
293295

294296
if pd.isnull(nrmse) or nrmse.real != nrmse:
295297
return (float("inf"),)
@@ -329,7 +331,14 @@ def make_offspring(self, population: list, num_offspring: int) -> list:
329331
offspring.append(child)
330332
return offspring
331333

332-
def run_gp(self, ngen: int, pop_size: int = 20, num_offspring: int = 10, seeds: list = None, repair=True) -> gp.PrimitiveTree:
334+
def run_gp(
335+
self,
336+
ngen: int,
337+
pop_size: int = 20,
338+
num_offspring: int = 10,
339+
seeds: list = None,
340+
repair=True,
341+
) -> gp.PrimitiveTree:
333342
"""
334343
Execute Genetic Programming to find the best expression using a mu+lambda algorithm.
335344

0 commit comments

Comments
 (0)