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.
- {dspin-1.4.2/dspin.egg-info → dspin-1.4.3}/PKG-INFO +1 -1
- {dspin-1.4.2 → dspin-1.4.3}/dspin/compute.py +35 -1
- {dspin-1.4.2 → dspin-1.4.3/dspin.egg-info}/PKG-INFO +1 -1
- {dspin-1.4.2 → dspin-1.4.3}/setup.py +1 -1
- {dspin-1.4.2 → dspin-1.4.3}/LICENSE +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/README.md +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/__init__.cpython-310.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/__init__.cpython-37.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/compute.cpython-310.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/compute.cpython-37.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/dspin_abstract.cpython-310.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/plot.cpython-310.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/__pycache__/plotting.cpython-37.pyc +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin/__init__.py +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin/annotate.py +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin/dspin.py +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin/plot.py +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin.egg-info/SOURCES.txt +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin.egg-info/dependency_links.txt +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin.egg-info/requires.txt +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/dspin.egg-info/top_level.txt +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/requirements.txt +0 -0
- {dspin-1.4.2 → dspin-1.4.3}/setup.cfg +0 -0
|
@@ -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
|
"""
|
|
@@ -21,7 +21,7 @@ install_requires = [
|
|
|
21
21
|
# ]
|
|
22
22
|
|
|
23
23
|
# Managing your version (adjust accordingly)
|
|
24
|
-
version = "1.4.
|
|
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
|
|
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
|