// file: $isip_ifc/class/stat/RelevanceVectorModel/rvm_07.cc
// version: $Id: rvm_07.cc 10423 2006-02-09 00:52:30Z raghavan $
//

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

// method: setMode
//
// arguments:
//  MODE arg: (input) mode to set
//
// return: a boolean value indicating status
//
// this method sets the computation mode and sets the initialization flag.
//
boolean RelevanceVectorModel::setMode(MODE arg_a) {

  // mode: PRECOMPUTE and prior mode is NONE
  //  we must initialize
  //
  if ((arg_a == PRECOMPUTE) && (mode_d == NONE)) {
    mode_d = PRECOMPUTE;
    is_valid_d = false;
  }

  // mode: PRECOMPUTE and prior mode is PRECOMPUTE
  //  or NONE and prior mode is NONE
  //  leave the state unchanged. we still might need to initialize
  //  if is_valid_d was false.
  //  note: it does not have to work in all cases
  //

  // mode: NONE and prior mode is PRECOMPUTE
  // 
  else if ((arg_a == NONE) && (mode_d == PRECOMPUTE)) {
    mode_d = arg_a;
  }

  // exit gracefully
  //
  return true;
}

// method: init
//
// arguments: none
//
// return: a boolean value indicating status
//
// this method checks the initial status
//
boolean RelevanceVectorModel::init() {

  // if we are not in the precompute mode, we don't need to do anything.
  //
  if (mode_d != PRECOMPUTE) {
    is_valid_d = true;
    return true;
  }

  // if the data are valid, we also don't need to do anything.
  // note: it does not have to work in all cases
  //
  else if (is_valid_d) {
    return true;
  }

  // check the arguments
  //
  long len_sv = vectors_d.length();
  long len_alphas = weights_d.length();

  if ((len_sv != len_alphas) || (len_sv <= 0)) {
    is_valid_d = false;
    return false;
  }
       
  // exit gracefully
  //
  return (is_valid_d = true);
}
