annotate src/samer/units/NoisyLinearSource.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 /*
samer@0 2 * Copyright (c) 2000, Samer Abdallah, King's College London.
samer@0 3 * All rights reserved.
samer@0 4 *
samer@0 5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 6 * without even the implied warranty of MERCHANTABILITY or
samer@0 7 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 8 */
samer@0 9
samer@0 10 package samer.units;
samer@0 11 import samer.core.*;
samer@0 12 import samer.maths.*;
samer@0 13 import samer.tools.*;
samer@0 14
samer@0 15 /**
samer@0 16 A class for generating random vectors according
samer@0 17 to a particular generative model. If the output
samer@0 18 is y, then
samer@0 19 y = Bx + e
samer@0 20 where x is a vector of indepedent identitically
samer@0 21 distributed random variables, e is another vector of
samer@0 22 iid random variables, and B is an arbitrary matrix.
samer@0 23 The elements of x are the 'sources' and are drawn from
samer@0 24 the random number generator rnd. The elements of e
samer@0 25 are the 'noise' and are drawn from a different generator,
samer@0 26 which defaults to Gaussian.
samer@0 27 */
samer@0 28
samer@0 29 public class NoisyLinearSource extends AnonymousTask
samer@0 30 {
samer@0 31 public VGenerator src, noise;
samer@0 32
samer@0 33 VVector s; // sources
samer@0 34 VVector x; // mixtures
samer@0 35 VVector e; // noise
samer@0 36 Matrix A; // mixing matrix
samer@0 37
samer@0 38 double [] xa, ea;
samer@0 39 Task t1, t2;
samer@0 40
samer@0 41 public NoisyLinearSource( int m, int n) throws Exception
samer@0 42 {
samer@0 43 // super("source");
samer@0 44
samer@0 45 // Shell.push(node);
samer@0 46 s = new VVector("s",m);
samer@0 47 x = new VVector("x",n);
samer@0 48 e = new VVector("e",n);
samer@0 49 A = new Matrix("A",n,m);
samer@0 50 A.identity();
samer@0 51
samer@0 52 src = new VGenerator("source");
samer@0 53 noise = new VGenerator("noise");
samer@0 54 // Shell.pop();
samer@0 55
samer@0 56 xa=s.array();
samer@0 57 ea=e.array();
samer@0 58 t1 = new MatrixTimesVector(x,A,s);
samer@0 59 t2 = new VectorPlusEqualsVector(x,e);
samer@0 60 }
samer@0 61
samer@0 62 public VVector output() { return x; }
samer@0 63 public Matrix getMixingMatrix() { return A; }
samer@0 64
samer@0 65 public void run() throws Exception {
samer@0 66 src.next(xa);
samer@0 67 noise.next(ea);
samer@0 68 t1.run();
samer@0 69 t2.run();
samer@0 70 s.changed();
samer@0 71 x.changed();
samer@0 72 e.changed();
samer@0 73 }
samer@0 74
samer@0 75 public void dispose()
samer@0 76 {
samer@0 77 src.dispose();
samer@0 78 noise.dispose();
samer@0 79 s.dispose();
samer@0 80 x.dispose();
samer@0 81 e.dispose();
samer@0 82 A.dispose();
samer@0 83 t1.dispose();
samer@0 84 t2.dispose();
samer@0 85 super.dispose();
samer@0 86 }
samer@0 87 }