dspin 1.5.0__tar.gz → 1.5.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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.1
2
2
  Name: dspin
3
- Version: 1.5.0
3
+ Version: 1.5.2
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
@@ -25,18 +25,6 @@ Requires-Dist: scanpy
25
25
  Requires-Dist: tqdm
26
26
  Requires-Dist: igraph
27
27
  Requires-Dist: leidenalg
28
- Dynamic: author
29
- Dynamic: author-email
30
- Dynamic: classifier
31
- Dynamic: description
32
- Dynamic: description-content-type
33
- Dynamic: home-page
34
- Dynamic: keywords
35
- Dynamic: license
36
- Dynamic: license-file
37
- Dynamic: requires-dist
38
- Dynamic: requires-python
39
- Dynamic: summary
40
28
 
41
29
  # D-SPIN: Constructing regulatory network models from scRNA-seq perturbation profiling
42
30
 
@@ -852,11 +852,12 @@ def samp_moments(j_mat: np.ndarray,
852
852
 
853
853
 
854
854
  @numba.njit()
855
- def samp_mcmc_states(j_mat: np.ndarray,
855
+ def sample_states_mcmc(j_mat: np.ndarray,
856
856
  h_vec: np.ndarray,
857
857
  sample_size: int,
858
858
  mixing_time: int,
859
- samp_gap: int) -> np.ndarray:
859
+ samp_gap: int,
860
+ seed: int = None) -> np.ndarray:
860
861
  """
861
862
  Sample states for the Markov Chain Monte Carlo (MCMC).
862
863
 
@@ -872,6 +873,8 @@ def samp_mcmc_states(j_mat: np.ndarray,
872
873
  Mixing time for the MCMC.
873
874
  samp_gap : int
874
875
  Gap between samples.
876
+ seed : int, optional
877
+ Seed for the random number generator. Default is None.
875
878
 
876
879
  Returns
877
880
  -------
@@ -891,8 +894,10 @@ def samp_mcmc_states(j_mat: np.ndarray,
891
894
  # Cast & make contiguous (Numba-safe)
892
895
  j_mat = np.ascontiguousarray(j_mat.astype(np.float64))
893
896
  # Accept both (n,) and (n,1) h_vec; flatten to 1D
894
- h_vec = h_vec.reshape(h_vec.size)
895
- h_vec = np.ascontiguousarray(h_vec.astype(np.float64))
897
+ h_vec = np.ascontiguousarray(h_vec.astype(np.float64)).reshape(- 1)
898
+
899
+ if seed is not None:
900
+ np.random.seed(seed)
896
901
 
897
902
  # Spins in {-1,0,1}
898
903
  cur_spin = (np.random.randint(0, 3, num_spin) - 1).astype(np.float64)
@@ -1272,7 +1277,7 @@ def learn_network_adam(raw_data: Any,
1272
1277
  rec_jgrad_sum_norm = np.inf * np.ones(num_epoch)
1273
1278
  mjj, vjj = np.zeros(cur_j.shape), np.zeros(cur_j.shape)
1274
1279
  mhh, vhh = np.zeros(cur_h.shape), np.zeros(cur_h.shape)
1275
- log_adam_grad = {name: deque(maxlen=backtrack_gap)
1280
+ log_adam_grad = {name: deque(maxlen=backtrack_gap + 1)
1276
1281
  for name in ["mjj", "vjj", "mhh", "vhh"]}
1277
1282
 
1278
1283
  apply_regularization(np.zeros((num_spin, num_spin, num_round)), np.zeros((num_spin, num_round)), cur_j, cur_h, train_dat, print_regu=True)
@@ -1322,7 +1327,6 @@ def learn_network_adam(raw_data: Any,
1322
1327
  pbar.set_postfix({"Network Gradient": f"{rec_jgrad_sum_norm[counter - 1]:.6f}"})
1323
1328
 
1324
1329
  # Handle backtracking
1325
-
1326
1330
  if_backtrack = False
1327
1331
 
1328
1332
  if (counter > backtrack_gap) and (rec_jgrad_sum_norm[counter - 1] > 1.5 * rec_jgrad_sum_norm[counter - 1 - backtrack_gap]):
@@ -1339,9 +1343,12 @@ def learn_network_adam(raw_data: Any,
1339
1343
  if if_backtrack:
1340
1344
  print('Backtracking at epoch %d' % counter)
1341
1345
  backtrack_counter += 1
1346
+ cur_j = rec_jmat_all[counter - 1 - backtrack_gap, :, :]
1347
+ cur_h = rec_hvec_all[counter - 1 - backtrack_gap, :, :]
1348
+
1342
1349
  mjj, vjj, mhh, vhh = [log_adam_grad[key][0]
1343
1350
  for key in ['mjj', 'vjj', 'mhh', 'vhh']]
1344
- counter = counter - backtrack_gap
1351
+ counter = counter - backtrack_gap + 1
1345
1352
  stepsz = stepsz / 4
1346
1353
  if backtrack_counter > backtrack_tol:
1347
1354
  print(
@@ -1354,8 +1361,9 @@ def learn_network_adam(raw_data: Any,
1354
1361
  pbar.close()
1355
1362
 
1356
1363
  # Retrieve parameters corresponding to the minimum gradient norm found during training
1357
- trace_epoch = 50 + num_epoch - counter
1358
- pos = num_epoch - trace_epoch + np.argmin(rec_jgrad_sum_norm[- trace_epoch: ])
1364
+ trace_range = np.sort(np.where(rec_jgrad_sum_norm < np.inf)[0])[- 50 :]
1365
+ pos = trace_range[np.argmin(rec_jgrad_sum_norm[trace_range])]
1366
+
1359
1367
  # print(pos)
1360
1368
  cur_h = rec_hvec_all[pos, :, :]
1361
1369
  cur_j = rec_jmat_all[pos, :, :]
@@ -1420,7 +1428,7 @@ def learn_program_regulators(gene_states: List[np.ndarray],
1420
1428
  rec_selfj_all = np.zeros((num_epoch, num_program))
1421
1429
  rec_selfh_all = np.zeros((num_epoch, num_program))
1422
1430
 
1423
- rec_grad = np.zeros(num_epoch)
1431
+ rec_grad = np.ones(num_epoch) * np.inf
1424
1432
 
1425
1433
  m_interaction, v_interaction = np.zeros_like(cur_interaction), np.zeros_like(cur_interaction)
1426
1434
  m_selfj, v_selfj = np.zeros_like(cur_selfj), np.zeros_like(cur_selfj)
@@ -1440,7 +1448,7 @@ def learn_program_regulators(gene_states: List[np.ndarray],
1440
1448
  rec_selfj_grad = np.zeros((num_round, num_program))
1441
1449
  rec_selfh_grad = np.zeros((num_round, num_program))
1442
1450
 
1443
- log_adam_grad = {name: deque(maxlen=backtrack_gap)
1451
+ log_adam_grad = {name: deque(maxlen=backtrack_gap + 1)
1444
1452
  for name in ["m_interaction", "v_interaction", "m_selfj", "v_selfj", "m_selfh", "v_selfh"]}
1445
1453
 
1446
1454
  tqdm._instances.clear()
@@ -1539,8 +1547,9 @@ def learn_program_regulators(gene_states: List[np.ndarray],
1539
1547
  pbar.close()
1540
1548
 
1541
1549
  # Retrieve parameters corresponding to the minimum gradient norm found during training
1542
- trace_epoch = 50 + num_epoch - counter
1543
- pos = num_epoch - trace_epoch + np.argmin(rec_grad[- trace_epoch: ])
1550
+ trace_range = np.sort(np.where(rec_grad < np.inf)[0])[- 50 :]
1551
+ pos = trace_range[np.argmin(rec_grad[trace_range])]
1552
+
1544
1553
  cur_interaction = rec_interaction_all[pos, :, :]
1545
1554
  cur_selfj = rec_selfj_all[pos, :]
1546
1555
  cur_selfh = rec_selfh_all[pos, :]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.1
2
2
  Name: dspin
3
- Version: 1.5.0
3
+ Version: 1.5.2
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
@@ -25,18 +25,6 @@ Requires-Dist: scanpy
25
25
  Requires-Dist: tqdm
26
26
  Requires-Dist: igraph
27
27
  Requires-Dist: leidenalg
28
- Dynamic: author
29
- Dynamic: author-email
30
- Dynamic: classifier
31
- Dynamic: description
32
- Dynamic: description-content-type
33
- Dynamic: home-page
34
- Dynamic: keywords
35
- Dynamic: license
36
- Dynamic: license-file
37
- Dynamic: requires-dist
38
- Dynamic: requires-python
39
- Dynamic: summary
40
28
 
41
29
  # D-SPIN: Constructing regulatory network models from scRNA-seq perturbation profiling
42
30
 
@@ -21,7 +21,7 @@ install_requires = [
21
21
  # ]
22
22
 
23
23
  # Managing your version (adjust accordingly)
24
- version = "1.5.0" # You can manage versioning in a more sophisticated way if needed
24
+ version = "1.5.2" # 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