コード例 #1
0
ファイル: lsh_search_impl.hpp プロジェクト: 0x0all/mlpack
inline force_inline
double LSHSearch<SortPolicy>::BaseCase(arma::mat& distances,
                                       arma::Mat<size_t>& neighbors,
                                       const size_t queryIndex,
                                       const size_t referenceIndex)
{
  // If the datasets are the same, then this search is only using one dataset
  // and we should not return identical points.
  if ((&querySet == &referenceSet) && (queryIndex == referenceIndex))
    return 0.0;

  const double distance = metric::EuclideanDistance::Evaluate(
      querySet.unsafe_col(queryIndex), referenceSet.unsafe_col(referenceIndex));

  // If this distance is better than any of the current candidates, the
  // SortDistance() function will give us the position to insert it into.
  arma::vec queryDist = distances.unsafe_col(queryIndex);
  arma::Col<size_t> queryIndices = neighbors.unsafe_col(queryIndex);
  size_t insertPosition = SortPolicy::SortDistance(queryDist, queryIndices,
      distance);

  // SortDistance() returns (size_t() - 1) if we shouldn't add it.
  if (insertPosition != (size_t() - 1))
    InsertNeighbor(distances, neighbors, queryIndex, insertPosition,
        referenceIndex, distance);

  return distance;
}
コード例 #2
0
void DiscreteBoundaryOperator<ValueType>::apply(
    const TranspositionMode trans, const arma::Mat<ValueType> &x_in,
    arma::Mat<ValueType> &y_inout, const ValueType alpha,
    const ValueType beta) const {
  bool transposed = (trans == TRANSPOSE || trans == CONJUGATE_TRANSPOSE);
  if (x_in.n_rows != (transposed ? rowCount() : columnCount()))
    throw std::invalid_argument("DiscreteBoundaryOperator::apply(): "
                                "vector x_in has invalid length");
  if (y_inout.n_rows != (transposed ? columnCount() : rowCount()))
    throw std::invalid_argument("DiscreteBoundaryOperator::apply(): "
                                "vector y_inout has invalid length");
  if (x_in.n_cols != y_inout.n_cols)
    throw std::invalid_argument("DiscreteBoundaryOperator::apply(): "
                                "vectors x_in and y_inout must have "
                                "the same number of columns");

  for (size_t i = 0; i < x_in.n_cols; ++i) {
    const arma::Col<ValueType> x_in_col = x_in.unsafe_col(i);
    arma::Col<ValueType> y_inout_col = y_inout.unsafe_col(i);
    applyBuiltInImpl(trans, x_in_col, y_inout_col, alpha, beta);
  }
}
コード例 #3
0
  double Forward(const arma::Mat<eT>& input, const arma::Mat<eT>& target)
  {
    reward = 0;
    arma::uword index = 0;

    for (size_t i = 0; i < input.n_cols; i++)
    {
      input.unsafe_col(i).max(index);
      reward = ((index + 1) == target(i)) * scale;
    }

    if (sizeAverage)
    {
      return -reward / input.n_cols;
    }

    return -reward;
  }
    virtual void evaluate(const GeometricalData<CoordinateType>& geomData,
                          arma::Mat<ValueType>& result) const {
        const arma::Mat<CoordinateType>& points  = geomData.globals;
        const arma::Mat<CoordinateType>& normals = geomData.normals;

#ifndef NDEBUG
        if ((int)points.n_rows != worldDimension() ||
                (int)points.n_rows != worldDimension())
            throw std::invalid_argument(
                    "SurfaceNormalAndDomainIndexDependentFunction::evaluate(): "
                    "incompatible world dimension");
#endif

        const size_t pointCount = points.n_cols;
        result.set_size(codomainDimension(), pointCount);
        for (size_t i = 0; i < pointCount; ++i) {
            arma::Col<ValueType> activeResultColumn = result.unsafe_col(i);
            m_functor.evaluate(points.unsafe_col(i), normals.unsafe_col(i),
                               geomData.domainIndex, activeResultColumn);
        }
    }