Example #1
0
  EReturn getVector(const tinyxml2::XMLElement & xml_vector,
      Eigen::VectorXd & eigen_vector)
  {
    //!< Temporaries
    double temp_entry;
    int i = 0;

    if (!xml_vector.GetText())
    {
      INDICATE_FAILURE
      ;
      eigen_vector = Eigen::VectorXd(); //!< Null matrix again
      return PAR_ERR;
    }
    std::istringstream text_parser(xml_vector.GetText());

    //!< Initialise looping
    text_parser >> temp_entry;
    while (!(text_parser.fail() || text_parser.bad()))  //!< No commenting!
    {
      eigen_vector.conservativeResize(++i); //!< Allocate storage for this entry (by increasing i)
      eigen_vector(i - 1) = temp_entry;
      text_parser >> temp_entry;
    }
    return (i > 0) ? SUCCESS : PAR_ERR;
  }
Example #2
0
void addVectorBlock( Eigen::VectorXd &matrix, const int block_length ){
  assert( 1==matrix.cols() );

  int old_size = matrix.rows();
  matrix.conservativeResize( old_size+block_length, 1 );
  matrix.block( old_size, 0, block_length, 1 ) = Eigen::MatrixXd::Zero( block_length, 1);

}
Example #3
0
void append(
    Eigen::VectorXd& v,
    const Eigen::PlainObjectBase<Derived1>& app)
{
  int n = v.size();
  if(n <= 0){
    v = app;
  }else{
    assertion(app.cols() == 1 , app.cols());
    v.conservativeResize(n + app.size());
    for(int i = 0; i < app.size(); i++)
      v(n+i) = app(i);
  }
}
Example #4
0
void deleteVectorBlock( Eigen::VectorXd &matrix, const int block_start_index, const int block_length ){

  assert( 1==matrix.cols() );
  assert( matrix.rows()>=block_start_index+block_length );

  int size = matrix.rows();
  /*
    R
    D
    M
  */

  matrix.block( block_start_index, 0, size-block_start_index-block_length, 1 ) = matrix.block( block_start_index+block_length, 0,  size-block_start_index-block_length, 1 );
  matrix.conservativeResize( size-block_length, 1 );

}
Example #5
0
double L2R_Huber_SVC::predict(const std::string fileNameLibSVMFormat,
                              Eigen::VectorXd &w) {
  Eigen::SparseMatrix<double, 1> vX;
  Eigen::ArrayXd vy;
  const char *fn = fileNameLibSVMFormat.c_str();
  read_LibSVMdata1(fn, vX, vy);
  // loadLib(fileNameLibSVMFormat, vX, vy);
  int vl = vX.rows();
  int vn = vX.cols();
  int success = 0;

  if (vn != w.size()) {
    w.conservativeResize(vn);
  }
  Eigen::ArrayXd prob = vy * (vX * w).array();

  for (int i = 0; i < vl; ++i) {
    if (prob.coeffRef(i) >= 0.0)
      ++success;
  }
  return (double)success / vl;
}