dcekit 2.18.1__tar.gz → 2.18.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dcekit-2.18.1/dcekit.egg-info → dcekit-2.18.2}/PKG-INFO +1 -1
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/generative_model/gmr.py +97 -34
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/generative_model/vbgmr.py +97 -34
- {dcekit-2.18.1 → dcekit-2.18.2/dcekit.egg-info}/PKG-INFO +1 -1
- {dcekit-2.18.1 → dcekit-2.18.2}/setup.py +1 -1
- {dcekit-2.18.1 → dcekit-2.18.2}/LICENSE +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/LICENSE.txt +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/MANIFEST.in +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/README.md +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/design_of_exmeriments/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/design_of_exmeriments/bayesian_optimization.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/generative_model/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/generative_model/gtm.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/generative_model/ssgmr_xgmm.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/generative_model/ssgmr_xgmm_xma.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/just_in_time/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/just_in_time/jitpls.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/just_in_time/lwpls.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/learning/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/learning/ensemble_learning.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/learning/semi_supervised_learning.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/learning/transfer_learning.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/optimization/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/optimization/fast_opt_svr_hyperparams.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/optimization/iot.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/optimization/opt_dnn_hyperparams.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/optimization/opt_dnn_hyperparams_class.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/sampling/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/sampling/kennard_stone.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/validation/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/validation/applicability_domain.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/validation/metrics.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/validation/validation.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/variable_selection/__init__.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/variable_selection/basic_variable_selection.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/variable_selection/local_interpretation.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit/variable_selection/variable_importance.py +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit.egg-info/SOURCES.txt +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit.egg-info/dependency_links.txt +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit.egg-info/requires.txt +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/dcekit.egg-info/top_level.txt +0 -0
- {dcekit-2.18.1 → dcekit-2.18.2}/setup.cfg +0 -0
|
@@ -32,6 +32,79 @@ class GMR(GaussianMixture):
|
|
|
32
32
|
|
|
33
33
|
self.rep = rep
|
|
34
34
|
self.display_flag = display_flag
|
|
35
|
+
|
|
36
|
+
def _calculate_logpdfs_and_weights(self, dataset, input_means, input_covariances):
|
|
37
|
+
"""
|
|
38
|
+
Calculate posterior component weights in log-space.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
dataset : numpy.ndarray
|
|
43
|
+
Input samples, shape = (n_samples, n_input_variables)
|
|
44
|
+
input_means : numpy.ndarray
|
|
45
|
+
Means of input variables, shape = (n_components, n_input_variables)
|
|
46
|
+
input_covariances : numpy.ndarray
|
|
47
|
+
Covariance matrices of input variables,
|
|
48
|
+
shape = (n_components, n_input_variables, n_input_variables)
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
weights : numpy.ndarray
|
|
53
|
+
Posterior weights, shape = (n_components, n_samples)
|
|
54
|
+
logpdfs : numpy.ndarray
|
|
55
|
+
Component-wise log density of input variables,
|
|
56
|
+
shape = (n_components, n_samples)
|
|
57
|
+
log_normalizer : numpy.ndarray
|
|
58
|
+
log p(x) for each sample, shape = (n_samples,)
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
n_samples = dataset.shape[0]
|
|
62
|
+
|
|
63
|
+
# log N(x | mu_x,k, Sigma_xx,k)
|
|
64
|
+
logpdfs = np.full([self.n_components, n_samples], -np.inf)
|
|
65
|
+
|
|
66
|
+
for component_number in range(self.n_components):
|
|
67
|
+
try:
|
|
68
|
+
logpdfs[component_number, :] = multivariate_normal.logpdf(
|
|
69
|
+
dataset,
|
|
70
|
+
mean=input_means[component_number, :],
|
|
71
|
+
cov=input_covariances[component_number, :, :]
|
|
72
|
+
)
|
|
73
|
+
except Exception:
|
|
74
|
+
print('assignment of logpdfs is failed, and -inf is assigned')
|
|
75
|
+
|
|
76
|
+
# log pi_k
|
|
77
|
+
log_priors = np.full(self.n_components, -np.inf)
|
|
78
|
+
positive_prior_flags = self.weights_ > 0
|
|
79
|
+
log_priors[positive_prior_flags] = np.log(self.weights_[positive_prior_flags])
|
|
80
|
+
log_priors = log_priors[:, np.newaxis]
|
|
81
|
+
|
|
82
|
+
# log pi_k + log N(x | mu_x,k, Sigma_xx,k)
|
|
83
|
+
log_unnormalized_weights = log_priors + logpdfs
|
|
84
|
+
|
|
85
|
+
# NaN は無効成分として扱う
|
|
86
|
+
log_unnormalized_weights[np.isnan(log_unnormalized_weights)] = -np.inf
|
|
87
|
+
|
|
88
|
+
# log Σ_k pi_k N(x | mu_x,k, Sigma_xx,k)
|
|
89
|
+
log_normalizer = logsumexp(log_unnormalized_weights, axis=0)
|
|
90
|
+
|
|
91
|
+
# posterior weights:
|
|
92
|
+
# h_k(x) = pi_k N(x | mu_x,k, Sigma_xx,k) / Σ_j pi_j N(x | mu_x,j, Sigma_xx,j)
|
|
93
|
+
weights = np.zeros_like(log_unnormalized_weights)
|
|
94
|
+
|
|
95
|
+
valid_sample_flags = np.isfinite(log_normalizer)
|
|
96
|
+
|
|
97
|
+
weights[:, valid_sample_flags] = np.exp(
|
|
98
|
+
log_unnormalized_weights[:, valid_sample_flags]
|
|
99
|
+
- log_normalizer[valid_sample_flags]
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# 全成分が underflow / -inf / NaN 等になったサンプルだけ一様重みにする
|
|
103
|
+
invalid_sample_flags = ~valid_sample_flags
|
|
104
|
+
if invalid_sample_flags.any():
|
|
105
|
+
weights[:, invalid_sample_flags] = 1.0 / self.n_components
|
|
106
|
+
|
|
107
|
+
return weights, logpdfs, log_normalizer
|
|
35
108
|
|
|
36
109
|
def predict(self, dataset, numbers_of_input_variables, numbers_of_output_variables):
|
|
37
110
|
"""
|
|
@@ -400,28 +473,25 @@ class GMR(GaussianMixture):
|
|
|
400
473
|
output_covariances = output_input_covariances[:, :, numbers_of_output_variables]
|
|
401
474
|
output_input_covariances = output_input_covariances[:, :, numbers_of_input_variables]
|
|
402
475
|
|
|
403
|
-
# estimated means and
|
|
476
|
+
# estimated means and covariances for all components
|
|
404
477
|
for component_number in range(self.n_components):
|
|
405
478
|
estimated_means[component_number, :, :] = output_means[component_number, :] + (
|
|
406
479
|
dataset - input_means[component_number, :]).dot(
|
|
407
480
|
np.linalg.inv(input_covariances[component_number, :, :])).dot(
|
|
408
481
|
input_output_covariances[component_number, :, :])
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
weights[:, invalid_samples] = 1.0
|
|
423
|
-
weights_sum = weights.sum(axis=0)
|
|
424
|
-
weights = weights / weights_sum
|
|
482
|
+
|
|
483
|
+
estimated_covariances[component_number, :, :] = (
|
|
484
|
+
output_covariances[component_number, :, :]
|
|
485
|
+
- output_input_covariances[component_number, :, :].dot(
|
|
486
|
+
np.linalg.inv(input_covariances[component_number, :, :])
|
|
487
|
+
).dot(input_output_covariances[component_number, :, :])
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
weights, _, _ = self._calculate_logpdfs_and_weights(
|
|
491
|
+
dataset,
|
|
492
|
+
input_means,
|
|
493
|
+
input_covariances
|
|
494
|
+
)
|
|
425
495
|
|
|
426
496
|
return estimated_means, estimated_covariances, weights
|
|
427
497
|
|
|
@@ -508,23 +578,16 @@ class GMR(GaussianMixture):
|
|
|
508
578
|
input_output_covariances[component_number, :, :])
|
|
509
579
|
estimated_covariances[component_number, :, :] = output_covariances[component_number, :, :] - output_input_covariances[component_number, :, :].dot(
|
|
510
580
|
np.linalg.inv(input_covariances[component_number, :, :])).dot(input_output_covariances[component_number, :, :])
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
weights_sum = weights.sum(axis=0)
|
|
522
|
-
invalid_samples = (weights_sum <= 0) | (~np.isfinite(weights_sum))
|
|
523
|
-
if invalid_samples.any():
|
|
524
|
-
weights[:, invalid_samples] = 1.0
|
|
525
|
-
weights_sum = weights.sum(axis=0)
|
|
526
|
-
weights = weights / weights_sum
|
|
527
|
-
|
|
581
|
+
|
|
582
|
+
weights, logpdfs, log_normalizer = self._calculate_logpdfs_and_weights(
|
|
583
|
+
dataset,
|
|
584
|
+
input_means,
|
|
585
|
+
input_covariances
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
with np.errstate(under='ignore'):
|
|
589
|
+
pdfs = np.exp(logpdfs)
|
|
590
|
+
|
|
528
591
|
ioe = -logsumexp(logpdfs, axis=0, b=weights)
|
|
529
592
|
|
|
530
593
|
return estimated_means, estimated_covariances, weights, pdfs, logpdfs, ioe
|
|
@@ -34,6 +34,79 @@ class VBGMR(BayesianGaussianMixture):
|
|
|
34
34
|
self.rep = rep
|
|
35
35
|
self.display_flag = display_flag
|
|
36
36
|
|
|
37
|
+
def _calculate_logpdfs_and_weights(self, dataset, input_means, input_covariances):
|
|
38
|
+
"""
|
|
39
|
+
Calculate posterior component weights in log-space.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
dataset : numpy.ndarray
|
|
44
|
+
Input samples, shape = (n_samples, n_input_variables)
|
|
45
|
+
input_means : numpy.ndarray
|
|
46
|
+
Means of input variables, shape = (n_components, n_input_variables)
|
|
47
|
+
input_covariances : numpy.ndarray
|
|
48
|
+
Covariance matrices of input variables,
|
|
49
|
+
shape = (n_components, n_input_variables, n_input_variables)
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
weights : numpy.ndarray
|
|
54
|
+
Posterior weights, shape = (n_components, n_samples)
|
|
55
|
+
logpdfs : numpy.ndarray
|
|
56
|
+
Component-wise log density of input variables,
|
|
57
|
+
shape = (n_components, n_samples)
|
|
58
|
+
log_normalizer : numpy.ndarray
|
|
59
|
+
log p(x) for each sample, shape = (n_samples,)
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
n_samples = dataset.shape[0]
|
|
63
|
+
|
|
64
|
+
# log N(x | mu_x,k, Sigma_xx,k)
|
|
65
|
+
logpdfs = np.full([self.n_components, n_samples], -np.inf)
|
|
66
|
+
|
|
67
|
+
for component_number in range(self.n_components):
|
|
68
|
+
try:
|
|
69
|
+
logpdfs[component_number, :] = multivariate_normal.logpdf(
|
|
70
|
+
dataset,
|
|
71
|
+
mean=input_means[component_number, :],
|
|
72
|
+
cov=input_covariances[component_number, :, :]
|
|
73
|
+
)
|
|
74
|
+
except Exception:
|
|
75
|
+
print('assignment of logpdfs is failed, and -inf is assigned')
|
|
76
|
+
|
|
77
|
+
# log pi_k
|
|
78
|
+
log_priors = np.full(self.n_components, -np.inf)
|
|
79
|
+
positive_prior_flags = self.weights_ > 0
|
|
80
|
+
log_priors[positive_prior_flags] = np.log(self.weights_[positive_prior_flags])
|
|
81
|
+
log_priors = log_priors[:, np.newaxis]
|
|
82
|
+
|
|
83
|
+
# log pi_k + log N(x | mu_x,k, Sigma_xx,k)
|
|
84
|
+
log_unnormalized_weights = log_priors + logpdfs
|
|
85
|
+
|
|
86
|
+
# NaN は無効成分として扱う
|
|
87
|
+
log_unnormalized_weights[np.isnan(log_unnormalized_weights)] = -np.inf
|
|
88
|
+
|
|
89
|
+
# log Σ_k pi_k N(x | mu_x,k, Sigma_xx,k)
|
|
90
|
+
log_normalizer = logsumexp(log_unnormalized_weights, axis=0)
|
|
91
|
+
|
|
92
|
+
# posterior weights:
|
|
93
|
+
# h_k(x) = pi_k N(x | mu_x,k, Sigma_xx,k) / Σ_j pi_j N(x | mu_x,j, Sigma_xx,j)
|
|
94
|
+
weights = np.zeros_like(log_unnormalized_weights)
|
|
95
|
+
|
|
96
|
+
valid_sample_flags = np.isfinite(log_normalizer)
|
|
97
|
+
|
|
98
|
+
weights[:, valid_sample_flags] = np.exp(
|
|
99
|
+
log_unnormalized_weights[:, valid_sample_flags]
|
|
100
|
+
- log_normalizer[valid_sample_flags]
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# 全成分が underflow / -inf / NaN 等になったサンプルだけ一様重みにする
|
|
104
|
+
invalid_sample_flags = ~valid_sample_flags
|
|
105
|
+
if invalid_sample_flags.any():
|
|
106
|
+
weights[:, invalid_sample_flags] = 1.0 / self.n_components
|
|
107
|
+
|
|
108
|
+
return weights, logpdfs, log_normalizer
|
|
109
|
+
|
|
37
110
|
def predict(self, dataset, numbers_of_input_variables, numbers_of_output_variables):
|
|
38
111
|
"""
|
|
39
112
|
Variational Bayesian Gaussian Mixture Regression (VBGMR) based on Variational Bayesian Gaussian Mixture Model (VBGMM)
|
|
@@ -89,7 +162,7 @@ class VBGMR(BayesianGaussianMixture):
|
|
|
89
162
|
mode_of_estimated_mean = np.zeros([dataset.shape[0], len(numbers_of_output_variables)])
|
|
90
163
|
weighted_estimated_mean = np.zeros([dataset.shape[0], len(numbers_of_output_variables)])
|
|
91
164
|
estimated_mean_for_all_components = np.zeros([self.n_components, dataset.shape[0], len(numbers_of_output_variables)])
|
|
92
|
-
weights = np.zeros([dataset.shape[0]
|
|
165
|
+
weights = np.zeros([self.n_components, dataset.shape[0]])
|
|
93
166
|
|
|
94
167
|
return mode_of_estimated_mean, weighted_estimated_mean, estimated_mean_for_all_components, weights
|
|
95
168
|
|
|
@@ -301,28 +374,25 @@ class VBGMR(BayesianGaussianMixture):
|
|
|
301
374
|
output_covariances = output_input_covariances[:, :, numbers_of_output_variables]
|
|
302
375
|
output_input_covariances = output_input_covariances[:, :, numbers_of_input_variables]
|
|
303
376
|
|
|
304
|
-
# estimated means and
|
|
377
|
+
# estimated means and covariances for all components
|
|
305
378
|
for component_number in range(self.n_components):
|
|
306
379
|
estimated_means[component_number, :, :] = output_means[component_number, :] + (
|
|
307
380
|
dataset - input_means[component_number, :]).dot(
|
|
308
381
|
np.linalg.inv(input_covariances[component_number, :, :])).dot(
|
|
309
382
|
input_output_covariances[component_number, :, :])
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
weights[:, invalid_samples] = 1.0
|
|
324
|
-
weights_sum = weights.sum(axis=0)
|
|
325
|
-
weights = weights / weights_sum
|
|
383
|
+
|
|
384
|
+
estimated_covariances[component_number, :, :] = (
|
|
385
|
+
output_covariances[component_number, :, :]
|
|
386
|
+
- output_input_covariances[component_number, :, :].dot(
|
|
387
|
+
np.linalg.inv(input_covariances[component_number, :, :])
|
|
388
|
+
).dot(input_output_covariances[component_number, :, :])
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
weights, _, _ = self._calculate_logpdfs_and_weights(
|
|
392
|
+
dataset,
|
|
393
|
+
input_means,
|
|
394
|
+
input_covariances
|
|
395
|
+
)
|
|
326
396
|
|
|
327
397
|
return estimated_means, estimated_covariances, weights
|
|
328
398
|
|
|
@@ -408,22 +478,15 @@ class VBGMR(BayesianGaussianMixture):
|
|
|
408
478
|
input_output_covariances[component_number, :, :])
|
|
409
479
|
estimated_covariances[component_number, :, :] = output_covariances[component_number, :, :] - output_input_covariances[component_number, :, :].dot(
|
|
410
480
|
np.linalg.inv(input_covariances[component_number, :, :])).dot(input_output_covariances[component_number, :, :])
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
weights_sum = weights.sum(axis=0)
|
|
422
|
-
invalid_samples = (weights_sum <= 0) | (~np.isfinite(weights_sum))
|
|
423
|
-
if invalid_samples.any():
|
|
424
|
-
weights[:, invalid_samples] = 1.0
|
|
425
|
-
weights_sum = weights.sum(axis=0)
|
|
426
|
-
weights = weights / weights_sum
|
|
481
|
+
|
|
482
|
+
weights, logpdfs, log_normalizer = self._calculate_logpdfs_and_weights(
|
|
483
|
+
dataset,
|
|
484
|
+
input_means,
|
|
485
|
+
input_covariances
|
|
486
|
+
)
|
|
487
|
+
with np.errstate(under='ignore'):
|
|
488
|
+
pdfs = np.exp(logpdfs)
|
|
489
|
+
|
|
427
490
|
ioe = -logsumexp(logpdfs, axis=0, b=weights)
|
|
428
491
|
|
|
429
492
|
return estimated_means, estimated_covariances, weights, pdfs, logpdfs, ioe
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|