``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79``` ```from numpy import dot, zeros, column_stack, vstack, concatenate, random as rnd import Orange def to_table(X, y=None): n, m = X.shape features = [Orange.feature.Continuous('f%i' % i) for i in range(m)] if y is None: return Orange.data.Table(Orange.data.Domain(features, False), X) else: return Orange.data.Table( Orange.data.Domain(features, Orange.feature.Continuous('class')), column_stack((X, y))) class Generator(object): def generate_matrix(self, **kwargs): data = self.generate_table(**kwargs) return data.to_numpy()[:2] def generate_table(self, **kwargs): data = self.generate_matrix(**kwargs) return to_table(*data) def __call__(self, orange=True, **kwargs): if orange: return self.generate_table(**kwargs) else: return self.generate_matrix(**kwargs) class Group(Generator): def __init__(self, groups=10, pergroup=20, factors=[5, 4, 3, 2, 1], tasks=20, overlap=2, seed=42): self.groups = groups self.pergroup = pergroup self.factors = factors self.m = groups * (pergroup - overlap) + overlap self.tasks = tasks self.seed = seed rnd.seed(seed) self.transform = zeros((self.m, sum(factors))) f = 0 for i, k in enumerate(factors): start = i * (pergroup - overlap) self.transform[start:start + pergroup, f:f + k] = \ rnd.normal(0, 1, (pergroup, k)) f += k mus = rnd.normal(0, 1, sum(factors)) self.weights = rnd.normal(mus, 1, (tasks, sum(factors))) self.intercepts = rnd.normal(100, 20, tasks) def get_model(self): return self.transform, self.weights, self.intercepts def generate_matrix(self, pertask=50, seed=None): if seed is None: seed = self.seed rnd.seed(seed) Xs = [rnd.normal(0, 1, (pertask, self.m)) for _ in range(self.tasks)] ys = [dot(dot(X, self.transform), w) + i for X, w, i in zip(Xs, self.weights, self.intercepts)] X = vstack(Xs) y = concatenate(ys) y += rnd.normal(0, 1, len(y)) return (X, y) def __call__(self, **kwargs): data = self.generate_table(**kwargs) values=[str(i) for i in range(self.tasks)] task = Orange.feature.Discrete('task', values=values) id = Orange.feature.Descriptor.new_meta_id() data.domain.add_meta(id, task) for ins, t in zip(data, (str(i) for i in range(self.tasks) for _ in range(len(data) // self.tasks))): ins[task] = t return data ```