Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor random fixes #277

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orangecontrib/network/network/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .base import Network
from .base import Network, DirectedEdges, UndirectedEdges
5 changes: 5 additions & 0 deletions orangecontrib/network/network/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ def as_edges(edges):
self.edges = [as_edges(e) for e in edges]
else:
self.edges = [as_edges(edges)]
if not all(edges.edges.shape[0] == edges.edges.shape[1]
for edges in self.edges):
raise ValueError("Edges must be square matrices")
if not all(edges.edges.shape[0] == len(nodes) for edges in self.edges):
raise ValueError("Number of nodes and edge matrix dimension must match")
self.name = name
self.coordinates = coordinates

Expand Down
10 changes: 5 additions & 5 deletions orangecontrib/network/network/twomode.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def to_single_mode(net, mode_mask, conn_mask, weighting):
single-mode network
"""
mode_edges = _filtered_edges(net, mode_mask, conn_mask)
new_edges = Weighting[weighting].func(mode_edges)
new_edges = Weighting[weighting].func(mode_edges, np.sum(mode_mask))
return Network(net.nodes[mode_mask], new_edges)


Expand All @@ -38,7 +38,7 @@ def _normalize(a, *nominators):


def _dot_edges(normalization):
def norm_dot(edges):
def norm_dot(edges, dim):
edges = normalization(
edges, wuu=lambda: edges.sum(axis=0), wvv=lambda: edges.sum(axis=1))
new_edges = np.dot(edges, edges.T).tocoo()
Expand All @@ -47,12 +47,12 @@ def norm_dot(edges):

return sp.csr_matrix(
(new_edges.data[mask], (new_edges.row[mask], new_edges.col[mask])),
shape=new_edges.shape)
shape=(dim, dim))
return norm_dot


def _weight_no_weights(edges):
new_edges = _weight_connections(edges)
def _weight_no_weights(edges, dim):
new_edges = _weight_connections(edges, dim)
new_edges[new_edges.nonzero()] = 1
return new_edges

Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/network/networks/makeNetworkList.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os
import os.path
import glob

Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/network/widgets/tests/test_ownxsinglemode.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_show_errors(self):
self.assertFalse(no_categorical())
self.assertTrue(same_values())

net = Network(range(3), sp.csr_matrix([[0, 1], [1, 2]]))
net = Network(range(3), sp.csr_matrix([[0, 1, 0], [1, 2, 0], [0, 0, 0]]))
self.send_signal(widget.Inputs.network, net)
self.assertTrue(no_data())
self.assertFalse(no_categorical())
Expand Down
Loading