File tree Expand file tree Collapse file tree 6 files changed +50
-52
lines changed
Expand file tree Collapse file tree 6 files changed +50
-52
lines changed Original file line number Diff line number Diff line change 11__init__.py:
22 def `networks`:
33 networks: false
4+ utils.py:
5+ def `items_from_distmatrix`:
6+ label: oznaka
7+ def `weights_from_distances`:
8+ All distances must be positive: Vse razdalje morajo biti pozitivne
49network/base.py:
510 class `Network`:
611 def `__init__`:
@@ -758,11 +763,6 @@ widgets/ownxsinglemode.py:
758763 def `main`:
759764 /Users/janez/Downloads/100_petrozavodsk_171_events_no_sqrt.net: false
760765 __main__: false
761- widgets/utils.py:
762- def `items_from_distmatrix`:
763- label: oznaka
764- def `weights_from_distances`:
765- All distances must be positive: Vse razdalje morajo biti pozitivne
766766widgets/tests/utils.py:
767767 class `NetworkTest`:
768768 def `_read_network`:
Original file line number Diff line number Diff line change 44
55from Orange .misc import DistMatrix
66from Orange .data import Table , Domain , ContinuousVariable
7- from orangecontrib .network .widgets . utils import items_from_distmatrix , weights_from_distances
7+ from orangecontrib .network .utils import items_from_distmatrix , weights_from_distances
88
99
1010class TestItemsFromMatrix (unittest .TestCase ):
Original file line number Diff line number Diff line change 1+ import numpy as np
2+ from Orange .data import Table , StringVariable , Domain
3+
4+
5+ def items_from_distmatrix (matrix ):
6+ if matrix .row_items is not None :
7+ row_items = matrix .row_items
8+ if isinstance (row_items , Table ):
9+ if matrix .axis == 1 :
10+ items = row_items
11+ else :
12+ items = [[v .name ] for v in row_items .domain .attributes ]
13+ else :
14+ items = [[str (x )] for x in matrix .row_items ]
15+ else :
16+ items = [[str (i )] for i in range (1 , 1 + matrix .shape [0 ])]
17+ if not isinstance (items , Table ):
18+ items = Table .from_list (
19+ Domain ([], metas = [StringVariable ('label' )]),
20+ items )
21+ return items
22+
23+
24+ def weights_from_distances (weights ):
25+ weights = weights .astype (np .float64 )
26+
27+ if weights .size == 0 :
28+ return weights
29+
30+ mi , ma = np .nanmin (weights ), np .nanmax (weights )
31+ assert mi >= 0 , "All distances must be positive"
32+
33+ if ma - mi < 1e-6 :
34+ return np .ones (weights .shape )
35+
36+ weights /= ma
37+ weights *= np .log (10 )
38+ np .exp (weights , out = weights )
39+ np .reciprocal (weights , out = weights )
40+
41+ return weights
Original file line number Diff line number Diff line change 1919from orangecontrib .network .network import Network
2020from orangecontrib .network .network .base import UndirectedEdges , DirectedEdges
2121# This enables summarize in widget preview, pylint: disable=unused-import
22- import orangecontrib .network .widgets
23- from orangecontrib .network .widgets .utils import items_from_distmatrix , weights_from_distances
22+ from orangecontrib .network .utils import items_from_distmatrix , weights_from_distances
2423
2524
2625class QIntValidatorWithFixup (QIntValidator ):
Original file line number Diff line number Diff line change 11import numpy as np
2- from numpy .lib .stride_tricks import as_strided
32import scipy .sparse as sp
43
54from AnyQt .QtCore import Qt
1514from orangecontrib .network .network import Network
1615from orangecontrib .network .network .base import UndirectedEdges , DirectedEdges
1716# This enables summarize in widget preview, pylint: disable=unused-import
18- import orangecontrib .network .widgets
19- from orangecontrib .network .widgets .utils import items_from_distmatrix , weights_from_distances
17+ from orangecontrib .network .utils import items_from_distmatrix , weights_from_distances
2018
2119
2220class OWNxNeighbor (widget .OWWidget ):
Original file line number Diff line number Diff line change 1- import numpy as np
2- from Orange .data import Table , StringVariable , Domain
3-
4-
5- def items_from_distmatrix (matrix ):
6- if matrix .row_items is not None :
7- row_items = matrix .row_items
8- if isinstance (row_items , Table ):
9- if matrix .axis == 1 :
10- items = row_items
11- else :
12- items = [[v .name ] for v in row_items .domain .attributes ]
13- else :
14- items = [[str (x )] for x in matrix .row_items ]
15- else :
16- items = [[str (i )] for i in range (1 , 1 + matrix .shape [0 ])]
17- if not isinstance (items , Table ):
18- items = Table .from_list (
19- Domain ([], metas = [StringVariable ('label' )]),
20- items )
21- return items
22-
23-
24- def weights_from_distances (weights ):
25- weights = weights .astype (np .float64 )
26-
27- if weights .size == 0 :
28- return weights
29-
30- mi , ma = np .nanmin (weights ), np .nanmax (weights )
31- assert mi >= 0 , "All distances must be positive"
32-
33- if ma - mi < 1e-6 :
34- return np .ones (weights .shape )
35-
36- weights /= ma
37- weights *= np .log (10 )
38- np .exp (weights , out = weights )
39- np .reciprocal (weights , out = weights )
40-
41- return weights
1+ from orangecontrib .network .utils import items_from_distmatrix , weights_from_distances
You can’t perform that action at this time.
0 commit comments