hippoformer 0.0.1__tar.gz → 0.0.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.
- {hippoformer-0.0.1 → hippoformer-0.0.2}/PKG-INFO +1 -1
- hippoformer-0.0.2/hippoformer/__init__.py +4 -0
- {hippoformer-0.0.1 → hippoformer-0.0.2}/hippoformer/hippoformer.py +63 -3
- {hippoformer-0.0.1 → hippoformer-0.0.2}/pyproject.toml +1 -1
- hippoformer-0.0.2/tests/test_hippoformer.py +37 -0
- hippoformer-0.0.1/hippoformer/__init__.py +0 -0
- hippoformer-0.0.1/tests/test_hippoformer.py +0 -15
- {hippoformer-0.0.1 → hippoformer-0.0.2}/.github/workflows/python-publish.yml +0 -0
- {hippoformer-0.0.1 → hippoformer-0.0.2}/.github/workflows/test.yml +0 -0
- {hippoformer-0.0.1 → hippoformer-0.0.2}/.gitignore +0 -0
- {hippoformer-0.0.1 → hippoformer-0.0.2}/LICENSE +0 -0
- {hippoformer-0.0.1 → hippoformer-0.0.2}/README.md +0 -0
- {hippoformer-0.0.1 → hippoformer-0.0.2}/hippoformer-fig6.png +0 -0
|
@@ -104,13 +104,73 @@ class PathIntegration(Module):
|
|
|
104
104
|
class mmTEM(Module):
|
|
105
105
|
def __init__(
|
|
106
106
|
self,
|
|
107
|
-
dim
|
|
107
|
+
dim,
|
|
108
|
+
*,
|
|
109
|
+
sensory_encoder: Module,
|
|
110
|
+
sensory_decoder: Module,
|
|
111
|
+
dim_sensory,
|
|
112
|
+
dim_action,
|
|
113
|
+
dim_encoded_sensory,
|
|
114
|
+
dim_structure,
|
|
115
|
+
meta_mlp_depth = 2,
|
|
116
|
+
decoder_mlp_depth = 2,
|
|
117
|
+
structure_variance_pred_mlp_depth = 2,
|
|
118
|
+
path_integrate_kwargs: dict = dict(),
|
|
119
|
+
loss_weight_generative = 1.,
|
|
120
|
+
loss_weight_inference = 1.,
|
|
121
|
+
loss_weight_consistency = 1.,
|
|
122
|
+
loss_weight_relational = 1.,
|
|
108
123
|
):
|
|
109
124
|
super().__init__()
|
|
110
125
|
|
|
126
|
+
dim_joint_rep = dim_encoded_sensory + dim_structure
|
|
127
|
+
|
|
128
|
+
# path integrator
|
|
129
|
+
|
|
130
|
+
self.path_integrator = PathIntegration(
|
|
131
|
+
dim_action = dim_action,
|
|
132
|
+
dim_structure = dim_structure,
|
|
133
|
+
**path_integrate_kwargs
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# meta mlp related
|
|
137
|
+
|
|
138
|
+
self.to_queries = nn.Linear(dim_joint_rep, dim, bias = False)
|
|
139
|
+
self.to_keys = nn.Linear(dim_joint_rep, dim, bias = False)
|
|
140
|
+
self.to_values = nn.Linear(dim_joint_rep, dim, bias = False)
|
|
141
|
+
|
|
142
|
+
self.meta_mlp = create_mlp(
|
|
143
|
+
dim = dim * 2,
|
|
144
|
+
depth = meta_mlp_depth,
|
|
145
|
+
dim_in = dim,
|
|
146
|
+
dim_out = dim,
|
|
147
|
+
activation = nn.ReLU()
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# mlp decoder (from meta mlp output to joint)
|
|
151
|
+
|
|
152
|
+
self.meta_mlp_output_decoder = create_mlp(
|
|
153
|
+
dim = dim * 2,
|
|
154
|
+
dim_in = dim,
|
|
155
|
+
dim_out = dim_joint_rep,
|
|
156
|
+
depth = decoder_mlp_depth,
|
|
157
|
+
activation = nn.ReLU()
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# the mlp that predicts the variance for the structural code
|
|
161
|
+
# for correcting the generated structural code modeling the feedback from HC to MEC
|
|
162
|
+
|
|
163
|
+
self.structure_variance_pred_mlp_depth = create_mlp(
|
|
164
|
+
dim = dim_structure * 2,
|
|
165
|
+
dim_in = dim_structure * 2 + 1,
|
|
166
|
+
dim_out = dim_structure,
|
|
167
|
+
depth = structure_variance_pred_mlp_depth
|
|
168
|
+
)
|
|
111
169
|
|
|
112
170
|
def forward(
|
|
113
171
|
self,
|
|
114
|
-
|
|
172
|
+
sensory,
|
|
173
|
+
actions
|
|
115
174
|
):
|
|
116
|
-
|
|
175
|
+
structural_codes = self.path_integrator(actions)
|
|
176
|
+
return structural_codes.sum()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
|
|
5
|
+
def test_path_integrate():
|
|
6
|
+
from hippoformer.hippoformer import PathIntegration
|
|
7
|
+
|
|
8
|
+
path_integrator = PathIntegration(32, 64)
|
|
9
|
+
|
|
10
|
+
actions = torch.randn(2, 16, 32)
|
|
11
|
+
|
|
12
|
+
structure_codes = path_integrator(actions)
|
|
13
|
+
structure_codes = path_integrator(actions, structure_codes) # pass in previous structure codes, it will auto use the last one as hidden and pass it to the RNN
|
|
14
|
+
|
|
15
|
+
assert structure_codes.shape == (2, 16, 64)
|
|
16
|
+
|
|
17
|
+
def test_mm_tem():
|
|
18
|
+
import torch
|
|
19
|
+
from hippoformer.hippoformer import mmTEM
|
|
20
|
+
|
|
21
|
+
from torch.nn import Linear
|
|
22
|
+
|
|
23
|
+
model = mmTEM(
|
|
24
|
+
dim = 32,
|
|
25
|
+
sensory_encoder = Linear(11, 32),
|
|
26
|
+
sensory_decoder = Linear(32, 11),
|
|
27
|
+
dim_sensory = 11,
|
|
28
|
+
dim_action = 7,
|
|
29
|
+
dim_structure = 32,
|
|
30
|
+
dim_encoded_sensory = 32
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
actions = torch.randn(2, 16, 7)
|
|
34
|
+
sensory = torch.randn(2, 16, 11)
|
|
35
|
+
|
|
36
|
+
loss = model(sensory, actions)
|
|
37
|
+
loss.backward()
|
|
File without changes
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
|
-
import torch
|
|
4
|
-
|
|
5
|
-
def test_path_integrate():
|
|
6
|
-
from hippoformer.hippoformer import PathIntegration
|
|
7
|
-
|
|
8
|
-
path_integrator = PathIntegration(32, 64)
|
|
9
|
-
|
|
10
|
-
actions = torch.randn(2, 16, 32)
|
|
11
|
-
|
|
12
|
-
structure_codes = path_integrator(actions)
|
|
13
|
-
structure_codes = path_integrator(actions, structure_codes) # pass in previous structure codes, it will auto use the last one as hidden and pass it to the RNN
|
|
14
|
-
|
|
15
|
-
assert structure_codes.shape == (2, 16, 64)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|