示例#1
0
typename aol::Vector<_DataType>::RealType aol::Vector<_DataType>:: getWeightedMedianValue( const aol::Vector<RealType> &Weights ) const {
  const int numVals = this->size();

  if ( numVals != Weights.size() )
    throw Exception ( "aol::Vector<DataType>::getWeightedMedianValue: numVals != Weights.size() !\n", __FILE__, __LINE__ );

  if ( Weights.getMinValue() <= 0 )
    throw Exception ( "aol::Vector<DataType>::getWeightedMedianValue: Nonpositive weights are not supported!\n", __FILE__, __LINE__ );

  std::vector<std::pair<_DataType, RealType> > valuesAndWeights;
  valuesAndWeights.reserve ( numVals );
  for ( int i = 0; i < numVals; ++i )
    valuesAndWeights.push_back ( std::pair<_DataType, RealType> ( this->get ( i ), Weights[i] ) );

  std::sort( valuesAndWeights.begin(), valuesAndWeights.end() );
  const RealType halfOfTotalWeight = 0.5 * Weights.sum();

  RealType weight = 0;
  for ( int i = 0; i < numVals; ++i ) {
    weight += valuesAndWeights[i].second;
    if ( ( weight > halfOfTotalWeight ) || ( i == ( numVals - 1 ) ) )
      return valuesAndWeights[i].first;
    else if ( aol::appeqAbsolute ( weight, halfOfTotalWeight ) ) {
      return ( valuesAndWeights[i].first * valuesAndWeights[i].second + valuesAndWeights[i+1].first * valuesAndWeights[i+1].second ) / ( valuesAndWeights[i].second +  valuesAndWeights[i+1].second );
    }
  }
  return valuesAndWeights[numVals-1].first;
}
示例#2
0
void aol::Vector<_DataType>::pushBackValues ( const aol::Vector<_DataType> &otherVector ) {
  const int currentSize = this->size();
  this->growBy ( otherVector.size() );
  for ( int i = 0; i < otherVector.size(); ++i ) {
    this->set ( currentSize + i, otherVector.get ( i ) );
  }
}
示例#3
0
_DataType aol::Vector<_DataType>::operator* ( const aol::Vector<_DataType> &c ) const {
  if ( c.size() != _size ) {
    throw aol::Exception ( "Vector::operator*: Vectorlengths not equal...", __FILE__, __LINE__ );
  } else {
    return ScalarProduct<DataType> ( this->_pData, c.getData(), _size );
  }
  return 0;
}
示例#4
0
void aol::Vector<_DataType>::addBlock ( int start, const aol::Vector<_DataType>& block ) {
  int siz = block.size ();

  if ( start + siz > size () )
    throw aol::Exception ( "aol::Vector<T,R>::addBlock: Parameter mismatch: Block does not fit", __FILE__, __LINE__ );

  for ( int i = 0; i < siz; ++i )
    add ( start + i, block.get ( i ) );
}
示例#5
0
void aol::Vector<_DataType>::absDiff ( aol::Vector<_DataType> const& Vec1,
                                       aol::Vector<_DataType> const& Vec2 ) {
  if ( Vec1.size() != _size || Vec2.size() != _size ) {
    throw aol::Exception ( "dimensions don't match", "aol::Vector::absDiff" );
  }
  for ( int i = 0; i < _size; ++i ) {
    _pData[ i ] = static_cast< DataType > ( aol::Abs ( Vec1._pData[i] - Vec2._pData[i] ) );
  }
}
示例#6
0
void aol::Vector<_DataType>::setSum ( const aol::Vector<_DataType>& Vec1,
                                      const aol::Vector<_DataType>& Vec2, _DataType Factor ) {
  if ( Vec1.size() != _size || Vec2.size() != _size ) {
    cerr << "ERROR in add: incompatible vectorlengths...\n";
    return;
  }
  DataType *ptr = _pData;
  for ( int i = 0; i < _size; ++i ) {
    *ptr = Vec1.get ( i ) + Vec2.get ( i ) * Factor;
    ptr++;
  }
}
示例#7
0
void Vector<unsigned char>::createHistogram ( aol::Vector<int> &Histo ) const {
  const int numPixels = this->size();
  Histo.reallocate ( 256 );
  for ( int i = 0; i < numPixels; ++i )
    ++Histo [ this->get ( i ) ];

}
void qc::FastUniformGridMatrix<_DataType, qc::QC_2D, BaseClass>::applyAdd ( const aol::Vector<_DataType> &Arg, aol::Vector<_DataType> &Dest ) const {
#ifdef _OPENMP
#pragma omp parallel for
#endif
  for ( int i = 0; i <= _w + 1; ++i ) {
    multCarefullyAtBoundary ( i, Arg, Dest );
  }
#if 1
  const DataType * ArgPtr  = Arg.getData();
  DataType * DestPtr = Dest.getData();
#ifdef _OPENMP
#pragma omp parallel for
#endif
  for ( int i = _w + 2; i < _size - _w - 2; ++i ) {
    for ( int k = 0; k < 3; ++k ) {
      int globos = _w * ( k - 1 ) - 1;
      int g = globos + i;
      for ( int j = 0; j < 3; ++j ) {
        DestPtr[i] += ArgPtr[g++] * _rows[k][i][j];
      }
    }
  }
#endif
#if 0
  const int seg_len = 10;
  for ( int seg = _w + 2; seg < _size - _w - 2; seg += seg_len ) {
    const int seg_end = aol::Min ( seg + seg_len, _size - _w - 2 );
    for ( int k = 0; k < 3; ++k ) {
      int globos = _w * ( k - 1 ) - 1;
      for ( int i = seg; i < seg_end; ++i ) {
        // cerr << "inner row = " << i << endl;
        int g = globos + i;
        for ( int j = 0; j < 3; ++j ) {
          Dest[i] += Arg[g++] * _rows[k][i][j];
        }
      }
    }
  }
#endif
#ifdef _OPENMP
#pragma omp parallel for
#endif
  for ( int i = aol::Max ( _w + 2, _size - _w - 2 ); i < _size; ++i ) {
    multCarefullyAtBoundary ( i, Arg, Dest );
  }
}
示例#9
0
typename aol::Vector<_DataType>::RealType aol::Vector<_DataType>::getWeightedMeanValue ( const aol::Vector<RealType> &Weights ) const {
  const int numVals = this->size();

  RealType mean = 0;
  for ( int i = 0; i < numVals; ++i )
    mean += Weights[i] * get(i);
  mean /= Weights.sum();

  return mean;
}
示例#10
0
文件: vec.cpp 项目: nmevenkamp/pcams
_DataType aol::Vector<_DataType>::sumWeighted ( aol::Vector<_DataType> const& weight ) const {
#ifdef BOUNDS_CHECK
  if ( weight.size() < _size ) {
    char error[1024];
    sprintf ( error, "Vector<DataType>::sumWeighted: weight vector not long enough (%d), should be %d at least.\n", weight.size(), _size );
    throw OutOfBoundsException ( error, __FILE__, __LINE__ );
  }
#endif
  _DataType ret = 0.;
  _DataType *ptr = _pData;
  for ( int i = 0; i < _size; ++i )
    ret += *ptr++ * weight[i];
  return ret;
}