samer@0: /* samer@0: * Copyright (c) 2002, 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.models; samer@0: samer@0: import samer.core.*; samer@0: import samer.core.types.*; samer@0: import samer.maths.*; samer@0: import samer.maths.opt.*; samer@0: import samer.tools.*; samer@0: samer@0: samer@0: public class Mixture extends NamedTask implements Model samer@0: { samer@0: private Model M[]; // models samer@0: private int n, m; // size of vector, num models samer@0: private Vec x; // input samer@0: private VVector w; // prior weights samer@0: private VVector s; // posterior samer@0: private int k; // MAP estimate samer@0: private VDouble Z; // Parition function, ie p(x) samer@0: private double[] _x,_s,_w,_g; samer@0: samer@0: public Mixture( Vec input, int m) { this(input.size(), m); setInput(input); } samer@0: public Mixture( int N, int L) samer@0: { samer@0: super("mixture"); samer@0: Shell.push(node); samer@0: samer@0: n = N; samer@0: m = L; samer@0: samer@0: x = null; samer@0: w = new VVector("prior",m); samer@0: s = new VVector("posterior",m); samer@0: Z = new VDouble("Z"); samer@0: M = new Model[m]; samer@0: Shell.pop(); samer@0: samer@0: _s=s.array(); samer@0: _w=w.array(); samer@0: _g=new double[n]; samer@0: Mathx.set(_w,new Constant(1.0/L)); samer@0: } samer@0: samer@0: public VVector prior() { return w; } samer@0: public VVector posterior() { return s; } samer@0: public void setModel(int i, Model m) { M[i]=m; } samer@0: public void setInput(Vec in) { x=in; _x=x.array(); } samer@0: public int getSize() { return n; } samer@0: samer@0: public void dispose() samer@0: { samer@0: s.dispose(); samer@0: w.dispose(); samer@0: Z.dispose(); samer@0: for (int i=0; i