#ifndef MIXTURE_NODE_H_
#define MIXTURE_NODE_H_

#include <graph/DeterministicNode.h>
#include <map>
#include <vector>

/**
 * A mixture node takes its value from one of several parents, based
 * on the current value of an index node, which is also a parent
 * @short Node for mixture models
 */
class MixtureNode : public DeterministicNode {
  std::map<Index, Node*> _map;
  std::vector<Node *> _index;
public:
  /**
   * Constructor. 
   * @param index Vector of discrete-valued scalar nodes
   * @param parameters Vector of pairs. Each pair associates a
   * possible value of the index nodes with a parent. The mixture node
   * copies its value from the parent that matches the current value
   * of the index.
   */
  MixtureNode(std::vector<Node *> const &index,
	      std::vector<std::pair<Index, Node *> > const &parameters);
  ~MixtureNode();
	
  void forwardSample();
  /** 
   * Returns the vector of index nodes.
   */
  std::vector<Node *> const &index() const;
  /**
   * Returns true if all of the parameters of the node are discrete-valued
   */
  bool isDiscreteValued() const;
};

MixtureNode const *asMixture(Node const *node);
bool isMixture(Node const *node);

#endif /* MIXTURE_NODE_H_ */


syntax highlighted by Code2HTML, v. 0.9.1