Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSGA-II features Update on Optimizers/GeneticAlgorithm #12

Open
wants to merge 91 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
061058e
NSGA-II implementation with properly printing optimal solutions at th…
JunyungKim Feb 19, 2023
ab4315c
Unnecessary changes in DataSet.py have been removed.
JunyungKim Feb 19, 2023
8b7f5d3
Unnecessary changes in DataSet.py have been removed.
JunyungKim Feb 19, 2023
3fcde82
ZDT test is added.
JunyungKim Feb 22, 2023
15debe4
Optimizer.py and RavenSampled.py are updated after having regression …
JunyungKim Feb 24, 2023
64510df
minor update on Optimizer.py
JunyungKim Feb 24, 2023
b1f0c3f
temporary fix, not the way I want
Jimmy-INL Mar 11, 2023
52389c3
NSGA-II testing fiels (multiSum wConstratint and ZDT1) are added.
JunyungKim Mar 13, 2023
391b9c3
moving models, xmls, and trying to resolve GD after converting object…
Jimmy-INL Mar 14, 2023
da9e0dd
fixing simulated annealing to accept a list of objectives
Jimmy-INL Mar 21, 2023
1fd2175
fixing rook to compare infs
Jimmy-INL Mar 22, 2023
7cedf83
Merge branch 'junyung-Mohammad-NSGAII' into JunyungKim-junyung-Mohamm…
Jimmy-INL Mar 22, 2023
305c2ac
making one mod in RAVENSAmpled
Jimmy-INL Apr 1, 2023
c820eea
making self._minMax a list
Jimmy-INL Apr 3, 2023
21bf42d
erroring out if type is not in ['min', 'max']
Jimmy-INL Apr 3, 2023
e639803
updating HERON to b316024
Jimmy-INL Apr 3, 2023
12e11f0
Merge branch 'devel' into enablingMinMaxList
Jimmy-INL Apr 3, 2023
be64a4d
updating dependencies
Jimmy-INL Apr 4, 2023
ccde4d9
Merge branch 'enablingMinMaxList' of github.com:Jimmy-INL/raven into …
Jimmy-INL Apr 4, 2023
95682a1
removing a trailing space
Jimmy-INL Apr 4, 2023
c3688e2
removing windows line endings
Jimmy-INL Apr 4, 2023
e25cc37
change to unix ending
Jimmy-INL Apr 5, 2023
f0d1412
adding the zdt_model.py
Jimmy-INL Apr 5, 2023
c2ca46e
converting zdt to unix line endings
Jimmy-INL Apr 5, 2023
1f1b969
Juan's change to simulateData for the interface
Jimmy-INL Apr 6, 2023
c7aebf3
resolving diff based on different batch Size, thanks @wangcj05
Jimmy-INL Apr 6, 2023
64e97a9
converting SimukateData.py to unix line endings
Jimmy-INL Apr 8, 2023
b29661b
regolding to print all batches in MOO
Jimmy-INL Apr 11, 2023
9626956
slight mods
Jimmy-INL Apr 12, 2023
34d5cb2
regolding and reverting inf in fitness
Jimmy-INL Apr 12, 2023
e0df314
trying to add all outputs to the rlz
Jimmy-INL Apr 12, 2023
c0476f7
adding everything to bestPoint
Jimmy-INL Apr 13, 2023
81dc580
chenging type==str to len(self._objectVar) == 1
Jimmy-INL Apr 13, 2023
3f27965
removing unnecessary if statement, this needs revisiting
Jimmy-INL Apr 18, 2023
facf74e
modifying reverting cycle length to its value not the inverse
Jimmy-INL Apr 20, 2023
a92049c
simulateData updating cost model.
Jun 12, 2023
0faeb9c
minor change is made in ZDT1 test.
JunyungKim Jul 15, 2023
e9ea9a2
Merge branch 'enablingMinMaxList' of https://github.com/Jimmy-INL/rav…
JunyungKim Jul 17, 2023
dbad22c
myConstraints for MultiSum is updated.
JunyungKim Jul 27, 2023
699b3de
Two issues are resolved: population and objective value mismatch, min…
JunyungKim Aug 8, 2023
8cffedb
minor things are corrected. Nothing important.
JunyungKim Aug 8, 2023
9f4eecd
Additional minor changes are made. Nothing important.
JunyungKim Aug 8, 2023
2487621
Additional minor change is made. Nothing important.
JunyungKim Aug 8, 2023
3657634
fitness data structure is changed from data xarray to dataSet. It wor…
Aug 30, 2023
285575f
single objective optimization works well with three different types o…
Aug 31, 2023
7707f67
NSGA-II improvement is in progress.
Sep 4, 2023
a32a45c
fitness-based NSGA-II is in progress. min-min is working well with to…
Sep 6, 2023
a9577f4
NSGA-II fitness-based rank and CD calcuration is completed. Temporary…
Sep 7, 2023
9b42d7d
minor bugs are fixed.
Sep 10, 2023
f6ecb5f
Every type of fitness is now working with newly updated GA interface …
Sep 17, 2023
8a26285
multi-objective optimization using invLinear and logistics now works.
Sep 21, 2023
51eb867
constraint handling for single and multi objective optimization in _u…
Sep 21, 2023
061c3bc
1. If-else statement for survivorSelection in _useRealization is remo…
Sep 25, 2023
59d43e1
1. Mohammad's comments are reflected; 2. Unneccesary if-else statemen…
Sep 26, 2023
8fb32c3
1. missing descriptions of self are added.
Sep 26, 2023
4dc0e57
tournamentSelection method in parentSelectors.py is enhanced followin…
JunyungKim Oct 14, 2023
4f457fe
tournamemntSelection for multi-objective is completed. RouletteWheel …
JunyungKim Oct 15, 2023
9d27568
simpleKnapsackTournament optOut file is regoldened. Final solution is…
JunyungKim Oct 15, 2023
255b58f
Comments from Mohammad are reflected.
JunyungKim Jan 29, 2024
f1ad2b3
Minor fixes to the fitness though a list of objective and penalty wei…
Jimmy-INL Jan 29, 2024
fae31be
Merge branch 'Junyung-Jimmy-enablingMinMaxList' into JunyungLatest-en…
JunyungKim Jan 29, 2024
ea59893
Merge pull request #3 from Jimmy-INL/JunyungLatest-enablingMinMaxList
JunyungKim Jan 29, 2024
d23ef44
test file for multi-objective optimization changed: the number of ite…
JunyungKim Jan 29, 2024
44b0b54
method to convert InputData to XML node(s)
GabrielSoto-INL Feb 16, 2024
80161ee
fixing input docstring
GabrielSoto-INL Feb 16, 2024
df6b98d
Junyung-Jimmy-enablingMinMaxList_vf_desk is merged to most-updated de…
Feb 26, 2024
f564f29
devel is merged with enabling MinMaxList_vf_desk.
Mar 4, 2024
02a961e
Modifications are done: All unit tests and GeneticAlgorithms-related …
JunyungKim Mar 6, 2024
ed460f9
SimulateData.py is now identical with the one from devel branch.
JunyungKim Mar 6, 2024
f339bf3
GeneticAlgorithm.py is updated. new file beale_flipped2.py is added. …
JunyungKim Mar 6, 2024
261799a
Issues that RAVEN could not catch error when non-rankNCrowdingBased s…
JunyungKim Mar 20, 2024
0259e38
unit test for convertToXML
GabrielSoto-INL Mar 20, 2024
fc625db
Merge pull request #2264 from GabrielSoto-INL/inputDataToXML
dylanjm Mar 21, 2024
679ab96
Removing numexpr dependency. (#2287)
joshua-cogliati-inl Mar 26, 2024
d97a3d1
Add BayCal plugin (#2285)
wangcj05 Mar 26, 2024
ed708c7
LaTeX _ escape improvement (#2292)
joshua-cogliati-inl Apr 2, 2024
677b474
RAVEN Manual related changes only are made.
JunyungKim Apr 2, 2024
cf67660
Minor changes are made. Functionally identical, just for readibility …
JunyungKim Apr 2, 2024
916eda0
two methods related to survivorSelectors are moved to survivorSelecto…
JunyungKim Apr 2, 2024
366974e
Some comments are left in fitness.py for future reference. invLinear …
JunyungKim Apr 2, 2024
ceb701d
Some comments are left in fitness.py for future reference. invLinear …
JunyungKim Apr 2, 2024
35e65e7
Some comments are added/deleted.
JunyungKim Apr 2, 2024
c8ac5c9
some files in NSGAII folder which are already relocated to other fold…
JunyungKim Apr 2, 2024
ce0aaad
commentations and code cleaning is dnoe in GeneticAlgorithm.py. Funct…
JunyungKim Apr 2, 2024
cfd5b31
rlzDict in def _resolveNewGenerationMulti is updated to avoid SIMULAT…
JunyungKim Apr 3, 2024
9d8941c
user manual related update - Equation correction
JunyungKim Apr 3, 2024
a055d68
Merge branch 'devel' into Junyung-Jimmy-NSGAII-ManualUpdate-DefectsFix
JunyungKim Apr 3, 2024
580cad8
user manual related update - Equation correction
JunyungKim Apr 3, 2024
06f4a46
very minor change made for user manuel.
JunyungKim Apr 3, 2024
a903939
survivorSelection.py is created.
JunyungKim Apr 3, 2024
8482a39
contaminated HERON and TEAL is now back to RAVEN.
May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions ravenframework/Optimizers/GeneticAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
from .crossOverOperators.crossovers import returnInstance as crossoversReturnInstance
from .mutators.mutators import returnInstance as mutatorsReturnInstance
from .survivorSelectors.survivorSelectors import returnInstance as survivorSelectionReturnInstance
from .survivorSelectors import survivorSelectors
from .survivorSelectors import survivorSelectors
from .survivorSelection import survivorSelection as survivorSelectionProcess
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we have a folder called survivorSelectors and another called survivorSelection? Or did you mean to remove one?

from .fitness.fitness import returnInstance as fitnessReturnInstance
from .repairOperators.repair import returnInstance as repairReturnInstance

Expand Down Expand Up @@ -618,9 +617,9 @@ def multiConstraint(self, info, rlz):
g0 = np.zeros((np.shape(offSprings)[0],len(self._constraintFunctions)+len(self._impConstraintFunctions)))

g = xr.DataArray(g0,
dims=['chromosome','Constraint'],
coords={'chromosome':np.arange(np.shape(offSprings)[0]),
'Constraint':[y.name for y in (self._constraintFunctions + self._impConstraintFunctions)]})
dims=['chromosome','Constraint'],
coords={'chromosome':np.arange(np.shape(offSprings)[0]),
'Constraint':[y.name for y in (self._constraintFunctions + self._impConstraintFunctions)]})

for index,individual in enumerate(offSprings):
newOpt = individual
Expand Down Expand Up @@ -674,8 +673,8 @@ def _useRealization(self, info, rlz):

if self._activeTraj:
# Step 0 @ n-1: Survivor selection(rlz): Update population container given obtained children
survivorSelectionFuncs: dict = {1: survivorSelectors.singleObjSurvivorSelect, 2: survivorSelectors.multiObjSurvivorSelect}
survivorSelection = survivorSelectionFuncs.get(objInd, survivorSelectors.singleObjSurvivorSelect)
survivorSelectionFuncs: dict = {1: survivorSelectionProcess.singleObjSurvivorSelect, 2: survivorSelectionProcess.multiObjSurvivorSelect}
survivorSelection = survivorSelectionFuncs.get(objInd, survivorSelectionProcess.singleObjSurvivorSelect)
survivorSelection(self, info, rlz, traj, offSprings, offSpringFitness, objectiveVal, g)

# Step 1 @ n-1: Plot results
Expand Down
96 changes: 96 additions & 0 deletions ravenframework/Optimizers/survivorSelection/survivorSelection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2017 Battelle Energy Alliance, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Implementation of survivorSelection step for new generation
selection process in Genetic Algorithm.

Created Apr,3,2024
@authors: Mohammad Abdo, Junyung Kim
"""
# External Modules----------------------------------------------------------------------------------
import numpy as np
import xarray as xr
from ravenframework.utils import frontUtils
# External Modules End------------------------------------------------------------------------------

# Internal Modules----------------------------------------------------------------------------------
from ...utils.gaUtils import dataArrayToDict, datasetToDataArray
# Internal Modules End------------------------------------------------------------------------------

# @profile

def singleObjSurvivorSelect(self, info, rlz, traj, offSprings, offSpringFitness, objectiveVal, g):
if self.counter == 1:
self.population = offSprings
self.fitness = offSpringFitness
self.objectiveVal = rlz[self._objectiveVar[0]].data
else:
self.population, self.fitness,\
self.popAge,self.objectiveVal = self._survivorSelectionInstance(age=self.popAge,
variables=list(self.toBeSampled),
population=self.population,
fitness=self.fitness,
newRlz=rlz,
offSpringsFitness=offSpringFitness,
popObjectiveVal=self.objectiveVal)

def multiObjSurvivorSelect(self, info, rlz, traj, offSprings, offSpringFitness, objectiveVal, g):
if self.counter == 1:
self.population = offSprings
self.fitness = offSpringFitness
self.constraintsV = g
# offspringObjsVals for Rank and CD calculation
offObjVal = []
for i in range(len(self._objectiveVar)):
offObjVal.append(list(np.atleast_1d(rlz[self._objectiveVar[i]].data)))

# offspringFitVals for Rank and CD calculation
fitVal = datasetToDataArray(self.fitness, self._objectiveVar).data
offspringFitVals = fitVal.tolist()
offSpringRank = frontUtils.rankNonDominatedFrontiers(np.array(offspringFitVals))
self.rank = xr.DataArray(offSpringRank,
dims=['rank'],
coords={'rank': np.arange(np.shape(offSpringRank)[0])})
offSpringCD = frontUtils.crowdingDistance(rank=offSpringRank,
popSize=len(offSpringRank),
objectives=np.array(offspringFitVals))

self.crowdingDistance = xr.DataArray(offSpringCD,
dims=['CrowdingDistance'],
coords={'CrowdingDistance': np.arange(np.shape(offSpringCD)[0])})
self.objectiveVal = []
for i in range(len(self._objectiveVar)):
self.objectiveVal.append(list(np.atleast_1d(rlz[self._objectiveVar[i]].data)))
else:
self.population,self.rank, \
self.popAge,self.crowdingDistance, \
self.objectiveVal,self.fitness, \
self.constraintsV = self._survivorSelectionInstance(age=self.popAge,
variables=list(self.toBeSampled),
population=self.population,
offsprings=rlz,
popObjectiveVal=self.objectiveVal,
offObjectiveVal=objectiveVal,
popFit = self.fitness,
offFit = offSpringFitness,
popConstV = self.constraintsV,
offConstV = g)

self._collectOptPointMulti(self.population,
self.rank,
self.crowdingDistance,
self.objectiveVal,
self.fitness,
self.constraintsV)
self._resolveNewGenerationMulti(traj, rlz, info)
68 changes: 0 additions & 68 deletions ravenframework/Optimizers/survivorSelectors/survivorSelectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,74 +33,6 @@

# @profile

def singleObjSurvivorSelect(self, info, rlz, traj, offSprings, offSpringFitness, objectiveVal, g):
if self.counter == 1:
self.population = offSprings
self.fitness = offSpringFitness
self.objectiveVal = rlz[self._objectiveVar[0]].data
else:
self.population, self.fitness,\
self.popAge,self.objectiveVal = self._survivorSelectionInstance(age=self.popAge,
variables=list(self.toBeSampled),
population=self.population,
fitness=self.fitness,
newRlz=rlz,
offSpringsFitness=offSpringFitness,
popObjectiveVal=self.objectiveVal)

def multiObjSurvivorSelect(self, info, rlz, traj, offSprings, offSpringFitness, objectiveVal, g):
if self.counter == 1:
self.population = offSprings
self.fitness = offSpringFitness
self.constraintsV = g
# offspringObjsVals for Rank and CD calculation
offObjVal = []
for i in range(len(self._objectiveVar)):
offObjVal.append(list(np.atleast_1d(rlz[self._objectiveVar[i]].data)))

# offspringFitVals for Rank and CD calculation
fitVal = datasetToDataArray(self.fitness, self._objectiveVar).data
offspringFitVals = fitVal.tolist()
offSpringRank = frontUtils.rankNonDominatedFrontiers(np.array(offspringFitVals))
self.rank = xr.DataArray(offSpringRank,
dims=['rank'],
coords={'rank': np.arange(np.shape(offSpringRank)[0])})
offSpringCD = frontUtils.crowdingDistance(rank=offSpringRank,
popSize=len(offSpringRank),
objectives=np.array(offspringFitVals))

self.crowdingDistance = xr.DataArray(offSpringCD,
dims=['CrowdingDistance'],
coords={'CrowdingDistance': np.arange(np.shape(offSpringCD)[0])})
self.objectiveVal = []
for i in range(len(self._objectiveVar)):
self.objectiveVal.append(list(np.atleast_1d(rlz[self._objectiveVar[i]].data)))
else:
self.population,self.rank, \
self.popAge,self.crowdingDistance, \
self.objectiveVal,self.fitness, \
self.constraintsV = self._survivorSelectionInstance(age=self.popAge,
variables=list(self.toBeSampled),
population=self.population,
offsprings=rlz,
popObjectiveVal=self.objectiveVal,
offObjectiveVal=objectiveVal,
popFit = self.fitness,
offFit = offSpringFitness,
popConstV = self.constraintsV,
offConstV = g)

self._collectOptPointMulti(self.population,
self.rank,
self.crowdingDistance,
self.objectiveVal,
self.fitness,
self.constraintsV)
self._resolveNewGenerationMulti(traj, rlz, info)




def ageBased(newRlz,**kwargs):
"""
ageBased survivorSelection mechanism for new generation selection.
Expand Down