Skip to content

Commit

Permalink
Remove _train abstract method
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjm committed Jun 1, 2023
1 parent 7fe54f8 commit 4495b14
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
22 changes: 11 additions & 11 deletions ravenframework/SupervisedLearning/SupervisedLearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def trainOnDictionary(self, tdict, indexMap):
self._localNormalizeData(values,names,feat)
# valueToUse can be either a matrix (for who can handle time-dep data) or a vector (for who can not)
if self.dynamicFeatures:
featureValues[:, :, cnt] = (valueToUse[:, :] - self.muAndSigmaFeatures[feat][0])/self.muAndSigmaFeatures[feat][1]
featureValues[:, :, cnt] = (valueToUse[:, :]- self.muAndSigmaFeatures[feat][0])/self.muAndSigmaFeatures[feat][1]
else:
featureValues[:,cnt] = ( (valueToUse[:,0] if len(valueToUse.shape) > 1 else valueToUse[:]) - self.muAndSigmaFeatures[feat][0])/self.muAndSigmaFeatures[feat][1]

Expand Down Expand Up @@ -795,16 +795,16 @@ def finalizeGlobalRomSegmentEvaluation(self, settings, evaluation, weights, slic
return evaluation
### END ROM Clustering ###

@abc.abstractmethod
def _train(self,featureVals,targetVals):
"""
Perform training on samples in featureVals with responses y.
For an one-class model, +1 or -1 is returned.
@ In, featureVals, {array-like, sparse matrix}, shape=[n_samples, n_features],
an array of input feature values
@ Out, targetVals, array, shape = [n_samples], an array of output target
associated with the corresponding points in featureVals
"""
# @abc.abstractmethod
# def _train(self,featureVals,targetVals):
# """
# Perform training on samples in featureVals with responses y.
# For an one-class model, +1 or -1 is returned.
# @ In, featureVals, {array-like, sparse matrix}, shape=[n_samples, n_features],
# an array of input feature values
# @ Out, targetVals, array, shape = [n_samples], an array of output target
# associated with the corresponding points in featureVals
# """

@abc.abstractmethod
def __confidenceLocal__(self,featureVals):
Expand Down
29 changes: 19 additions & 10 deletions ravenframework/utils/mathUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def numpyNearestMatch(findIn, val):

return returnMatch

def relativeDiff(f1, f2):
def relativeDiff(f1, f2, scaling='second'):
"""
Given two floats, safely compares them to determine relative difference.
@ In, f1, float, first value (the value to compare to f2, "measured")
Expand All @@ -449,16 +449,25 @@ def relativeDiff(f1, f2):
except ValueError:
raise RuntimeError(f'Provided argument to compareFloats could not be cast as a float! Second argument is {f2} type {type(f2)}')
diff = abs(diffWithInfinites(f1, f2))

# "scale" is the relative scaling factor
scale = f2
# protect against div 0
if f2 == 0.0:
# try using the "measured" for scale
if f1 != 0.0:
scale = f1
# at this point, they're both equal to zero, so just divide by 1.0
else:
scale = 1.0
if scaling == 'second':
scale = f2
#protect against div 0
if f2 == 0.0:
#try using the "measured" for scale
if f1 != 0.0:
scale = f1
# at this point, they're both equal to zero, so just divide by 1.0
else:
scale = 1.0
elif scaling == 'average':
scale = 0.5 * (f1 + f2)
if scale == 0:
scale = 1
else:
raise KeyError(f'Unrecognized relativeDiff scaling option: "{scaling}"')

if abs(scale) == np.inf:
# no mathematical rigor here, but typical algorithmic use cases
if diff == np.inf:
Expand Down

0 comments on commit 4495b14

Please sign in to comment.