samer@0: /* samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.units; samer@0: import samer.core.*; samer@0: import samer.maths.*; samer@0: import samer.tools.*; samer@0: samer@0: /** samer@0: A class for generating random vectors according samer@0: to a particular generative model. If the output samer@0: is y, then samer@0: y = Bx + e samer@0: where x is a vector of indepedent identitically samer@0: distributed random variables, e is another vector of samer@0: iid random variables, and B is an arbitrary matrix. samer@0: The elements of x are the 'sources' and are drawn from samer@0: the random number generator rnd. The elements of e samer@0: are the 'noise' and are drawn from a different generator, samer@0: which defaults to Gaussian. samer@0: */ samer@0: samer@0: public class NoisyLinearSource extends AnonymousTask samer@0: { samer@0: public VGenerator src, noise; samer@0: samer@0: VVector s; // sources samer@0: VVector x; // mixtures samer@0: VVector e; // noise samer@0: Matrix A; // mixing matrix samer@0: samer@0: double [] xa, ea; samer@0: Task t1, t2; samer@0: samer@0: public NoisyLinearSource( int m, int n) throws Exception samer@0: { samer@0: // super("source"); samer@0: samer@0: // Shell.push(node); samer@0: s = new VVector("s",m); samer@0: x = new VVector("x",n); samer@0: e = new VVector("e",n); samer@0: A = new Matrix("A",n,m); samer@0: A.identity(); samer@0: samer@0: src = new VGenerator("source"); samer@0: noise = new VGenerator("noise"); samer@0: // Shell.pop(); samer@0: samer@0: xa=s.array(); samer@0: ea=e.array(); samer@0: t1 = new MatrixTimesVector(x,A,s); samer@0: t2 = new VectorPlusEqualsVector(x,e); samer@0: } samer@0: samer@0: public VVector output() { return x; } samer@0: public Matrix getMixingMatrix() { return A; } samer@0: samer@0: public void run() throws Exception { samer@0: src.next(xa); samer@0: noise.next(ea); samer@0: t1.run(); samer@0: t2.run(); samer@0: s.changed(); samer@0: x.changed(); samer@0: e.changed(); samer@0: } samer@0: samer@0: public void dispose() samer@0: { samer@0: src.dispose(); samer@0: noise.dispose(); samer@0: s.dispose(); samer@0: x.dispose(); samer@0: e.dispose(); samer@0: A.dispose(); samer@0: t1.dispose(); samer@0: t2.dispose(); samer@0: super.dispose(); samer@0: } samer@0: }