// Copyright (C) 1999 Jean-Marc Valin #include "BufferedNode.h" #include "Buffer.h" #include "Vector.h" #include "Matrix.h" #ifdef HAVE_FLOAT_H #include #endif using namespace std; namespace FD { class MarkovProb; DECLARE_NODE(MarkovProb) /*Node * * @name MarkovProb * @category HMM * @description Calculates the Markov chain probability * * @input_name INPUT * @input_description State probability * * @input_name MATRIX * @input_description Transition probability matrix * * @output_name OUTPUT * @output_description A posteriori probability * END*/ class MarkovProb : public BufferedNode { int inputID; int outputID; int matrixID; public: MarkovProb(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { inputID = addInput("INPUT"); matrixID = addInput("MATRIX"); outputID = addOutput("OUTPUT"); inOrder=1; outputs[outputID].lookBack += 1; } void calculate(int output_id, int count, Buffer &out) { ObjectRef inputValue = getInput(inputID, count); const Vector &in = object_cast > (inputValue); int length = in.size(); ObjectRef matrixValue = getInput(matrixID, count); const Matrix &mat = object_cast > (matrixValue); if (mat.nrows() != mat.nrows() || mat.nrows() != length) throw new NodeException(this, "Transition matrix has wrong size", __FILE__, __LINE__); Vector &output = *Vector::alloc(length); out[count] = &output; if (count > 0) { //ObjectRef pastValue = getOutput(outputID, count-1); //const Vector &past = object_cast > (pastValue); const Vector &past = object_cast > (out[count-1]); if (past.size() != length) throw new NodeException(this, "Number of states changed... that's odd", __FILE__, __LINE__); for (int i=0;i