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

[ENH] Radviz: new widget #2480

Merged
merged 6 commits into from
Dec 21, 2017
Merged
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
1 change: 1 addition & 0 deletions Orange/projection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .cur import *
from .manifold import *
from .freeviz import *
from .radviz import radviz
45 changes: 45 additions & 0 deletions Orange/projection/radviz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np

from Orange.data import Domain


def radviz(data, attrs, points=None):
x = data.transform(domain=Domain(attrs)).X
mask = ~np.isnan(x).any(axis=1)
x = x[mask]

n = len(x)
if not n:
return None, None, mask
x = normalize(x)

r_x = np.zeros(n)
r_y = np.zeros(n)

m = x.shape[1]
if points is not None:
s = points[:, :2]
else:
s = np.array([(np.cos(t), np.sin(t))
for t in [2.0 * np.pi * (i / float(m))
for i in range(m)]])
for i in range(n):
row = x[i]
row_ = np.repeat(np.expand_dims(row, axis=1), 2, axis=1)
with np.errstate(divide='ignore', invalid='ignore'):
a = (s * row_).sum(axis=0)
b = row.sum()
y = np.divide(a, b, out=np.zeros_like(a), where=b != 0)
r_x[i] = y[0]
r_y[i] = y[1]

return np.stack((r_x, r_y), axis=1), np.column_stack((s, attrs)), mask


def normalize(x):
"""
MinMax normalization to fit a matrix in the space [0,1] by column.
"""
a = x.min(axis=0)
b = x.max(axis=0)
return (x - a[np.newaxis, :]) / ((b - a)[np.newaxis, :])
37 changes: 37 additions & 0 deletions Orange/widgets/visualize/icons/Radviz.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading