当前位置: 首页>>代码示例>>C++>>正文


C++ arma::Col类代码示例

本文整理汇总了C++中arma::Col的典型用法代码示例。如果您正苦于以下问题:C++ Col类的具体用法?C++ Col怎么用?C++ Col使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Col类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SortPointSet

size_t CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::
    SortPointSet(arma::Col<size_t>& indices,
                 arma::vec& distances,
                 const size_t childFarSetSize,
                 const size_t childUsedSetSize,
                 const size_t farSetSize)
{
  // We'll use low-level memcpy calls ourselves, just to ensure it's done
  // quickly and the way we want it to be.  Unfortunately this takes up more
  // memory than one-element swaps, but there's not a great way around that.
  const size_t bufferSize = std::min(farSetSize, childUsedSetSize);
  const size_t bigCopySize = std::max(farSetSize, childUsedSetSize);

  // Sanity check: there is no need to sort if the buffer size is going to be
  // zero.
  if (bufferSize == 0)
    return (childFarSetSize + farSetSize);

  size_t* indicesBuffer = new size_t[bufferSize];
  ElemType* distancesBuffer = new ElemType[bufferSize];

  // The start of the memory region to copy to the buffer.
  const size_t bufferFromLocation = ((bufferSize == farSetSize) ?
      (childFarSetSize + childUsedSetSize) : childFarSetSize);
  // The start of the memory region to move directly to the new place.
  const size_t directFromLocation = ((bufferSize == farSetSize) ?
      childFarSetSize : (childFarSetSize + childUsedSetSize));
  // The destination to copy the buffer back to.
  const size_t bufferToLocation = ((bufferSize == farSetSize) ?
      childFarSetSize : (childFarSetSize + farSetSize));
  // The destination of the directly moved memory region.
  const size_t directToLocation = ((bufferSize == farSetSize) ?
      (childFarSetSize + farSetSize) : childFarSetSize);

  // Copy the smaller piece to the buffer.
  memcpy(indicesBuffer, indices.memptr() + bufferFromLocation,
      sizeof(size_t) * bufferSize);
  memcpy(distancesBuffer, distances.memptr() + bufferFromLocation,
      sizeof(ElemType) * bufferSize);

  // Now move the other memory.
  memmove(indices.memptr() + directToLocation,
      indices.memptr() + directFromLocation, sizeof(size_t) * bigCopySize);
  memmove(distances.memptr() + directToLocation,
      distances.memptr() + directFromLocation, sizeof(ElemType) * bigCopySize);

  // Now copy the temporary memory to the right place.
  memcpy(indices.memptr() + bufferToLocation, indicesBuffer,
      sizeof(size_t) * bufferSize);
  memcpy(distances.memptr() + bufferToLocation, distancesBuffer,
      sizeof(ElemType) * bufferSize);

  delete[] indicesBuffer;
  delete[] distancesBuffer;

  // This returns the complete size of the far set.
  return (childFarSetSize + farSetSize);
}
开发者ID:AmesianX,项目名称:mlpack,代码行数:58,代码来源:cover_tree_impl.hpp

示例2: reset_nocopy

 /**
  * WARNING: Only use this method if you know what you are doing!
  *
  * This deallocates any data currently in this matrix.
  * It then takes the data from the given arguments;
  * this transfers ownership of the data to this class,
  * clearing the data from the given arguments.
  * This permits piecemeal construction of a CSC matrix without
  * unnecessary reallocation.
  *
  * @param new_row_indices   WARNING: These MUST be sorted in increasing
  *                          order (for each column).
  */
 void reset_nocopy(size_type m, size_type n,
                   arma::Col<size_type>& new_col_offsets,
                   arma::Col<size_type>& new_row_indices,
                   arma::Col<value_type>& new_values) {
   assert(new_col_offsets.size() == n + 1);
   assert(new_row_indices.size() == new_values.size());
   if (new_row_indices.size() != 0)
     assert(new_row_indices[new_row_indices.size()-1] < m);
   // TO DO: More validity checks.
   n_rows = m;
   n_cols = n;
   // TO DO: USE ARMA SWAP METHODS ONCE IMPLEMENTED
   std::swap(col_offsets_, new_col_offsets);
   std::swap(row_indices_, new_row_indices);
   std::swap(values_, new_values);
 }
开发者ID:vdeepak13,项目名称:sill,代码行数:29,代码来源:csc_matrix.hpp

示例3: getModel

    inline double ParallelKinematicMachine3PUPS::getEndEffectorPoseError(
        const arma::Col<double>::fixed<6>& endEffectorPose,
        const arma::Row<double>& redundantJointActuations) const {
      const arma::Cube<double>::fixed<3, 3, 2>& model = getModel(endEffectorPose, redundantJointActuations);

      const arma::Mat<double>::fixed<3, 3>& baseJoints = model.slice(0);

      const arma::Mat<double>::fixed<3, 3>& endEffectorJoints = model.slice(1);
      arma::Mat<double>::fixed<3, 3> endEffectorJointsRotated = endEffectorJoints;
      endEffectorJointsRotated.each_col() -= endEffectorPose.subvec(0, 1);

      const arma::Mat<double>::fixed<3, 3>& baseToEndEffectorJointPositions = endEffectorJoints - baseJoints;
      const arma::Row<double>::fixed<3>& baseToEndEffectorJointActuations = arma::sqrt(arma::sum(arma::square(baseToEndEffectorJointPositions)));

      if (arma::any(baseToEndEffectorJointActuations < minimalActiveJointActuations_) || arma::any(baseToEndEffectorJointActuations > maximalActiveJointActuations_)) {
        return 0.0;
      }

      arma::Mat<double>::fixed<6, 3> forwardKinematic;
      forwardKinematic.head_rows(3) = baseToEndEffectorJointPositions;
      for (std::size_t n = 0; n < baseToEndEffectorJointPositions.n_cols; ++n) {
        forwardKinematic.submat(3, n, 5, n) = arma::cross(endEffectorJointsRotated.col(n), baseToEndEffectorJointPositions.col(n));
      }

      arma::Mat<double> inverseKinematic(6, 3 + redundantJointIndicies_.n_elem, arma::fill::zeros);
      inverseKinematic.diag() = -arma::sqrt(arma::sum(arma::square(baseToEndEffectorJointPositions)));
      for (std::size_t n = 0; n < redundantJointIndicies_.n_elem; ++n) {
        const unsigned int& redundantJointIndex = redundantJointIndicies_(n);
        inverseKinematic(n, 3 + n) = arma::dot(baseToEndEffectorJointPositions.col(redundantJointIndex), redundantJointAngles_.col(redundantJointIndex));
      }

      return -1.0 / arma::cond(arma::solve(forwardKinematic.t(), inverseKinematic));
    }
开发者ID:markusmarx,项目名称:Mantella,代码行数:33,代码来源:parallelKinematicMachine3PUPS.hpp

示例4: permuteVector

 void permuteVector(const arma::Col<ValueType> &original,
                    arma::Col<ValueType> &permuted) const {
   const int dim = original.n_elem;
   permuted.set_size(dim);
   for (int i = 0; i < dim; ++i)
     permuted(m_permutedIndices[i]) = original(i);
 }
开发者ID:getzze,项目名称:bempp,代码行数:7,代码来源:index_permutation.hpp

示例5: getModel

    inline double ParallelKinematicMachine3PRPR::getEndEffectorPoseError(
        const arma::Col<double>::fixed<3>& endEffectorPose,
        const arma::Row<double>& redundantJointActuations) const {
      const arma::Cube<double>::fixed<2, 3, 2>& model = getModel(endEffectorPose, redundantJointActuations);

      const arma::Mat<double>::fixed<2, 3>& baseJointPositions = model.slice(1);

      const arma::Mat<double>::fixed<2, 3>& endEffectorJointPositions = model.slice(1);
      arma::Mat<double>::fixed<2, 3> endEffectorJointPositionsRotated = endEffectorJointPositions;
      endEffectorJointPositionsRotated.each_col() -= endEffectorPose.subvec(0, 1);

      const arma::Mat<double>::fixed<2, 3>& baseToEndEffectorJointPositions = endEffectorJointPositions - baseJointPositions;
      const arma::Row<double>::fixed<3>& baseToEndEffectorJointActuations = arma::sqrt(arma::sum(arma::square(baseToEndEffectorJointPositions)));

      if (arma::any(baseToEndEffectorJointActuations < minimalActiveJointActuations_) || arma::any(baseToEndEffectorJointActuations > maximalActiveJointActuations_)) {
        return 0.0;
      }

      arma::Mat<double>::fixed<3, 3> forwardKinematic;
      forwardKinematic.head_rows(2) = baseToEndEffectorJointPositions;
      forwardKinematic.row(2) = -forwardKinematic.row(0) % endEffectorJointPositionsRotated.row(1) + forwardKinematic.row(1) % endEffectorJointPositionsRotated.row(0);

      arma::Mat<double> inverseKinematic(3, 3 + redundantJointIndicies_.n_elem, arma::fill::zeros);
      inverseKinematic.diag() = -baseToEndEffectorJointActuations;
      for (std::size_t n = 0; n < redundantJointIndicies_.n_elem; ++n) {
        const unsigned int& redundantJointIndex = redundantJointIndicies_(n);
        inverseKinematic(n, 3 + n) = forwardKinematic(redundantJointIndex, 0) * redundantJointAngleCosines_(n) + forwardKinematic(redundantJointIndex, 1) * redundantJointAngleSines_(n);
      }

      return -1.0 / arma::cond(arma::solve(forwardKinematic.t(), inverseKinematic));
    }
开发者ID:markusmarx,项目名称:Mantella,代码行数:31,代码来源:parallelKinematicMachine3PRPR.hpp

示例6: unpermuteVector

 void unpermuteVector(const arma::Col<ValueType> &permuted,
                      arma::Col<ValueType> &original) const {
   const int dim = permuted.n_elem;
   original.set_size(dim);
   for (int i = 0; i < dim; ++i)
     original(i) = permuted(m_permutedIndices[i]);
 }
开发者ID:getzze,项目名称:bempp,代码行数:7,代码来源:index_permutation.hpp

示例7: getPolynomialTailValueImplementation

 double PolyharmonicSplineRadialBasisFunction::getPolynomialTailValueImplementation(
     const arma::Col<double>& parameter,
     const arma::Col<double>& polynomialCoefficients) const {
   if (polynomialOrder_ > 1) {
     return arma::dot(polynomialCoefficients.head(numberOfDimensions_), parameter) + polynomialCoefficients(polynomialCoefficients.n_elem - 1);
   } else {
     return polynomialCoefficients(polynomialCoefficients.n_elem - 1);
   }
 }
开发者ID:hnkien,项目名称:Mantella,代码行数:9,代码来源:polyharmonicSplineRadialBasisFunction.cpp

示例8: center

inline void HRectBound<MetricType, ElemType>::Center(
    arma::Col<ElemType>& center) const
{
  // Set size correctly if necessary.
  if (!(center.n_elem == dim))
    center.set_size(dim);

  for (size_t i = 0; i < dim; i++)
    center(i) = bounds[i].Mid();
}
开发者ID:DeepCV,项目名称:mlpack,代码行数:10,代码来源:hrectbound_impl.hpp

示例9: verify

  void OptimisationProblem<T>::setParameterTranslation(
      const arma::Col<T>& parameterTranslation) {
    verify(parameterTranslation.n_elem == numberOfDimensions_, "The number of elements must be equal to the number of dimensions.");
    verify(parameterTranslation.is_finite(), "All elements must be finite.");

    parameterTranslation_ = parameterTranslation;

    // Resets all counters and caches, as the problem could be changed.
    reset();
  }
开发者ID:markusmarx,项目名称:Mantella,代码行数:10,代码来源:optimisationProblem.hpp

示例10: wrapInTrilinosVector

Teuchos::RCP<Thyra::DefaultSpmdVector<ValueType> >
wrapInTrilinosVector(arma::Col<ValueType>& col)
{
    size_t size = col.n_rows;
    Teuchos::ArrayRCP<ValueType> trilinosArray =
            Teuchos::arcp(col.memptr(), 0 /* lowerOffset */,
                          size, false /* doesn't own memory */);
    typedef Thyra::DefaultSpmdVector<ValueType> TrilinosVector;
    return Teuchos::RCP<TrilinosVector>(new TrilinosVector(
        Thyra::defaultSpmdVectorSpace<ValueType>(size),
        trilinosArray, 1 /* stride */));
}
开发者ID:UCL,项目名称:bempp,代码行数:12,代码来源:default_iterative_solver.cpp

示例11: logStateProb

double HMM<Distribution>::Predict(const arma::mat& dataSeq,
                                  arma::Col<size_t>& stateSeq) const
{
  // This is an implementation of the Viterbi algorithm for finding the most
  // probable sequence of states to produce the observed data sequence.  We
  // don't use log-likelihoods to save that little bit of time, but we'll
  // calculate the log-likelihood at the end of it all.
  stateSeq.set_size(dataSeq.n_cols);
  arma::mat logStateProb(transition.n_rows, dataSeq.n_cols);
  arma::mat stateSeqBack(transition.n_rows, dataSeq.n_cols);

  // Store the logs of the transposed transition matrix.  This is because we
  // will be using the rows of the transition matrix.
  arma::mat logTrans(log(trans(transition)));

  // The calculation of the first state is slightly different; the probability
  // of the first state being state j is the maximum probability that the state
  // came to be j from another state.
  logStateProb.col(0).zeros();
  for (size_t state = 0; state < transition.n_rows; state++)
  {
    logStateProb(state, 0) = log(initial[state] *
        emission[state].Probability(dataSeq.unsafe_col(0)));
    stateSeqBack(state, 0) = state;
  }

  // Store the best first state.
  arma::uword index;
  for (size_t t = 1; t < dataSeq.n_cols; t++)
  {
    // Assemble the state probability for this element.
    // Given that we are in state j, we use state with the highest probability
    // of being the previous state.
    for (size_t j = 0; j < transition.n_rows; j++)
    {
      arma::vec prob = logStateProb.col(t - 1) + logTrans.col(j);
      logStateProb(j, t) = prob.max(index) +
          log(emission[j].Probability(dataSeq.unsafe_col(t)));
        stateSeqBack(j, t) = index;
    }
  }

  // Backtrack to find the most probable state sequence.
  logStateProb.unsafe_col(dataSeq.n_cols - 1).max(index);
  stateSeq[dataSeq.n_cols - 1] = index;
  for (size_t t = 2; t <= dataSeq.n_cols; t++)
    stateSeq[dataSeq.n_cols - t] =
        stateSeqBack(stateSeq[dataSeq.n_cols - t + 1], dataSeq.n_cols - t + 1);

  return logStateProb(stateSeq(dataSeq.n_cols - 1), dataSeq.n_cols - 1);
}
开发者ID:shenzebang,项目名称:mlpack,代码行数:51,代码来源:hmm_impl.hpp

示例12: exponents

void NaiveBayesClassifier<MatType>::Classify(const MatType& data,
                                             arma::Col<size_t>& results)
{
  // Check that the number of features in the test data is same as in the
  // training data.
  Log::Assert(data.n_rows == means.n_rows);

  arma::vec probs = arma::log(probabilities);
  arma::mat invVar = 1.0 / variances;

  arma::mat testProbs = arma::repmat(probs.t(), data.n_cols, 1);

  results.set_size(data.n_cols); // No need to fill with anything yet.

  Log::Info << "Running Naive Bayes classifier on " << data.n_cols
      << " data points with " << data.n_rows << " features each." << std::endl;

  // Calculate the joint probability for each of the data points for each of the
  // means.n_cols.

  // Loop over every class.
  for (size_t i = 0; i < means.n_cols; i++)
  {
    // This is an adaptation of gmm::phi() for the case where the covariance is
    // a diagonal matrix.
    arma::mat diffs = data - arma::repmat(means.col(i), 1, data.n_cols);
    arma::mat rhs = -0.5 * arma::diagmat(invVar.col(i)) * diffs;
    arma::vec exponents(diffs.n_cols);
    for (size_t j = 0; j < diffs.n_cols; ++j)
      exponents(j) = std::exp(arma::accu(diffs.col(j) % rhs.unsafe_col(j)));

    testProbs.col(i) += log(pow(2 * M_PI, (double) data.n_rows / -2.0) *
        pow(det(arma::diagmat(invVar.col(i))), -0.5) * exponents);
  }

  // Now calculate the label.
  for (size_t i = 0; i < data.n_cols; ++i)
  {
    // Find the index of the class with maximum probability for this point.
    arma::uword maxIndex = 0;
    arma::vec pointProbs = testProbs.row(i).t();
    pointProbs.max(maxIndex);

    results[i] = maxIndex;
  }

  return;
}
开发者ID:Praxyk,项目名称:Praxyk,代码行数:48,代码来源:naive_bayes_classifier_impl.hpp

示例13: readData

 bool CmpParser::readData(arma::Col<double> &data,short code){
     
     unsigned int dim=hdr.sampSize/4;
     data.resize(dim);
     if (code==0){
         float *p=new float;
         for (int i=0;i<dim;i++){
             if (file.read((char*)p,sizeof(float))==0)
             return false;
             SwapInt32((int*)p);
             data[i]=*p;
         }
         delete p;
     }
     return true;
 }
开发者ID:noetits,项目名称:MotionMachine,代码行数:16,代码来源:mmCmpParser.cpp

示例14: getNextFrame

 //ReadHTKHeader();
 bool CmpParser::getNextFrame(arma::Col<double> &frame, int derivate){
     if (file.is_open()==false)
     return false;
     if (hdr.sampKind&1024){//compressed mode. TODO to be implemented
         std::cerr<<"HTK compressed mode is not yet supported"<<std::endl;
         return false;
     }
     else{
         unsigned int dim=hdr.sampSize/4;
         arma::Col<double> data;
         if (!this->readData(data)){
             return false;
         }
         if (prev1.n_rows!=data.n_rows){
             prev2=data;
             if (!this->readData(prev1)){
                 return false;
             }
             if (!this->readData(data)){
                 return false;
             }
         }
         if (derivate==2){
             frame.resize(3*dim);
             frame.subvec(0, dim-1)=prev1;
             frame.subvec(dim, 2*dim-1)=(data-prev2)/2;
             frame.subvec(2*dim, 3*dim-1)=prev2-2*prev1+data;
         }
         else if (derivate==1){
             frame.resize(2*dim);
             frame.subvec(0, dim-1)=prev1;
             frame.subvec(dim, 2*dim-1)=(data-prev2)/2;
         }
         else{
             frame.resize(dim);
             frame=data;
         }
         prev2=prev1;
         prev1=data;
         //std::cout<<"data:"<<std::endl;
         //std::cout<<frame<<std::endl;
         return true;
     }
 }
开发者ID:noetits,项目名称:MotionMachine,代码行数:45,代码来源:mmCmpParser.cpp

示例15: calculateDependentVariables

//This function is specific to a single problem
void calculateDependentVariables(const arma::Mat<std::complex<double> >& myOffsets,
				 const arma::Col<std::complex<double> >& myCurrentGuess, 
		                 arma::Col<std::complex<double> >& targetsCalculated)
{
	//Evaluate a dependent variable for each iteration
	//The arma::Col allows this to be expressed as a vector operation
	for(int i = 0; i < NUMDIMENSIONS; i++)
	{
		targetsCalculated[i] = arma::sum(pow(myCurrentGuess.subvec(0,1) - myOffsets.row(i).subvec(0,1).t(),2.0));
		targetsCalculated[i] = targetsCalculated[i] + myCurrentGuess[2]*pow(-1.0, i) - myOffsets.row(i)[2]; 
		//std::cout << targetsCalculated[i] << std::endl;
	}
	//std::cout << "model evaluated *************************" << std::endl;
	//std::cout << targetsCalculated << std::endl;
	//std::cout << myOffsets << std::endl;
	
}
开发者ID:utsa-idl,项目名称:NewtonRaphsonExamples,代码行数:18,代码来源:complex_step.cpp


注:本文中的arma::Col类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。