Skip to content
Snippets Groups Projects
Commit cc7a024b authored by Danilo Ferreira de Lima's avatar Danilo Ferreira de Lima
Browse files

Better use of multithreading.

parent c0995a34
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,4 @@
Estimate high-resolution photon spectrometer data from low-resolution non-invasive measurements.
"""
VERSION = "0.1.5"
VERSION = "0.1.6"
......@@ -623,7 +623,7 @@ class MultiOutputWithStd(MetaEstimatorMixin, BaseEstimator):
return self
def predict(self, X: np.ndarray, return_std: bool=False) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
def predict(self, X: np.ndarray, return_std: bool=False, n_jobs: Optional[int]=None) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
"""Predict multi-output variable using model for each target variable.
Args:
......@@ -634,7 +634,9 @@ class MultiOutputWithStd(MetaEstimatorMixin, BaseEstimator):
Multi-output targets predicted across multiple predictors.
Note: Separate models are generated for each predictor.
"""
y = Parallel(n_jobs=self.n_jobs)(
if n_jobs is None:
n_jobs = self.n_jobs
y = Parallel(n_jobs=n_jobs)(
delayed(e.predict)(X, return_std) for e in self.estimators_
#delayed(e.predict)(X) for e in self.estimators_
)
......@@ -698,7 +700,7 @@ class Model(TransformerMixin, BaseEstimator):
('pca', PCA(n_pca_hr, whiten=True)),
('unc', UncertaintyHolder()),
])
self.ood = {ch: IsolationForest()
self.ood = {ch: IsolationForest(n_jobs=-1)
for ch in channels+['full']}
#self.fit_model = MultiOutputWithStd(ARDRegression(n_iter=300, tol=1e-8, verbose=True), n_jobs=8)
self.fit_model = MultiOutputWithStd(BayesianRidge(n_iter=300, tol=1e-8, verbose=True), n_jobs=8)
......@@ -990,7 +992,7 @@ class Model(TransformerMixin, BaseEstimator):
"""
low_res_pre = self.x_select.transform(low_res_data)
low_pca = self.x_model.transform(low_res_pre)
high_pca, high_pca_unc = self.fit_model.predict(low_pca, return_std=True)
high_pca, high_pca_unc = self.fit_model.predict(low_pca, return_std=True, n_jobs=-1)
#high_pca = self.fit_model.predict(low_pca)
#high_pca_unc = 0
n_trains = high_pca.shape[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment