dspin 1.4.2__tar.gz → 1.4.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dspin
3
- Version: 1.4.2
3
+ Version: 1.4.3
4
4
  Summary: Regulatory network models from single-cell perturbation profiling
5
5
  Home-page: https://github.com/JialongJiang/DSPIN
6
6
  Author: Jialong Jiang
@@ -985,6 +985,7 @@ def apply_regularization(rec_jgrad: np.ndarray,
985
985
 
986
986
  if 'lambda_l2_h_rela_prior' in train_dat:
987
987
  perturb_matrix = train_dat['perturb_matrix']
988
+ rec_hgrad = average_batch_control(rec_hgrad, if_control, batch_index)
988
989
  rec_hgrad += train_dat['lambda_l2_h_rela_prior'] * (h_rela - perturb_matrix)
989
990
 
990
991
  if 'lambda_l1_h_rela' in train_dat:
@@ -1421,7 +1422,7 @@ def compute_relative_responses(cur_h: np.ndarray,
1421
1422
  batch_samples_idx = np.where(batch_index == current_batch)[0]
1422
1423
 
1423
1424
  if np.any(if_control[batch_samples_idx]):
1424
- batch_controls_idx = batch_samples_idx[if_control[batch_samples_idx]]
1425
+ batch_controls_idx = batch_samples_idx[np.where(if_control[batch_samples_idx])[0]]
1425
1426
  batch_controls_mean = np.mean(cur_h[:, batch_controls_idx], axis=1)
1426
1427
  else:
1427
1428
  batch_controls_mean = all_controls_mean
@@ -1432,6 +1433,39 @@ def compute_relative_responses(cur_h: np.ndarray,
1432
1433
  return relative_h
1433
1434
 
1434
1435
 
1436
+ def average_batch_control(hgrad_raw: np.ndarray,
1437
+ if_control: np.ndarray,
1438
+ batch_index: np.ndarray) -> np.ndarray:
1439
+ """
1440
+ Assign the gradient of control samples as the average gradient of the samples in the same batch.
1441
+
1442
+ Parameters
1443
+ ----------
1444
+ hgrad : np.ndarray
1445
+ The gradient of the h matrix.
1446
+ if_control : np.ndarray
1447
+ A boolean array indicating which samples are control samples.
1448
+ batch_index : np.ndarray
1449
+ An array indicating the batch assignment for each sample.
1450
+ """
1451
+
1452
+ hgrad = hgrad_raw.copy()
1453
+
1454
+ unique_batches = np.unique(batch_index)
1455
+ num_batches = len(unique_batches)
1456
+
1457
+ for current_batch in unique_batches:
1458
+ batch_samples_idx = np.where(batch_index == current_batch)[0]
1459
+
1460
+ if np.any(if_control[batch_samples_idx]):
1461
+ if np.any(if_control[batch_samples_idx]):
1462
+ batch_controls_idx = batch_samples_idx[np.where(if_control[batch_samples_idx])[0]]
1463
+ batch_mean = np.mean(hgrad_raw[:, batch_samples_idx], axis=1)
1464
+
1465
+ hgrad[:, batch_controls_idx] = batch_mean[:, np.newaxis]
1466
+
1467
+ return hgrad
1468
+
1435
1469
  def select_representative_sample(raw_data: List[Tuple[np.ndarray, np.ndarray]],
1436
1470
  num_select: int) -> List[int]:
1437
1471
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dspin
3
- Version: 1.4.2
3
+ Version: 1.4.3
4
4
  Summary: Regulatory network models from single-cell perturbation profiling
5
5
  Home-page: https://github.com/JialongJiang/DSPIN
6
6
  Author: Jialong Jiang
@@ -21,7 +21,7 @@ install_requires = [
21
21
  # ]
22
22
 
23
23
  # Managing your version (adjust accordingly)
24
- version = "1.4.2" # You can manage versioning in a more sophisticated way if needed
24
+ version = "1.4.3" # You can manage versioning in a more sophisticated way if needed
25
25
 
26
26
  # Long description (usually a README file)
27
27
  readme = open("README_PyPI.md").read() # Adjust the file name if necessary
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