rbms 0.4.0__tar.gz → 0.4.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.
Files changed (76) hide show
  1. {rbms-0.4.0 → rbms-0.4.2}/PKG-INFO +1 -1
  2. {rbms-0.4.0 → rbms-0.4.2}/pyproject.toml +1 -1
  3. {rbms-0.4.0 → rbms-0.4.2}/rbms/bernoulli_bernoulli/implement.py +3 -3
  4. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/parser.py +9 -2
  5. {rbms-0.4.0 → rbms-0.4.2}/rbms/potts_bernoulli/classes.py +1 -1
  6. {rbms-0.4.0 → rbms-0.4.2}/rbms/potts_bernoulli/implement.py +4 -4
  7. {rbms-0.4.0 → rbms-0.4.2}/rbms/scripts/train_rbm.py +2 -1
  8. {rbms-0.4.0 → rbms-0.4.2}/rbms/training/pcd.py +11 -1
  9. {rbms-0.4.0 → rbms-0.4.2}/rbms/training/utils.py +2 -1
  10. {rbms-0.4.0 → rbms-0.4.2}/.github/workflows/codecov.yaml +0 -0
  11. {rbms-0.4.0 → rbms-0.4.2}/.github/workflows/test.yaml +0 -0
  12. {rbms-0.4.0 → rbms-0.4.2}/.github/workflows/whats_new.yaml +0 -0
  13. {rbms-0.4.0 → rbms-0.4.2}/.gitignore +0 -0
  14. {rbms-0.4.0 → rbms-0.4.2}/LICENSE +0 -0
  15. {rbms-0.4.0 → rbms-0.4.2}/MANIFEST.in +0 -0
  16. {rbms-0.4.0 → rbms-0.4.2}/README.md +0 -0
  17. {rbms-0.4.0 → rbms-0.4.2}/rbms/__init__.py +0 -0
  18. {rbms-0.4.0 → rbms-0.4.2}/rbms/bernoulli_bernoulli/__init__.py +0 -0
  19. {rbms-0.4.0 → rbms-0.4.2}/rbms/bernoulli_bernoulli/classes.py +0 -0
  20. {rbms-0.4.0 → rbms-0.4.2}/rbms/bernoulli_bernoulli/functional.py +0 -0
  21. {rbms-0.4.0 → rbms-0.4.2}/rbms/classes.py +0 -0
  22. {rbms-0.4.0 → rbms-0.4.2}/rbms/const.py +0 -0
  23. {rbms-0.4.0 → rbms-0.4.2}/rbms/custom_fn.py +0 -0
  24. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/__init__.py +0 -0
  25. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/dataset_class.py +0 -0
  26. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/fasta_utils.py +0 -0
  27. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/load_fasta.py +0 -0
  28. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/load_h5.py +0 -0
  29. {rbms-0.4.0 → rbms-0.4.2}/rbms/dataset/utils.py +0 -0
  30. {rbms-0.4.0 → rbms-0.4.2}/rbms/io.py +0 -0
  31. {rbms-0.4.0 → rbms-0.4.2}/rbms/map_model.py +0 -0
  32. {rbms-0.4.0 → rbms-0.4.2}/rbms/metrics/__init__.py +0 -0
  33. {rbms-0.4.0 → rbms-0.4.2}/rbms/metrics/aats.py +0 -0
  34. {rbms-0.4.0 → rbms-0.4.2}/rbms/parser.py +0 -0
  35. {rbms-0.4.0 → rbms-0.4.2}/rbms/partition_function/ais.py +0 -0
  36. {rbms-0.4.0 → rbms-0.4.2}/rbms/partition_function/exact.py +0 -0
  37. {rbms-0.4.0 → rbms-0.4.2}/rbms/plot.py +0 -0
  38. {rbms-0.4.0 → rbms-0.4.2}/rbms/potts_bernoulli/__init__.py +0 -0
  39. {rbms-0.4.0 → rbms-0.4.2}/rbms/potts_bernoulli/functional.py +0 -0
  40. {rbms-0.4.0 → rbms-0.4.2}/rbms/potts_bernoulli/tools.py +0 -0
  41. {rbms-0.4.0 → rbms-0.4.2}/rbms/potts_bernoulli/utils.py +0 -0
  42. {rbms-0.4.0 → rbms-0.4.2}/rbms/sampling/gibbs.py +0 -0
  43. {rbms-0.4.0 → rbms-0.4.2}/rbms/sampling/pt.py +0 -0
  44. {rbms-0.4.0 → rbms-0.4.2}/rbms/scripts/__init__.py +0 -0
  45. {rbms-0.4.0 → rbms-0.4.2}/rbms/scripts/entrypoint.py +0 -0
  46. {rbms-0.4.0 → rbms-0.4.2}/rbms/scripts/pt_sampling.py +0 -0
  47. {rbms-0.4.0 → rbms-0.4.2}/rbms/utils.py +0 -0
  48. {rbms-0.4.0 → rbms-0.4.2}/tests/conftest.py +0 -0
  49. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_compute_energy_bbrbm.py +0 -0
  50. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_compute_energy_hiddens_bbrbm.py +0 -0
  51. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_compute_energy_visibles_bbrbm.py +0 -0
  52. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_compute_gradient_bbrbm.py +0 -0
  53. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_init_chains_bbrbm.py +0 -0
  54. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_init_parameters_bbrbm.py +0 -0
  55. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_sample_hiddens_bbrbm.py +0 -0
  56. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/implement/test_sample_visibles_bbrbm.py +0 -0
  57. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/test_bernoulli_utils_bbrbm.py +0 -0
  58. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/test_functional_bbrbm.py +0 -0
  59. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/bernoulli_bernoulli/test_methods_bbrbm.py +0 -0
  60. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/metrics/test_aats.py +0 -0
  61. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_compute_energy_hiddens_pbrbm.py +0 -0
  62. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_compute_energy_pbrbm.py +0 -0
  63. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_compute_energy_visibles_pbrbm.py +0 -0
  64. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_compute_gradient_pbrbm.py +0 -0
  65. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_init_chains_pbrbm.py +0 -0
  66. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_init_parameters_pbrbm.py +0 -0
  67. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_sample_hiddens_pbrbm.py +0 -0
  68. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/implement/test_sample_visibles_pbrbm.py +0 -0
  69. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/test_functional_pbrbm.py +0 -0
  70. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/test_methods_pbrbm.py +0 -0
  71. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/potts_bernoulli/test_utils_pbrbm.py +0 -0
  72. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/test_custom_fn.py +0 -0
  73. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/test_utils.py +0 -0
  74. {rbms-0.4.0 → rbms-0.4.2}/tests/unit_test/training/test_pcd.py +0 -0
  75. {rbms-0.4.0 → rbms-0.4.2}/tests/use_cases/test_bbrbm.py +0 -0
  76. {rbms-0.4.0 → rbms-0.4.2}/tests/use_cases/test_pbrbm.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rbms
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Training and analyzing Restricted Boltzmann Machines in PyTorch
5
5
  Project-URL: Homepage, https://github.com/DsysDML/rbms
6
6
  Project-URL: Issues, https://github.com/DsysDML/rbms/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "rbms"
7
- version = "0.4.0"
7
+ version = "0.4.2"
8
8
  authors = [
9
9
  {name="Nicolas Béreux", email="nicolas.bereux@gmail.com"},
10
10
  {name="Aurélien Decelle"},
@@ -121,9 +121,9 @@ def _compute_gradient(
121
121
  grad_hbias = h_data_mean - h_gen_mean
122
122
 
123
123
  if lambda_l1 > 0:
124
- grad_weight_matrix -= 2 * lambda_l2 * torch.sign(weight_matrix)
125
- grad_vbias -= 2 * lambda_l2 * torch.sign(vbias)
126
- grad_hbias -= 2 * lambda_l2 * torch.sign(hbias)
124
+ grad_weight_matrix -= lambda_l1 * torch.sign(weight_matrix)
125
+ grad_vbias -= lambda_l1 * torch.sign(vbias)
126
+ grad_hbias -= lambda_l1 * torch.sign(hbias)
127
127
 
128
128
  if lambda_l2 > 0:
129
129
  grad_weight_matrix -= 2 * lambda_l2 * weight_matrix
@@ -8,10 +8,17 @@ def add_args_dataset(parser: argparse.ArgumentParser) -> argparse.ArgumentParser
8
8
  dataset_args = parser.add_argument_group("Dataset")
9
9
  dataset_args.add_argument(
10
10
  "-d",
11
- "--data",
11
+ "--dataset",
12
12
  type=str,
13
13
  required=True,
14
- help="Name of the dataset ('HGD', 'MNIST', 'BKACE', 'PF00072', 'PF13354'), or path to a data file (type should be .h5 or .fasta)",
14
+ help="Path to a data file (type should be .h5 or .fasta)",
15
+ )
16
+ dataset_args.add_argument(
17
+ "--test_dataset",
18
+ type=str,
19
+ required=False,
20
+ default=None,
21
+ help="Path to test dataset file (type should be .h5 or .fasta)",
15
22
  )
16
23
  dataset_args.add_argument(
17
24
  "--subset_labels",
@@ -119,7 +119,7 @@ class PBRBM(RBM):
119
119
  hbias=self.hbias,
120
120
  weight_matrix=self.weight_matrix,
121
121
  centered=centered,
122
- lambda_l1=0.0,
122
+ lambda_l1=lambda_l1,
123
123
  lambda_l2=lambda_l2,
124
124
  )
125
125
 
@@ -179,11 +179,11 @@ def _compute_gradient(
179
179
  grad_hbias = h_data_mean - h_gen_mean
180
180
 
181
181
  if lambda_l1 > 0:
182
- grad_weight_matrix -= 2 * lambda_l2 * torch.sign(weight_matrix)
183
- grad_vbias -= 2 * lambda_l2 * torch.sign(vbias)
184
- grad_hbias -= 2 * lambda_l2 * torch.sign(hbias)
182
+ grad_weight_matrix -= lambda_l1 * torch.sign(weight_matrix)
183
+ grad_vbias -= lambda_l1 * torch.sign(vbias)
184
+ grad_hbias -= lambda_l1 * torch.sign(hbias)
185
185
 
186
- if lambda_l2 != 0:
186
+ if lambda_l2 > 0:
187
187
  grad_weight_matrix -= 2 * lambda_l2 * weight_matrix
188
188
  grad_vbias -= 2 * lambda_l2 * vbias
189
189
  grad_hbias -= 2 * lambda_l2 * hbias
@@ -36,7 +36,8 @@ def train_rbm(args: dict):
36
36
  num_updates=args["num_updates"], n_save=args["n_save"], spacing=args["spacing"]
37
37
  )
38
38
  train_dataset, test_dataset = load_dataset(
39
- dataset_name=args["data"],
39
+ dataset_name=args["dataset"],
40
+ test_dataset_name=args["test_dataset"],
40
41
  subset_labels=args["subset_labels"],
41
42
  use_weights=args["use_weights"],
42
43
  alphabet=args["alphabet"],
@@ -24,6 +24,8 @@ def fit_batch_pcd(
24
24
  gibbs_steps: int,
25
25
  beta: float,
26
26
  centered: bool = True,
27
+ lambda_l1: float = 0.0,
28
+ lambda_l2: float = 0.0,
27
29
  ) -> Tuple[dict[str, Tensor], dict]:
28
30
  """Sample the EBM and compute the gradient.
29
31
 
@@ -48,7 +50,13 @@ def fit_batch_pcd(
48
50
  parallel_chains = params.sample_state(
49
51
  chains=parallel_chains, n_steps=gibbs_steps, beta=beta
50
52
  )
51
- params.compute_gradient(data=curr_batch, chains=parallel_chains, centered=centered)
53
+ params.compute_gradient(
54
+ data=curr_batch,
55
+ chains=parallel_chains,
56
+ centered=centered,
57
+ lambda_l1=lambda_l1,
58
+ lambda_l2=lambda_l2,
59
+ )
52
60
  logs = {}
53
61
  return parallel_chains, logs
54
62
 
@@ -123,6 +131,8 @@ def train(
123
131
  gibbs_steps=args["gibbs_steps"],
124
132
  beta=args["beta"],
125
133
  centered=not (args["no_center"]),
134
+ lambda_l1=args["L1"],
135
+ lambda_l2=args["L2"],
126
136
  )
127
137
  optimizer.step()
128
138
  if isinstance(params, PBRBM):
@@ -201,6 +201,7 @@ def initialize_model_archive(
201
201
  train_dataset: RBMDataset,
202
202
  test_dataset: Optional[RBMDataset],
203
203
  dtype: torch.dtype,
204
+ flags: List[str] = ["checkpoint"],
204
205
  ):
205
206
  num_visibles = train_dataset.get_num_visibles()
206
207
  args = set_args_default(args=args, default_args=default_args)
@@ -229,7 +230,7 @@ def initialize_model_archive(
229
230
  learning_rate=args["learning_rate"],
230
231
  train_size=args["train_size"],
231
232
  log=args["log"],
232
- flags=["checkpoint"],
233
+ flags=flags,
233
234
  seed=args["seed"],
234
235
  L1=args["L1"],
235
236
  L2=args["L2"],
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