package yi.stat.em;

/**
 * A component of mixture models
 */

public interface MixtureComponential {

  /**
   * Add a new sample, with weight, into the component.
   * @param data
   * @param weight
   */
  public void add(double[] data, double weight);

  /**
   * Tigger the training/learning process
   */
  public void learnTheModel() throws ModelSingularException;

  /**
   * Return the means of the samples
   * @return
   */
  public double[] getMeans() throws ModelSingularException;

  /**
   * Return the probability/density of the data under the model
   * @param data
   * @return
   */
  public double getDensity(double[] data)  throws ModelSingularException;

  /**
   * Return the sum of the probability of the samples
   * @return
   */
  public double getProbabilitySum();

  class ProbabilityData
      implements java.io.Serializable {
    public double probability;
    public double[] data;
    public ProbabilityData(double[] data, double p) {
      this.data = data;
      this.probability = p;
    }

    public String toString() {
      StringBuffer str = new StringBuffer();
      for (int j = 0; j < data.length; j++) {
        if (j != 0)
          str.append(' ');
        str.append(data[j]);
      }
      str.append(" [" + probability + "]");
      return str.toString();
    }
  }

}