Skip to content

Commit

Permalink
Addressing issue idaholab#2427: making the crowding distance of the r…
Browse files Browse the repository at this point in the history
…epeaqted boundry points on the nondominated fronts infinity
  • Loading branch information
Jimmy-INL committed Jan 18, 2025
1 parent 2022286 commit 71e36ec
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 255 deletions.
22 changes: 16 additions & 6 deletions ravenframework/utils/frontUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def crowdingDistance(rank, popSize, fitness):
@ In, fitness, np.array, matrix contains fitness values for each element of the population
@ Out, crowdDist, np.array, array of crowding distances
"""
if isinstance(rank,xr.DataArray):
if isinstance(rank, xr.DataArray):
rank = rank.data
crowdDist = np.zeros(popSize)
fronts = np.unique(rank)
Expand All @@ -126,7 +126,6 @@ def crowdingDistance(rank, popSize, fitness):
frontIndices[r].append(i)

for f in fronts:
# front = np.where(rank == f)[0] # Get indices of current front
front = frontIndices[f] # Get indices of current front
numObjectives = fitness.shape[1]
numPoints = len(front)
Expand All @@ -143,6 +142,16 @@ def crowdingDistance(rank, popSize, fitness):
crowdDist[sortedFront[0]] = np.inf
crowdDist[sortedFront[-1]] = np.inf

# Ensure all repeated boundary points are set to infinity
boundaryValueMin = fitness[sortedFront[0], obj]
boundaryValueMax = fitness[sortedFront[-1], obj]

for i in range(1, numPoints - 1):
if fitness[sortedFront[i], obj] == boundaryValueMin:
crowdDist[sortedFront[i]] = np.inf
if fitness[sortedFront[i], obj] == boundaryValueMax:
crowdDist[sortedFront[i]] = np.inf

# Skip normalization if all values are identical
fMax = fitness[sortedFront, obj].max()
fMin = fitness[sortedFront, obj].min()
Expand All @@ -151,7 +160,8 @@ def crowdingDistance(rank, popSize, fitness):

# Calculate normalized distances with epsilon protection
for i in range(1, numPoints - 1):
nextObjValue = fitness[sortedFront[i + 1], obj]
prevObjValue = fitness[sortedFront[i - 1], obj]
crowdDist[sortedFront[i]] += (nextObjValue - prevObjValue) / (fMax - fMin)
return crowdDist
if crowdDist[sortedFront[i]] != np.inf:
nextObjValue = fitness[sortedFront[i + 1], obj]
prevObjValue = fitness[sortedFront[i - 1], obj]
crowdDist[sortedFront[i]] += (nextObjValue - prevObjValue) / (fMax - fMin)
return crowdDist
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
x1,x2,x3,obj1,obj2,age,batchId,rank,CD,FitnessEvaluation_obj1,FitnessEvaluation_obj2,accepted
3.0,2.0,4.0,19.0,7.0,0.0,1.0,3.0,inf,-19.0,7.0,first
3.0,2.0,4.0,19.0,7.0,0.0,1.0,3.0,0.0,-19.0,7.0,first
3.0,2.0,4.0,19.0,7.0,0.0,1.0,3.0,inf,-19.0,7.0,first
3.0,4.0,2.0,17.0,11.0,0.0,1.0,1.0,inf,-17.0,11.0,first
2.0,3.0,4.0,20.0,8.0,0.0,1.0,3.0,inf,-20.0,8.0,first
4.0,2.0,3.0,17.0,8.0,0.0,1.0,2.0,inf,-17.0,8.0,first
Expand All @@ -12,42 +12,42 @@ x1,x2,x3,obj1,obj2,age,batchId,rank,CD,FitnessEvaluation_obj1,FitnessEvaluation_
4.0,3.0,2.0,16.0,10.0,1.0,2.0,1.0,inf,-17.0,11.0,accepted
2.0,3.0,4.0,20.0,8.0,1.0,2.0,1.0,inf,-17.0,11.0,accepted
4.0,3.0,2.0,16.0,10.0,1.0,2.0,1.0,inf,-16.0,10.0,accepted
3.0,2.0,4.0,19.0,7.0,1.0,2.0,1.0,0.0,-16.0,10.0,accepted
3.0,2.0,4.0,19.0,7.0,1.0,2.0,1.0,inf,-16.0,10.0,accepted
4.0,3.0,2.0,16.0,10.0,1.0,2.0,1.0,inf,-16.0,10.0,accepted
3.0,2.0,4.0,19.0,7.0,1.0,2.0,2.0,inf,-17.0,8.0,accepted
2.0,3.0,4.0,20.0,8.0,1.0,2.0,2.0,inf,-19.0,10.0,accepted
3.0,2.0,4.0,19.0,7.0,1.0,2.0,2.0,inf,-19.0,10.0,accepted
2.0,3.0,4.0,20.0,8.0,1.0,2.0,3.0,inf,-19.0,7.0,accepted
3.0,2.0,4.0,19.0,7.0,1.0,2.0,3.0,inf,-20.0,8.0,accepted
3.0,2.0,4.0,19.0,7.0,1.0,2.0,3.0,inf,-19.0,7.0,accepted
3.0,2.0,4.0,19.0,7.0,0.0,3.0,1.0,inf,-17.0,11.0,accepted
4.0,2.0,3.0,17.0,8.0,0.0,3.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,0.0,3.0,1.0,0.0,-16.0,10.0,accepted
2.0,4.0,3.0,19.0,10.0,0.0,3.0,1.0,0.0,-17.0,11.0,accepted
4.0,2.0,3.0,17.0,8.0,0.0,3.0,1.0,inf,-17.0,11.0,accepted
2.0,3.0,4.0,20.0,8.0,0.0,3.0,1.0,inf,-16.0,10.0,accepted
2.0,4.0,3.0,19.0,10.0,0.0,3.0,2.0,inf,-17.0,8.0,accepted
2.0,3.0,4.0,20.0,8.0,0.0,3.0,2.0,inf,-19.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,0.0,3.0,1.0,inf,-16.0,10.0,accepted
2.0,4.0,3.0,19.0,10.0,0.0,3.0,1.0,inf,-16.0,10.0,accepted
4.0,2.0,3.0,17.0,8.0,0.0,3.0,1.0,inf,-16.0,10.0,accepted
2.0,3.0,4.0,20.0,8.0,0.0,3.0,1.0,inf,-17.0,11.0,accepted
2.0,4.0,3.0,19.0,10.0,0.0,3.0,2.0,inf,-17.0,8.0,accepted
2.0,3.0,4.0,20.0,8.0,0.0,3.0,2.0,inf,-19.0,10.0,accepted
3.0,2.0,4.0,19.0,7.0,3.0,4.0,1.0,inf,-17.0,11.0,accepted
4.0,2.0,3.0,17.0,8.0,3.0,4.0,1.0,inf,-16.0,10.0,accepted
2.0,3.0,4.0,20.0,8.0,3.0,4.0,1.0,0.0,-16.0,10.0,accepted
4.0,2.0,3.0,17.0,8.0,3.0,4.0,1.0,0.0,-17.0,11.0,accepted
3.0,2.0,4.0,19.0,7.0,3.0,4.0,1.0,0.0,-16.0,10.0,accepted
4.0,2.0,3.0,17.0,8.0,3.0,4.0,1.0,0.0,-17.0,11.0,accepted
2.0,4.0,3.0,19.0,10.0,3.0,4.0,1.0,0.0,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,4.0,1.0,inf,-16.0,10.0,accepted
4.0,3.0,2.0,16.0,10.0,3.0,4.0,1.0,inf,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,4.0,2.0,inf,-17.0,8.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,5.0,1.0,inf,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,5.0,1.0,inf,-16.0,10.0,accepted
4.0,3.0,2.0,16.0,10.0,3.0,5.0,1.0,0.0,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,5.0,1.0,0.0,-17.0,11.0,accepted
4.0,2.0,3.0,17.0,8.0,3.0,5.0,1.0,0.0,-16.0,10.0,accepted
3.0,2.0,4.0,19.0,7.0,3.0,5.0,1.0,0.0,-17.0,11.0,accepted
4.0,3.0,2.0,16.0,10.0,3.0,5.0,1.0,0.0,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,5.0,1.0,0.0,-17.0,11.0,accepted
4.0,2.0,3.0,17.0,8.0,3.0,5.0,1.0,inf,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,5.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,3.0,5.0,1.0,inf,-17.0,11.0,final
4.0,3.0,2.0,16.0,10.0,3.0,5.0,1.0,inf,-16.0,10.0,final
2.0,4.0,3.0,19.0,10.0,0.0,3.0,2.0,inf,-19.0,10.0,accepted
2.0,3.0,4.0,20.0,8.0,0.0,3.0,2.0,inf,-17.0,8.0,accepted
3.0,4.0,2.0,17.0,11.0,0.0,4.0,1.0,inf,-17.0,11.0,accepted
4.0,3.0,2.0,16.0,10.0,0.0,4.0,1.0,inf,-17.0,11.0,accepted
3.0,2.0,4.0,19.0,7.0,0.0,4.0,1.0,inf,-16.0,10.0,accepted
4.0,2.0,3.0,17.0,8.0,0.0,4.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,0.0,4.0,1.0,inf,-16.0,10.0,accepted
4.0,3.0,2.0,16.0,10.0,0.0,4.0,1.0,inf,-17.0,11.0,accepted
3.0,2.0,4.0,19.0,7.0,0.0,4.0,1.0,inf,-17.0,11.0,accepted
4.0,3.0,2.0,16.0,10.0,0.0,4.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,0.0,4.0,1.0,inf,-17.0,11.0,accepted
4.0,3.0,2.0,16.0,10.0,0.0,4.0,1.0,inf,-16.0,10.0,accepted
4.0,2.0,3.0,17.0,8.0,1.0,5.0,1.0,inf,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-17.0,11.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-17.0,11.0,accepted
4.0,3.0,2.0,16.0,10.0,1.0,5.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-17.0,11.0,accepted
4.0,2.0,3.0,17.0,8.0,1.0,5.0,1.0,inf,-16.0,10.0,accepted
3.0,4.0,2.0,17.0,11.0,1.0,5.0,1.0,inf,-17.0,11.0,final
4.0,3.0,2.0,16.0,10.0,1.0,5.0,1.0,inf,-16.0,10.0,final

0 comments on commit 71e36ec

Please sign in to comment.