From dd36f40e57a4cfb0c29c086265bd2bd49560b14d Mon Sep 17 00:00:00 2001 From: Malinda Date: Thu, 30 Jun 2022 14:20:22 -0700 Subject: [PATCH 1/4] Utilize NumPy APIs more --- ravenframework/SupervisedLearning/MSR.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ravenframework/SupervisedLearning/MSR.py b/ravenframework/SupervisedLearning/MSR.py index aaa33d75d6..5eeeab84bc 100644 --- a/ravenframework/SupervisedLearning/MSR.py +++ b/ravenframework/SupervisedLearning/MSR.py @@ -552,9 +552,7 @@ def __evaluateLocal__(self,featureVals): ############# ## OR ############# - weights[key] = 0 - for idx in indices: - weights[key] += self.__kernel(dists[:,idx]/h) + weights[key] = np.sum([self.__kernel(dists[:,idx]/h) for idx in indices]) weights[key] ############# From 92a3d2c34f64454362c6ff35b154cbb15a7484ab Mon Sep 17 00:00:00 2001 From: Malinda Date: Thu, 30 Jun 2022 15:16:07 -0700 Subject: [PATCH 2/4] Remove loop and use join instead --- ravenframework/SupervisedLearning/GaussPolynomialRom.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ravenframework/SupervisedLearning/GaussPolynomialRom.py b/ravenframework/SupervisedLearning/GaussPolynomialRom.py index 695a6162b6..04abfca25f 100644 --- a/ravenframework/SupervisedLearning/GaussPolynomialRom.py +++ b/ravenframework/SupervisedLearning/GaussPolynomialRom.py @@ -465,9 +465,7 @@ def __trainLocal__(self,featureVals,targetVals): missing.append(pt) if len(missing)>0: msg='\n' - msg+='DEBUG missing feature vals:\n' - for i in missing: - msg+=' '+str(i)+'\n' + msg+='DEBUG missing feature vals:\n' + '\n'.join(map(lambda x:' '+str(x),missing))+ '\n' self.raiseADebug(msg) self.raiseADebug('sparse:',sgs) self.raiseADebug('solns :',fvs) From e4fa5ece8f5f37f11acf92aa7687abdbabeb0ec4 Mon Sep 17 00:00:00 2001 From: Malinda Date: Tue, 5 Jul 2022 01:53:39 -0700 Subject: [PATCH 3/4] use multi_dot --- ravenframework/contrib/pyDOE/var_regression_matrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ravenframework/contrib/pyDOE/var_regression_matrix.py b/ravenframework/contrib/pyDOE/var_regression_matrix.py index 7ae5549178..2108159d62 100755 --- a/ravenframework/contrib/pyDOE/var_regression_matrix.py +++ b/ravenframework/contrib/pyDOE/var_regression_matrix.py @@ -47,5 +47,5 @@ def var_regression_matrix(H, x, model, sigma=1): raise ValueError("model and DOE don't suit together") x_mod = build_regression_matrix(x, model) - var = sigma**2*np.dot(np.dot(x_mod.T, np.linalg.inv(np.dot(H.T, H))), x_mod) + var = sigma**2*np.linalg.multi_dot([x_mod.T, np.linalg.inv(np.dot(H.T, H)), x_mod]) return var From fb14e4df001bd1298ccf8f69ffa3066013511ea8 Mon Sep 17 00:00:00 2001 From: Malinda Date: Wed, 6 Jul 2022 12:35:42 -0700 Subject: [PATCH 4/4] define axis for np.sum --- ravenframework/SupervisedLearning/MSR.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ravenframework/SupervisedLearning/MSR.py b/ravenframework/SupervisedLearning/MSR.py index 5eeeab84bc..f2c22cbb89 100644 --- a/ravenframework/SupervisedLearning/MSR.py +++ b/ravenframework/SupervisedLearning/MSR.py @@ -552,7 +552,7 @@ def __evaluateLocal__(self,featureVals): ############# ## OR ############# - weights[key] = np.sum([self.__kernel(dists[:,idx]/h) for idx in indices]) + weights[key] = np.sum([self.__kernel(dists[:,idx]/h) for idx in indices], axis=0) weights[key] #############