dcekit 2.14.2__tar.gz → 2.16.1__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.
Files changed (41) hide show
  1. {dcekit-2.14.2/dcekit.egg-info → dcekit-2.16.1}/PKG-INFO +3 -2
  2. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/generative_model/gmr.py +109 -4
  3. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/generative_model/gtm.py +8 -7
  4. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/generative_model/vbgmr.py +107 -4
  5. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/variable_selection/basic_variable_selection.py +1 -1
  6. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/variable_selection/variable_importance.py +12 -3
  7. {dcekit-2.14.2 → dcekit-2.16.1/dcekit.egg-info}/PKG-INFO +3 -2
  8. {dcekit-2.14.2 → dcekit-2.16.1}/setup.py +1 -1
  9. {dcekit-2.14.2 → dcekit-2.16.1}/LICENSE +0 -0
  10. {dcekit-2.14.2 → dcekit-2.16.1}/LICENSE.txt +0 -0
  11. {dcekit-2.14.2 → dcekit-2.16.1}/MANIFEST.in +0 -0
  12. {dcekit-2.14.2 → dcekit-2.16.1}/README.md +0 -0
  13. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/__init__.py +0 -0
  14. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/design_of_exmeriments/__init__.py +0 -0
  15. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/design_of_exmeriments/bayesian_optimization.py +0 -0
  16. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/generative_model/__init__.py +0 -0
  17. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/just_in_time/__init__.py +0 -0
  18. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/just_in_time/jitpls.py +0 -0
  19. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/just_in_time/lwpls.py +0 -0
  20. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/learning/__init__.py +0 -0
  21. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/learning/ensemble_learning.py +0 -0
  22. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/learning/semi_supervised_learning.py +0 -0
  23. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/learning/transfer_learning.py +0 -0
  24. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/optimization/__init__.py +0 -0
  25. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/optimization/fast_opt_svr_hyperparams.py +0 -0
  26. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/optimization/iot.py +0 -0
  27. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/optimization/opt_dnn_hyperparams.py +0 -0
  28. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/optimization/opt_dnn_hyperparams_class.py +0 -0
  29. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/sampling/__init__.py +0 -0
  30. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/sampling/kennard_stone.py +0 -0
  31. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/validation/__init__.py +0 -0
  32. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/validation/applicability_domain.py +0 -0
  33. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/validation/metrics.py +0 -0
  34. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/validation/validation.py +0 -0
  35. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/variable_selection/__init__.py +0 -0
  36. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit/variable_selection/local_interpretation.py +0 -0
  37. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit.egg-info/SOURCES.txt +0 -0
  38. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit.egg-info/dependency_links.txt +0 -0
  39. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit.egg-info/requires.txt +0 -0
  40. {dcekit-2.14.2 → dcekit-2.16.1}/dcekit.egg-info/top_level.txt +0 -0
  41. {dcekit-2.14.2 → dcekit-2.16.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dcekit
3
- Version: 2.14.2
3
+ Version: 2.16.1
4
4
  Summary: Data Chemical Engineering toolkit
5
5
  Home-page: https://github.com/hkaneko1985/dcekit/
6
6
  Author: Hiromasa Kaneko
@@ -38,6 +38,7 @@ Dynamic: author-email
38
38
  Dynamic: description
39
39
  Dynamic: home-page
40
40
  Dynamic: license
41
+ Dynamic: license-file
41
42
  Dynamic: requires-dist
42
43
  Dynamic: summary
43
44
 
@@ -24,8 +24,10 @@ warnings.simplefilter('ignore')
24
24
  class GMR(GaussianMixture):
25
25
 
26
26
  def __init__(self, n_components=1, covariance_type='full', rep='mean',
27
+ weights_init=None, means_init=None, precisions_init=None,
27
28
  max_iter=100, random_state=None, display_flag=False):
28
29
  super(self.__class__, self).__init__(n_components=n_components, covariance_type=covariance_type,
30
+ weights_init=weights_init, means_init=means_init, precisions_init=precisions_init,
29
31
  max_iter=max_iter, random_state=random_state)
30
32
 
31
33
  self.rep = rep
@@ -123,9 +125,9 @@ class GMR(GaussianMixture):
123
125
  """
124
126
 
125
127
  mode_of_estimated_mean, weighted_estimated_mean, _, _ = self.predict(dataset, numbers_of_input_variables, numbers_of_output_variables)
126
- if self.rep == 'mean':
128
+ if self.rep == 'mode':
127
129
  values = mode_of_estimated_mean.copy()
128
- elif self.rep == 'mode':
130
+ elif self.rep == 'mean':
129
131
  values = weighted_estimated_mean.copy()
130
132
  return values
131
133
 
@@ -301,7 +303,6 @@ class GMR(GaussianMixture):
301
303
  Parameters
302
304
  ----------
303
305
  gmm_model: mixture.gaussian_mixture.GaussianMixture
304
- GMM model constructed using scikit-learn
305
306
  dataset: numpy.array or pandas.DataFrame
306
307
  (autoscaled) m x n matrix of dataset of training data or test data,
307
308
  m is the number of sammples and
@@ -363,6 +364,104 @@ class GMR(GaussianMixture):
363
364
  l x m matrix of weights,
364
365
  """
365
366
 
367
+ dataset = np.array(dataset)
368
+ if dataset.ndim == 0:
369
+ dataset = np.reshape(dataset, (1, 1))
370
+ elif dataset.ndim == 1:
371
+ dataset = np.reshape(dataset, (1, dataset.shape[0]))
372
+
373
+ input_means = self.means_[:, numbers_of_input_variables]
374
+ output_means = self.means_[:, numbers_of_output_variables]
375
+
376
+ if self.covariance_type == 'full':
377
+ all_covariances = self.covariances_
378
+ elif self.covariance_type == 'diag':
379
+ all_covariances = np.empty(
380
+ [self.n_components, self.covariances_.shape[1], self.covariances_.shape[1]])
381
+ for component_number in range(self.n_components):
382
+ all_covariances[component_number, :, :] = np.diag(self.covariances_[component_number, :])
383
+ elif self.covariance_type == 'tied':
384
+ all_covariances = np.tile(self.covariances_, (self.n_components, 1, 1))
385
+ elif self.covariance_type == 'spherical':
386
+ all_covariances = np.empty([self.n_components, self.means_.shape[1], self.means_.shape[1]])
387
+ for component_number in range(self.n_components):
388
+ all_covariances[component_number, :, :] = np.diag(
389
+ self.covariances_[component_number] * np.ones(self.means_.shape[1]))
390
+
391
+ estimated_means = np.zeros([self.n_components, dataset.shape[0], len(numbers_of_output_variables)])
392
+ estimated_covariances = np.zeros([self.n_components, len(numbers_of_output_variables), len(numbers_of_output_variables)])
393
+ weights = np.zeros([self.n_components, dataset.shape[0]])
394
+ # print(all_covariances.shape[2], len(numbers_of_input_variables), len(numbers_of_output_variables))
395
+ if all_covariances.shape[2] == len(numbers_of_input_variables) + len(numbers_of_output_variables):
396
+ input_output_covariances = all_covariances[:, numbers_of_input_variables, :]
397
+ input_covariances = input_output_covariances[:, :, numbers_of_input_variables]
398
+ input_output_covariances = input_output_covariances[:, :, numbers_of_output_variables]
399
+ output_input_covariances = all_covariances[:, numbers_of_output_variables, :]
400
+ output_covariances = output_input_covariances[:, :, numbers_of_output_variables]
401
+ output_input_covariances = output_input_covariances[:, :, numbers_of_input_variables]
402
+
403
+ # estimated means and weights for all components
404
+ for component_number in range(self.n_components):
405
+ estimated_means[component_number, :, :] = output_means[component_number, :] + (
406
+ dataset - input_means[component_number, :]).dot(
407
+ np.linalg.inv(input_covariances[component_number, :, :])).dot(
408
+ input_output_covariances[component_number, :, :])
409
+ estimated_covariances[component_number, :, :] = output_covariances[component_number, :, :] - output_input_covariances[component_number, :, :].dot(
410
+ np.linalg.inv(input_covariances[component_number, :, :])).dot(input_output_covariances[component_number, :, :])
411
+ try:
412
+ weights[component_number, :] = self.weights_[component_number] * \
413
+ multivariate_normal.pdf(dataset,
414
+ input_means[component_number, :],
415
+ input_covariances[component_number, :, :])
416
+ except:
417
+ print('assignment of weights is failed, and zero is assigned')
418
+
419
+ if len(np.where(weights.sum(axis=0)==0)[0]) > 0:
420
+ weights = np.ones(weights.shape)
421
+ if np.isnan(weights.sum(axis=0)).any():
422
+ weights = np.ones(weights.shape)
423
+ if np.isinf(weights.sum(axis=0)).any():
424
+ weights = np.ones(weights.shape)
425
+ weights = weights / weights.sum(axis=0)
426
+
427
+ return estimated_means, estimated_covariances, weights
428
+
429
+ def predict_mog_pdf(self, dataset, numbers_of_input_variables, numbers_of_output_variables):
430
+ """
431
+ Gaussian Mixture Regression (GMR) based on Gaussian Mixture Model (GMM)
432
+
433
+ Predict values of variables for forward analysis (regression) and inverse analysis. Predition results are given as mixture of Gaussians
434
+
435
+ Parameters
436
+ ----------
437
+ gmm_model: mixture.gaussian_mixture.GaussianMixture
438
+ GMM model constructed using scikit-learn
439
+ dataset: numpy.array or pandas.DataFrame
440
+ (autoscaled) m x n matrix of dataset of training data or test data,
441
+ m is the number of sammples and
442
+ n is the number of input variables
443
+ When this is X-variables, it is forward analysis (regression) and
444
+ when this is Y-variables, it is inverse analysis
445
+ numbers_of_input_variables: list
446
+ vector of numbers of input variables
447
+ When this is numbers of X-variables, it is forward analysis (regression) and
448
+ when this is numbers of Y-variables, it is inverse analysis
449
+ numbers_of_output_variables: list
450
+ vector of numbers of output variables
451
+ When this is numbers of Y-variables, it is forward analysis (regression) and
452
+ when this is numbers of X-variables, it is inverse analysis
453
+
454
+ Returns
455
+ -------
456
+ estimated_means : numpy.array
457
+ (autoscaled) l x m x k matrix of output variables estimated for all components,
458
+ k is the number of output variables
459
+ estimated_covariances : numpy.array
460
+ (autoscaled) l x k x k variance-covariance matrix of output variables estimated for all components,
461
+ weights : numpy.array
462
+ l x m matrix of weights,
463
+ """
464
+
366
465
  dataset = np.array(dataset)
367
466
  if dataset.ndim == 0:
368
467
  dataset = np.reshape(dataset, (1, 1))
@@ -390,6 +489,9 @@ class GMR(GaussianMixture):
390
489
  estimated_means = np.zeros([self.n_components, dataset.shape[0], len(numbers_of_output_variables)])
391
490
  estimated_covariances = np.zeros([self.n_components, len(numbers_of_output_variables), len(numbers_of_output_variables)])
392
491
  weights = np.zeros([self.n_components, dataset.shape[0]])
492
+ pdfs = np.zeros([self.n_components, dataset.shape[0]])
493
+ logpdfs = np.zeros([self.n_components, dataset.shape[0]])
494
+
393
495
  # print(all_covariances.shape[2], len(numbers_of_input_variables), len(numbers_of_output_variables))
394
496
  if all_covariances.shape[2] == len(numbers_of_input_variables) + len(numbers_of_output_variables):
395
497
  input_output_covariances = all_covariances[:, numbers_of_input_variables, :]
@@ -412,6 +514,8 @@ class GMR(GaussianMixture):
412
514
  multivariate_normal.pdf(dataset,
413
515
  input_means[component_number, :],
414
516
  input_covariances[component_number, :, :])
517
+ pdfs[component_number, :] = multivariate_normal.pdf(dataset, input_means[component_number, :], input_covariances[component_number, :, :])
518
+ logpdfs[component_number, :] = multivariate_normal.logpdf(dataset, input_means[component_number, :], input_covariances[component_number, :, :])
415
519
  except:
416
520
  print('assignment of weights is failed, and zero is assigned')
417
521
 
@@ -422,8 +526,9 @@ class GMR(GaussianMixture):
422
526
  if np.isinf(weights.sum(axis=0)).any():
423
527
  weights = np.ones(weights.shape)
424
528
  weights = weights / weights.sum(axis=0)
529
+ ioe = -logsumexp(logpdfs, axis=0, b=weights)
425
530
 
426
- return estimated_means, estimated_covariances, weights
531
+ return estimated_means, estimated_covariances, weights, pdfs, logpdfs, ioe
427
532
 
428
533
  def cv_opt(self, dataset, numbers_of_input_variables, numbers_of_output_variables, covariance_types,
429
534
  numbers_of_components, fold_number):
@@ -627,7 +627,7 @@ class GTM:
627
627
  if bo_iter == 0: # 最初の試行ではD最適基準を計算
628
628
  # D最適基準の計算
629
629
  param_std = params_df.std(axis=0, ddof=1)
630
- param_std[np.where(param_std == 0)[0]] = 1
630
+ param_std.iloc[np.where(param_std == 0)[0]] = 1
631
631
  autoscaled_params_df = (params_df - params_df.mean(axis=0)) / param_std # 計算のために標準化
632
632
 
633
633
  all_indexes = list(range(autoscaled_params_df.shape[0])) # indexを取得
@@ -748,7 +748,7 @@ class GTM:
748
748
  for bo_sample_number in range(bo_number_of_selecting_samples):
749
749
  # オートスケーリング
750
750
  x_std = bo_x_data.std(axis=0, ddof=1)
751
- x_std[np.where(x_std == 0)[0]] = 1
751
+ x_std.iloc[np.where(x_std == 0)[0]] = 1
752
752
  autoscaled_bo_y_data = (bo_y_data - bo_y_data.mean()) / bo_y_data.std()
753
753
  autoscaled_bo_x_data = (bo_x_data - bo_x_data.mean()) / x_std
754
754
  autoscaled_bo_x_prediction = (bo_x_prediction - bo_x_data.mean()) / x_std
@@ -937,7 +937,7 @@ class GTM:
937
937
  if bo_iter == 0: # 最初の試行ではD最適基準を計算
938
938
  # D最適基準の計算
939
939
  param_std = params_df.std(axis=0, ddof=1)
940
- param_std[np.where(param_std == 0)[0]] = 1
940
+ param_std.iloc[np.where(param_std == 0)[0]] = 1
941
941
  autoscaled_params_df = (params_df - params_df.mean(axis=0)) / param_std # 計算のために標準化
942
942
 
943
943
  all_indexes = list(range(autoscaled_params_df.shape[0])) # indexを取得
@@ -1004,8 +1004,8 @@ class GTM:
1004
1004
  else:
1005
1005
  # k3nerror_of_gtm = 10 ** 100
1006
1006
  k3nerror_of_gtm = (np.random.rand()/10 + 1) * 50
1007
-
1008
- params_with_score_df['k3nerror score'].loc[selected_params_idx] = k3nerror_of_gtm # データの保存
1007
+
1008
+ params_with_score_df.loc[selected_params_idx, 'k3nerror score'] = k3nerror_of_gtm # データの保存
1009
1009
 
1010
1010
  if bo_display_flag:
1011
1011
  print('Best k3n-error :', params_with_score_df['k3nerror score'].min())
@@ -1016,7 +1016,7 @@ class GTM:
1016
1016
  break
1017
1017
 
1018
1018
  # Bayesian optimization
1019
- bo_x_data = bo_params_df.copy() # GP学習用データはGMRの結果があるサンプル
1019
+ bo_x_data = bo_params_df.copy() # GP学習用データはGTMの結果があるサンプル
1020
1020
  bo_x_prediction = remaining_params_df.copy() # predictionは選択されていない(GMRの結果がない)サンプル
1021
1021
  bo_y_data = params_with_score_df.loc[bo_params_df.index, 'k3nerror score'] # yはGMRのr2cv
1022
1022
 
@@ -1039,7 +1039,7 @@ class GTM:
1039
1039
  for bo_sample_number in range(bo_number_of_selecting_samples):
1040
1040
  # オートスケーリング
1041
1041
  x_std = bo_x_data.std(axis=0, ddof=1)
1042
- x_std[np.where(x_std == 0)[0]] = 1
1042
+ x_std.iloc[np.where(x_std == 0)[0]] = 1
1043
1043
  autoscaled_bo_y_data = (bo_y_data - bo_y_data.mean()) / bo_y_data.std()
1044
1044
  autoscaled_bo_x_data = (bo_x_data - bo_x_data.mean()) / x_std
1045
1045
  autoscaled_bo_x_prediction = (bo_x_prediction - bo_x_data.mean()) / x_std
@@ -1125,6 +1125,7 @@ class GTM:
1125
1125
  self.shape_of_rbf_centers = [shape_of_rbf_centers, shape_of_rbf_centers]
1126
1126
  self.variance_of_rbfs = variance_of_rbfs
1127
1127
  self.lambda_in_em_algorithm = lambda_in_em
1128
+ self.rep = 'mean'
1128
1129
  self.k3nerror = params_with_score_df_best['k3nerror score']
1129
1130
  if bo_display_flag:
1130
1131
  self.display_flag = True
@@ -25,11 +25,11 @@ class VBGMR(BayesianGaussianMixture):
25
25
  def __init__(self, n_components=30, covariance_type='full',
26
26
  weight_concentration_prior_type='dirichlet_process',
27
27
  weight_concentration_prior=0.01, rep='mean', max_iter=100,
28
- random_state=None, display_flag=False):
28
+ init_params='kmeans', random_state=None, display_flag=False):
29
29
  super(self.__class__, self).__init__(n_components=n_components, covariance_type=covariance_type,
30
30
  weight_concentration_prior_type=weight_concentration_prior_type,
31
31
  weight_concentration_prior=weight_concentration_prior,
32
- max_iter=max_iter, random_state=random_state)
32
+ init_params=init_params, max_iter=max_iter, random_state=random_state)
33
33
 
34
34
  self.rep = rep
35
35
  self.display_flag = display_flag
@@ -132,9 +132,9 @@ class VBGMR(BayesianGaussianMixture):
132
132
  """
133
133
 
134
134
  mode_of_estimated_mean, weighted_estimated_mean, _, _ = self.predict(dataset, numbers_of_input_variables, numbers_of_output_variables)
135
- if self.rep == 'mean':
135
+ if self.rep == 'mode':
136
136
  values = mode_of_estimated_mean.copy()
137
- elif self.rep == 'mode':
137
+ elif self.rep == 'mean':
138
138
  values = weighted_estimated_mean.copy()
139
139
  return values
140
140
 
@@ -327,6 +327,109 @@ class VBGMR(BayesianGaussianMixture):
327
327
 
328
328
  return estimated_means, estimated_covariances, weights
329
329
 
330
+ def predict_mog_pdf(self, dataset, numbers_of_input_variables, numbers_of_output_variables):
331
+ """
332
+ Variational Bayesian Gaussian Mixture Regression (VBGMR) based on Variational Bayesian Gaussian Mixture Model (VBGMM)
333
+
334
+ Predict values of variables for forward analysis (regression) and inverse analysis. Predition results are given as mixture of Gaussians
335
+
336
+ Parameters
337
+ ----------
338
+ gmm_model: mixture.gaussian_mixture.GaussianMixture
339
+ GMM model constructed using scikit-learn
340
+ dataset: numpy.array or pandas.DataFrame
341
+ (autoscaled) m x n matrix of dataset of training data or test data,
342
+ m is the number of sammples and
343
+ n is the number of input variables
344
+ When this is X-variables, it is forward analysis (regression) and
345
+ when this is Y-variables, it is inverse analysis
346
+ numbers_of_input_variables: list
347
+ vector of numbers of input variables
348
+ When this is numbers of X-variables, it is forward analysis (regression) and
349
+ when this is numbers of Y-variables, it is inverse analysis
350
+ numbers_of_output_variables: list
351
+ vector of numbers of output variables
352
+ When this is numbers of Y-variables, it is forward analysis (regression) and
353
+ when this is numbers of X-variables, it is inverse analysis
354
+
355
+ Returns
356
+ -------
357
+ estimated_means : numpy.array
358
+ (autoscaled) l x m x k matrix of output variables estimated for all components,
359
+ k is the number of output variables
360
+ estimated_covariances : numpy.array
361
+ (autoscaled) l x k x k variance-covariance matrix of output variables estimated for all components,
362
+ weights : numpy.array
363
+ l x m matrix of weights,
364
+ """
365
+
366
+ dataset = np.array(dataset)
367
+ if dataset.ndim == 0:
368
+ dataset = np.reshape(dataset, (1, 1))
369
+ elif dataset.ndim == 1:
370
+ dataset = np.reshape(dataset, (1, dataset.shape[0]))
371
+
372
+ input_means = self.means_[:, numbers_of_input_variables]
373
+ output_means = self.means_[:, numbers_of_output_variables]
374
+
375
+ if self.covariance_type == 'full':
376
+ all_covariances = self.covariances_
377
+ elif self.covariance_type == 'diag':
378
+ all_covariances = np.empty(
379
+ [self.n_components, self.covariances_.shape[1], self.covariances_.shape[1]])
380
+ for component_number in range(self.n_components):
381
+ all_covariances[component_number, :, :] = np.diag(self.covariances_[component_number, :])
382
+ elif self.covariance_type == 'tied':
383
+ all_covariances = np.tile(self.covariances_, (self.n_components, 1, 1))
384
+ elif self.covariance_type == 'spherical':
385
+ all_covariances = np.empty([self.n_components, self.means_.shape[1], self.means_.shape[1]])
386
+ for component_number in range(self.n_components):
387
+ all_covariances[component_number, :, :] = np.diag(
388
+ self.covariances_[component_number] * np.ones(self.means_.shape[1]))
389
+
390
+ estimated_means = np.zeros([self.n_components, dataset.shape[0], len(numbers_of_output_variables)])
391
+ estimated_covariances = np.zeros([self.n_components, len(numbers_of_output_variables), len(numbers_of_output_variables)])
392
+ weights = np.zeros([self.n_components, dataset.shape[0]])
393
+ pdfs = np.zeros([self.n_components, dataset.shape[0]])
394
+ logpdfs = np.zeros([self.n_components, dataset.shape[0]])
395
+ # print(all_covariances.shape[2], len(numbers_of_input_variables), len(numbers_of_output_variables))
396
+ if all_covariances.shape[2] == len(numbers_of_input_variables) + len(numbers_of_output_variables):
397
+ input_output_covariances = all_covariances[:, numbers_of_input_variables, :]
398
+ input_covariances = input_output_covariances[:, :, numbers_of_input_variables]
399
+ input_output_covariances = input_output_covariances[:, :, numbers_of_output_variables]
400
+ output_input_covariances = all_covariances[:, numbers_of_output_variables, :]
401
+ output_covariances = output_input_covariances[:, :, numbers_of_output_variables]
402
+ output_input_covariances = output_input_covariances[:, :, numbers_of_input_variables]
403
+
404
+ # estimated means and weights for all components
405
+ for component_number in range(self.n_components):
406
+ estimated_means[component_number, :, :] = output_means[component_number, :] + (
407
+ dataset - input_means[component_number, :]).dot(
408
+ np.linalg.inv(input_covariances[component_number, :, :])).dot(
409
+ input_output_covariances[component_number, :, :])
410
+ estimated_covariances[component_number, :, :] = output_covariances[component_number, :, :] - output_input_covariances[component_number, :, :].dot(
411
+ np.linalg.inv(input_covariances[component_number, :, :])).dot(input_output_covariances[component_number, :, :])
412
+ try:
413
+ weights[component_number, :] = self.weights_[component_number] * \
414
+ multivariate_normal.pdf(dataset,
415
+ input_means[component_number, :],
416
+ input_covariances[component_number, :, :])
417
+ pdfs[component_number, :] = multivariate_normal.pdf(dataset, input_means[component_number, :], input_covariances[component_number, :, :])
418
+ logpdfs[component_number, :] = multivariate_normal.logpdf(dataset, input_means[component_number, :], input_covariances[component_number, :, :])
419
+ except:
420
+ print('assignment of weights is failed, and zero is assigned')
421
+
422
+ if len(np.where(weights.sum(axis=0)==0)[0]) > 0:
423
+ weights = np.ones(weights.shape)
424
+ if np.isnan(weights.sum(axis=0)).any():
425
+ weights = np.ones(weights.shape)
426
+ if np.isinf(weights.sum(axis=0)).any():
427
+ weights = np.ones(weights.shape)
428
+ weights = weights / weights.sum(axis=0)
429
+ ioe = -logsumexp(logpdfs, axis=0, b=weights)
430
+
431
+ return estimated_means, estimated_covariances, weights, pdfs, logpdfs, ioe
432
+
330
433
  def cv_opt(self, dataset, numbers_of_input_variables, numbers_of_output_variables, covariance_types,
331
434
  numbers_of_components, weight_concentration_prior_types, weight_concentration_priors, fold_number):
332
435
  """
@@ -103,7 +103,7 @@ def clustering_based_on_correlation_coefficients(x, threshold_of_r):
103
103
  distance_in_x = 1 / r_in_x
104
104
 
105
105
  # clustering
106
- clustering = AgglomerativeClustering(n_clusters=None, affinity='precomputed', compute_full_tree='True',
106
+ clustering = AgglomerativeClustering(n_clusters=None, metric='precomputed', compute_full_tree='auto',
107
107
  distance_threshold=1 / threshold_of_r, linkage='complete')
108
108
  clustering.fit(distance_in_x)
109
109
  cluster_numbers = clustering.labels_
@@ -88,7 +88,11 @@ def cvpfi(
88
88
  corr_variable_all = X[:, corr_variable_number].copy()
89
89
  for sample_number in range(x_test.shape[0]):
90
90
  if np.random.rand(1)[0] < target_x_corr[corr_variable_number]:
91
- x_test_shuffled[sample_number, corr_variable_number] = np.random.choice(corr_variable_all, 1, replace=replace)
91
+ tmp = np.random.choice(corr_variable_all, 1, replace=replace)
92
+ if len(tmp)== 1:
93
+ x_test_shuffled[sample_number, corr_variable_number] = tmp[0]
94
+ else:
95
+ x_test_shuffled[sample_number, corr_variable_number] = tmp
92
96
 
93
97
  estimated_y_test_shuffled = estimator_copy.predict(x_test_shuffled)
94
98
  if y.ndim == 1:
@@ -115,11 +119,12 @@ def cvpfi(
115
119
  accuracy_cv = accuracy_score(y, estimated_y_in_cv)
116
120
  else:
117
121
  accuracy_cv = accuracy_score(np.ravel(y), np.ravel(estimated_y_in_cv))
118
- # print(accuracy_score)
122
+ print(accuracy_cv)
119
123
  for variable_number in range(X.shape[1]):
120
124
  for n_repeat in range(n_repeats):
121
125
  # print(accuracy_score(y, estimated_y_in_cv_shuffled[:, n_repeat, variable_number]))
122
126
  if y.ndim == 1:
127
+ print(accuracy_score(y, estimated_y_in_cv_shuffled[:, n_repeat, variable_number]))
123
128
  importances[variable_number, n_repeat] = accuracy_cv - accuracy_score(y, estimated_y_in_cv_shuffled[:, n_repeat, variable_number])
124
129
  else:
125
130
  importances[variable_number, n_repeat] = accuracy_cv - accuracy_score(np.ravel(y), np.ravel(estimated_y_in_cv_shuffled[:, :, n_repeat, variable_number]))
@@ -202,7 +207,11 @@ def cvpfi_gmr(
202
207
  corr_variable_all = X[:, corr_variable_number].copy()
203
208
  for sample_number in range(x_test.shape[0]):
204
209
  if np.random.rand(1)[0] < target_x_corr[corr_variable_number]:
205
- x_test_shuffled[sample_number, corr_variable_number] = np.random.choice(corr_variable_all, 1, replace=replace)
210
+ tmp = np.random.choice(corr_variable_all, 1, replace=replace)
211
+ if len(tmp)== 1:
212
+ x_test_shuffled[sample_number, corr_variable_number] = tmp[0]
213
+ else:
214
+ x_test_shuffled[sample_number, corr_variable_number] = tmp
206
215
  estimated_y_in_cv_shuffled[fold_index==fold_number_in_outer_cv, :, n_repeat, variable_number] = estimator_copy.predict_rep(x_test_shuffled, numbers_of_x, numbers_of_y)
207
216
 
208
217
  importances = np.zeros([X.shape[1], n_repeats])
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dcekit
3
- Version: 2.14.2
3
+ Version: 2.16.1
4
4
  Summary: Data Chemical Engineering toolkit
5
5
  Home-page: https://github.com/hkaneko1985/dcekit/
6
6
  Author: Hiromasa Kaneko
@@ -38,6 +38,7 @@ Dynamic: author-email
38
38
  Dynamic: description
39
39
  Dynamic: home-page
40
40
  Dynamic: license
41
+ Dynamic: license-file
41
42
  Dynamic: requires-dist
42
43
  Dynamic: summary
43
44
 
@@ -13,7 +13,7 @@ with open('LICENSE.txt') as f:
13
13
 
14
14
  setup(
15
15
  name='dcekit',
16
- version='2.14.2',
16
+ version='2.16.1',
17
17
  description='Data Chemical Engineering toolkit',
18
18
  long_description=readme,
19
19
  author='Hiromasa Kaneko',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes