Skip to content

Commit

Permalink
use check_random_state
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohjeah committed Jun 25, 2017
1 parent e52cb07 commit b7feea1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions few/few.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score, accuracy_score
from sklearn.preprocessing import Imputer
from sklearn.utils import check_random_state
from DistanceClassifier import DistanceClassifier
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -54,7 +55,7 @@ def __init__(self, population_size=50, generations=100,
ml = None, min_depth = 1, max_depth = 2, max_depth_init = 2,
sel = 'epsilon_lexicase', tourn_size = 2, fit_choice = None,
op_weight = False, max_stall=10, seed_with_ml = True, erc = False,
random_state=np.random.randint(9999999), verbosity=0,
random_state=None, verbosity=0,
scoring_function=None, disable_update_check=False,
elitism=True, boolean = False,classification=False,clean=False,
track_diversity=False,mdr=False,otype='f',c=True):
Expand Down Expand Up @@ -93,7 +94,7 @@ def __init__(self, population_size=50, generations=100,
self.max_stall = max_stall
self.seed_with_ml = seed_with_ml
self.erc = erc
self.random_state = random_state
self.random_state = check_random_state(random_state)
self.verbosity = verbosity
self.scoring_function = scoring_function
self.gp_generation = 0
Expand Down Expand Up @@ -164,7 +165,6 @@ def __init__(self, population_size=50, generations=100,
def fit(self, features, labels):
"""Fit model to data"""

np.random.seed(self.random_state)
# setup data
# imputation
if self.clean:
Expand Down Expand Up @@ -228,7 +228,7 @@ def fit(self, features, labels):
self.term_set.append(node('x',loc=i)) # features
# add ephemeral random constants if flag
if self.erc: # ephemeral random constants
self.term_set.append(node('k',value=np.random.rand()))
self.term_set.append(node('k',value=self.random_state.rand()))

# edit function set if boolean
if self.boolean or self.otype=='b': # include boolean functions
Expand Down Expand Up @@ -528,7 +528,7 @@ def init_pop(self,num_features=1):
elif p is not None:
# make program if pop is bigger than model componennts
make_program(p.stack,self.func_set,self.term_set,
np.random.randint(self.min_depth,
self.random_state.randint(self.min_depth,
self.max_depth+1),
self.otype)
p.stack = list(reversed(p.stack))
Expand All @@ -552,7 +552,7 @@ def init_pop(self,num_features=1):
p.stack = [node('x',loc=i)]
else:
make_program(p.stack,self.func_set,self.term_set,
np.random.randint(self.min_depth,
self.random_state.randint(self.min_depth,
self.max_depth+1),
self.otype)
p.stack = list(reversed(p.stack))
Expand All @@ -565,7 +565,7 @@ def init_pop(self,num_features=1):

else:
for I in pop.individuals:
depth = np.random.randint(self.min_depth,self.max_depth+1)
depth = self.random_state.randint(self.min_depth,self.max_depth+1)
# print("hex(id(I)):",hex(id(I)))
# depth = 2;
# print("initial I.stack:",I.stack)
Expand Down

0 comments on commit b7feea1

Please sign in to comment.