Skip to content

Commit fc10a77

Browse files
authored
Merge pull request #2480 from jerneju/radviz
[ENH] Radviz: new widget
2 parents 06709e9 + b2de1a5 commit fc10a77

File tree

10 files changed

+1196
-0
lines changed

10 files changed

+1196
-0
lines changed

Orange/projection/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from .cur import *
44
from .manifold import *
55
from .freeviz import *
6+
from .radviz import radviz

Orange/projection/radviz.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import numpy as np
2+
3+
from Orange.data import Domain
4+
5+
6+
def radviz(data, attrs, points=None):
7+
x = data.transform(domain=Domain(attrs)).X
8+
mask = ~np.isnan(x).any(axis=1)
9+
x = x[mask]
10+
11+
n = len(x)
12+
if not n:
13+
return None, None, mask
14+
x = normalize(x)
15+
16+
r_x = np.zeros(n)
17+
r_y = np.zeros(n)
18+
19+
m = x.shape[1]
20+
if points is not None:
21+
s = points[:, :2]
22+
else:
23+
s = np.array([(np.cos(t), np.sin(t))
24+
for t in [2.0 * np.pi * (i / float(m))
25+
for i in range(m)]])
26+
for i in range(n):
27+
row = x[i]
28+
row_ = np.repeat(np.expand_dims(row, axis=1), 2, axis=1)
29+
with np.errstate(divide='ignore', invalid='ignore'):
30+
a = (s * row_).sum(axis=0)
31+
b = row.sum()
32+
y = np.divide(a, b, out=np.zeros_like(a), where=b != 0)
33+
r_x[i] = y[0]
34+
r_y[i] = y[1]
35+
36+
return np.stack((r_x, r_y), axis=1), np.column_stack((s, attrs)), mask
37+
38+
39+
def normalize(x):
40+
"""
41+
MinMax normalization to fit a matrix in the space [0,1] by column.
42+
"""
43+
a = x.min(axis=0)
44+
b = x.max(axis=0)
45+
return (x - a[np.newaxis, :]) / ((b - a)[np.newaxis, :])
Lines changed: 37 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)