Skip to content

Commit

Permalink
Reverted test_population
Browse files Browse the repository at this point in the history
  • Loading branch information
alcides committed Oct 14, 2024
1 parent df52430 commit dfd6065
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions experiment/test_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,62 @@

root_dir = d(abspath(__file__))
sys.path.append(root_dir)
print("appended", root_dir, "to sys.path")
print('appended',root_dir,'to sys.path')

import importlib
from read_file import read_file

if "OMP_NUM_THREADS" not in os.environ.keys():
os.environ["OMP_NUM_THREADS"] = "1"
if "OPENBLAS_NUM_THREADS" not in os.environ.keys():
os.environ["OPENBLAS_NUM_THREADS"] = "1"
if "MKL_NUM_THREADS" not in os.environ.keys():
os.environ["MKL_NUM_THREADS"] = "1"
if 'OMP_NUM_THREADS' not in os.environ.keys():
os.environ['OMP_NUM_THREADS'] = '1'
if 'OPENBLAS_NUM_THREADS' not in os.environ.keys():
os.environ['OPENBLAS_NUM_THREADS'] = '1'
if 'MKL_NUM_THREADS' not in os.environ.keys():
os.environ['MKL_NUM_THREADS'] = '1'


def test_population(ml):
"""Sympy compatibility of model string"""

dataset = "test/192_vineyard_small.tsv.gz"
dataset = 'test/192_vineyard_small.tsv.gz'
random_state = 42

algorithm = importlib.__import__(
f"methods.{ml}.regressor",
globals(),
locals(),
["est", "hyper_params", "complexity"],
)

features, labels, feature_names = read_file(dataset, use_dataframe=True)
print("feature_names:", feature_names)
algorithm = importlib.__import__(f'methods.{ml}.regressor',globals(),
locals(),
['est','hyper_params','complexity'])

# generate train/test split
X_train, X_test, y_train, y_test = train_test_split(
features, labels, train_size=0.75, test_size=0.25, random_state=random_state
features, labels, feature_names = read_file(
dataset,
use_dataframe=True
)
print('feature_names:',feature_names)

# generate train/test split
X_train, X_test, y_train, y_test = train_test_split(features, labels,
train_size=0.75,
test_size=0.25,
random_state=random_state)

# Few samples to try to make it quick
sample_idx = np.random.choice(np.arange(len(X_train)), size=10)

y_train = y_train[sample_idx]
X_train = X_train.iloc[sample_idx]

algorithm.est.fit(X_train.values, y_train)

if "get_population" not in dir(algorithm):
if 'get_population' not in dir(algorithm):
algorithm.get_population = lambda est: [est]
if "get_best_solution" not in dir(algorithm):
if 'get_best_solution' not in dir(algorithm):
algorithm.get_best_solution = lambda est: est

population = algorithm.get_population(algorithm.est)
print(population, "pop", algorithm.est.get_population())
best_model = algorithm.get_best_solution(algorithm.est)
print(algorithm.model(best_model, X_train))
print(algorithm.est.predict(X_train.values))

# assert that population has at least 1 and no more than 100 individuals
assert (
1 <= len(population) <= 100
), "Population size is not within the expected range"

assert 1 <= len(population) <= 100, "Population size is not within the expected range"

for p in population:
print(population, algorithm.est, type(algorithm.est))
print(algorithm.model(p, X_train))
print(p.predict(X_train.values))

0 comments on commit dfd6065

Please sign in to comment.