Skip to content

Commit

Permalink
Revert "remove one-encoding for binary target"
Browse files Browse the repository at this point in the history
This reverts commit 8ac69b6.
  • Loading branch information
pegerto-ck committed Mar 26, 2024
1 parent 8ac69b6 commit f481063
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/graphpro/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NodeTargetBinaryAttribute(NodeTarget):
"""
def encode(self, G: Graph) -> torch.Tensor:
present = [self.attr_name in G.node_attr(n) for n in G.nodes()]
return torch.tensor([present], dtype=torch.int64).to(torch.float).T
return F.one_hot(torch.tensor(present, dtype=torch.int64), num_classes=2).to(torch.float)


class NodeAnnotation():
Expand Down Expand Up @@ -76,4 +76,4 @@ def generate(self, G: Graph, atom_group: AtomGroup):

def encode(self, G: Graph) -> torch.tensor:
total_area = [G.node_attr(n)[self.attr_name] if self.attr_name in G.node_attr(n) else 0 for n in G.nodes()]
return F.normalize(torch.tensor([total_area], dtype=torch.float).T, dim=(0,1))
return F.normalize(torch.tensor([total_area], dtype=torch.float).T, dim=(0,1))
6 changes: 3 additions & 3 deletions test/graphpro/annotations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_node_target_binary():

target = NodeTargetBinaryAttribute("test_attr")
y = target.encode(G)
assert y.size() == (214, 1)
assert torch.all(y[0].eq(torch.tensor([0.])))
assert torch.all(y[1].eq(torch.tensor([1.])))
assert y.size() == (214,2)
assert torch.all(y[0].eq(torch.tensor([1., 0.])))
assert torch.all(y[1].eq(torch.tensor([0., 1.])))


def test_resname_annotation():
Expand Down
2 changes: 1 addition & 1 deletion test/graphpro/graph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def test_to_data_x_transformer():

def test_to_data_y_target():
data = SIMPLE_G_ATTR.to_data(node_encoders= [ResidueType()], target = NodeTargetBinaryAttribute("target"))
assert data.y.size() == (2,1)
assert data.y.size() == (2,2)

0 comments on commit f481063

Please sign in to comment.