// file: $isip/class/stat/GaussianModel/gaus_06.cc
// version: $Id: gaus_06.cc 7556 2001-12-26 22:32:53Z alphonso $
//

// system include files
//
#include <typeinfo>

// isip include files
//
#include "GaussianModel.h"

// method: eq
//
// arguments:
//  const GaussianModel& arg: (input) dat ato copy
//
// return: a boolean value - true if objects are equivalent, false otherwise
//
// check whether the gaussian models are equal. this is a pure equality
// method so the means and covariances must be exactly equal.
//
boolean GaussianModel::eq(const GaussianModel& arg_a) const {

  // check the mean vectors
  //
  if (!mean_d.eq(arg_a.mean_d)) {
    return false;
  }

  // if the objects are in the same initialization state,
  // we can compare them directly
  //
  if ((mode_d == NONE) && (arg_a.mode_d == NONE)) {
    return covariance_d.eq(arg_a.covariance_d);
  }

  if ((mode_d == PRECOMPUTE) && (arg_a.mode_d == PRECOMPUTE) &&
      (is_valid_d == arg_a.is_valid_d)) {
    return covariance_d.eq(arg_a.covariance_d);
  }

  // if the covariance matrices have not been inverted, invert them.
  // it is better to compare inverted matrices in this case,
  // since restoring an inverted matrix is prone to numerical error.
  //
  MatrixFloat tmp_0(covariance_d);
  if ((mode_d == NONE) || (!is_valid_d)) {
    tmp_0.inverse();
  }

  MatrixFloat tmp_1(arg_a.covariance_d);
  if ((arg_a.mode_d == NONE) || (!arg_a.is_valid_d)) {
    tmp_1.inverse();
  }

  // now we can check the matrices
  //
  return tmp_0.eq(tmp_1);
}

// method: eq
//
// arguments:
//  const StatisticalModelBase& arg: (input) object to test
//
// return: a boolean value indicating equality
//
// this method is part of the StatisticalModelBase interface contract
// which compares two virtual model types
//
boolean GaussianModel::eq(const StatisticalModelBase& arg_a) const {

  if (typeid(arg_a) == typeid(GaussianModel)) {
    return eq((GaussianModel&)arg_a);
  }
  else {
    return Error::handle(name(), L"eq", Error::ARG, __FILE__, __LINE__);
  }
}









