StackGP 0.0.15__tar.gz → 0.0.16__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stackgp-0.0.15 → stackgp-0.0.16}/PKG-INFO +1 -1
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP/StackGP.py +47 -4
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP.egg-info/PKG-INFO +1 -1
- {stackgp-0.0.15 → stackgp-0.0.16}/pyproject.toml +1 -1
- {stackgp-0.0.15 → stackgp-0.0.16}/LICENSE +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/README.md +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP/__init__.py +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP.egg-info/SOURCES.txt +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP.egg-info/dependency_links.txt +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP.egg-info/requires.txt +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/StackGP.egg-info/top_level.txt +0 -0
- {stackgp-0.0.15 → stackgp-0.0.16}/setup.cfg +0 -0
|
@@ -701,7 +701,7 @@ def alignGPModel(model, data, response): #Aligns a model
|
|
|
701
701
|
setModelQuality(newModel,data,response)
|
|
702
702
|
return newModel
|
|
703
703
|
alignGPModel.__doc__ = "alignGPModel(model, input, response) aligns a model such that response-a*f(x)+b are minimized over a and b"
|
|
704
|
-
def evolve(inputData, responseData, generations=100, ops=defaultOps(), const=defaultConst(), variableNames=[], mutationRate=79, crossoverRate=11, spawnRate=10, extinction=False,extinctionRate=10,elitismRate=
|
|
704
|
+
def evolve(inputData, responseData, generations=100, ops=defaultOps(), const=defaultConst(), variableNames=[], mutationRate=79, crossoverRate=11, spawnRate=10, extinction=False,extinctionRate=10,elitismRate=10,popSize=300,maxComplexity=100,align=True,initialPop=[],timeLimit=300,capTime=False,tourneySize=5,tracking=False,returnTracking=False,liveTracking=False,liveTrackingInterval=1,modelEvaluationMetrics=[fitness,stackGPModelComplexity],dataSubsample=False,samplingMethod=randomSubsample,alternateObjectives=[],alternateObjFrequency=10,allowEarlyTermination=False,earlyTerminationThreshold=0):
|
|
705
705
|
|
|
706
706
|
metrics=modelEvaluationMetrics
|
|
707
707
|
|
|
@@ -731,7 +731,7 @@ def evolve(inputData, responseData, generations=100, ops=defaultOps(), const=def
|
|
|
731
731
|
if allowEarlyTermination and min([mods[2][0] for mods in models])<=earlyTerminationThreshold:
|
|
732
732
|
print("Early termination at generation ", i)
|
|
733
733
|
break
|
|
734
|
-
if tracking or liveTracking:
|
|
734
|
+
if tracking or liveTracking or returnTracking:
|
|
735
735
|
bestFits.append(min([mods[2][0] for mods in paretoTournament(models)]))
|
|
736
736
|
if liveTracking and time.perf_counter()-ckTime>liveTrackingInterval:
|
|
737
737
|
ax.clear()
|
|
@@ -789,8 +789,10 @@ def evolve(inputData, responseData, generations=100, ops=defaultOps(), const=def
|
|
|
789
789
|
if align:
|
|
790
790
|
models=[alignGPModel(mods,fullInput,fullResponse) for mods in models]
|
|
791
791
|
|
|
792
|
-
if tracking:
|
|
793
|
-
bestFits.append(min([mods[2][0] for mods in paretoTournament(models)]))
|
|
792
|
+
if tracking or returnTracking:
|
|
793
|
+
bestFits.append(min([mods[2][0] for mods in paretoTournament(models)]))
|
|
794
|
+
if returnTracking:
|
|
795
|
+
return models, bestFits
|
|
794
796
|
plt.figure()
|
|
795
797
|
plt.plot(bestFits)
|
|
796
798
|
plt.title("Fitness over Time")
|
|
@@ -1237,6 +1239,47 @@ def runEpochs(x,y,epochs=5,**kwargs):
|
|
|
1237
1239
|
return sortModels(models)
|
|
1238
1240
|
|
|
1239
1241
|
|
|
1242
|
+
############################
|
|
1243
|
+
#Parallelization
|
|
1244
|
+
############################
|
|
1245
|
+
from joblib import Parallel, delayed
|
|
1246
|
+
def parallelEvolve(*args,n_jobs=-1,avail_cores=-1, **kwargs):
|
|
1247
|
+
if avail_cores==-1:
|
|
1248
|
+
try:
|
|
1249
|
+
avail_cores=len(os.sched_getaffinity(0))
|
|
1250
|
+
except:
|
|
1251
|
+
avail_cores=os.cpu_count()
|
|
1252
|
+
if n_jobs==-1:
|
|
1253
|
+
try:
|
|
1254
|
+
n_jobs=len(os.sched_getaffinity(0))
|
|
1255
|
+
except:
|
|
1256
|
+
n_jobs=os.cpu_count()
|
|
1257
|
+
|
|
1258
|
+
if "tracking" in kwargs and kwargs["tracking"]:
|
|
1259
|
+
kwargs["returnTracking"]=True
|
|
1260
|
+
|
|
1261
|
+
print(f"Running parallel evolution with {n_jobs} jobs.")
|
|
1262
|
+
if "liveTracking" in kwargs:
|
|
1263
|
+
print("Live tracking is not supported in parallel evolution, disabling live tracking.")
|
|
1264
|
+
kwargs["liveTracking"]=False
|
|
1265
|
+
|
|
1266
|
+
runs = Parallel(n_jobs=avail_cores, backend="loky")(delayed(evolve)(*args, **kwargs) for _ in range(n_jobs))
|
|
1267
|
+
if ("tracking" in kwargs and kwargs["tracking"]):
|
|
1268
|
+
runs, tracking = zip(*runs)
|
|
1269
|
+
# plot tracking for each job
|
|
1270
|
+
plt.figure(figsize=(12, 6))
|
|
1271
|
+
for i, track in enumerate(tracking):
|
|
1272
|
+
plt.plot(track, label=f'Job {i+1}')
|
|
1273
|
+
plt.title('Best Fitness Over Generations for Each Parallel Run')
|
|
1274
|
+
plt.xlabel('Generations')
|
|
1275
|
+
plt.ylabel('Best Fitness')
|
|
1276
|
+
if n_jobs <= 16: # Only show legend if there are a reasonable number of jobs
|
|
1277
|
+
plt.legend()
|
|
1278
|
+
plt.show()
|
|
1279
|
+
flat = [model for sublist in runs for model in sublist]
|
|
1280
|
+
return sortModels(flat)
|
|
1281
|
+
|
|
1282
|
+
|
|
1240
1283
|
############################
|
|
1241
1284
|
#Benchmarking
|
|
1242
1285
|
############################
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|