Ejemplo n.º 1
0
  static typename std::enable_if<
      std::is_same<Border, ValidConvolution>::value, void>::type
  Convolution(const arma::Mat<eT>& input,
              const arma::Mat<eT>& filter,
              arma::Mat<eT>& output,
              const size_t dW = 1,
              const size_t dH = 1)
  {
    output = arma::zeros<arma::Mat<eT> >((input.n_rows - filter.n_rows + 1) /
        dW, (input.n_cols - filter.n_cols + 1) / dH);

    // It seems to be about 3.5 times faster to use pointers instead of
    // filter(ki, kj) * input(leftInput + ki, topInput + kj) and output(i, j).
    eT* outputPtr = output.memptr();

    for (size_t j = 0; j < output.n_cols; ++j)
    {
      for (size_t i = 0; i < output.n_rows; ++i, outputPtr++)
      {
        const eT* kernelPtr = filter.memptr();
        for (size_t kj = 0; kj < filter.n_cols; ++kj)
        {
          const eT* inputPtr = input.colptr(kj + j * dW) + i * dH;
          for (size_t ki = 0; ki < filter.n_rows; ++ki, ++kernelPtr, ++inputPtr)
            *outputPtr += *kernelPtr * (*inputPtr);
        }
      }
    }
  }
Ejemplo n.º 2
0
std::vector<double> extract_column_vector(const arma::Mat<double>& data, long index) {
	if (index<0 || index >= long(data.n_cols))
		throw std::range_error(join("Index out of range: ", index));
	const long n_rows = data.n_rows;
	const double* memptr = data.colptr(index);
	std::vector<double> result(memptr, memptr + n_rows);
	return std::move(result);
}
Ejemplo n.º 3
0
void MainWindow::selectCorr(int idx) {
    int mapId = _mapid(idx) - 1;

    int k = 0;
    for (int i = 0; i < _imageBuffer.n_rows; i++) {
        for (int j = 0; j < _imageBuffer.n_cols; j++) {

            if (std::isnan(_imageBuffer(i,j))) {
                continue;
            }
            float corr = crossCorrelation(_dataT.colptr(mapId), _dataT.colptr(k), _dataT.n_rows);
            if (std::isnan(corr)) {
                continue;
            }
            _imageBuffer(i, j) = corr;
            k++;
        }
    }

    _mapItem->setRange(-1, 1);
    _mapItem->refresh();
}
Ejemplo n.º 4
0
void CF<FactorizerType>::InsertNeighbor(const size_t queryIndex,
                                        const size_t pos,
                                        const size_t neighbor,
                                        const double value,
                                        arma::Mat<size_t>& recommendations,
                                        arma::mat& values) const
{
  // We only memmove() if there is actually a need to shift something.
  if (pos < (recommendations.n_rows - 1))
  {
    const int len = (values.n_rows - 1) - pos;
    memmove(values.colptr(queryIndex) + (pos + 1),
        values.colptr(queryIndex) + pos,
        sizeof(double) * len);
    memmove(recommendations.colptr(queryIndex) + (pos + 1),
        recommendations.colptr(queryIndex) + pos,
        sizeof(size_t) * len);
  }

  // Now put the new information in the right index.
  values(pos, queryIndex) = value;
  recommendations(pos, queryIndex) = neighbor;
}
Ejemplo n.º 5
0
void LSHSearch<SortPolicy>::InsertNeighbor(arma::mat& distances,
                                           arma::Mat<size_t>& neighbors,
                                           const size_t queryIndex,
                                           const size_t pos,
                                           const size_t neighbor,
                                           const double distance)
{
  // We only memmove() if there is actually a need to shift something.
  if (pos < (distances.n_rows - 1))
  {
    const size_t len = (distances.n_rows - 1) - pos;
    memmove(distances.colptr(queryIndex) + (pos + 1),
        distances.colptr(queryIndex) + pos,
        sizeof(double) * len);
    memmove(neighbors.colptr(queryIndex) + (pos + 1),
        neighbors.colptr(queryIndex) + pos,
        sizeof(size_t) * len);
  }

  // Now put the new information in the right index.
  distances(pos, queryIndex) = distance;
  neighbors(pos, queryIndex) = neighbor;
}
Ejemplo n.º 6
0
void FastMKS<KernelType, TreeType>::InsertNeighbor(arma::Mat<size_t>& indices,
                                                   arma::mat& products,
                                                   const size_t queryIndex,
                                                   const size_t pos,
                                                   const size_t neighbor,
                                                   const double distance)
{
  // We only memmove() if there is actually a need to shift something.
  if (pos < (products.n_rows - 1))
  {
    int len = (products.n_rows - 1) - pos;
    memmove(products.colptr(queryIndex) + (pos + 1),
        products.colptr(queryIndex) + pos,
        sizeof(double) * len);
    memmove(indices.colptr(queryIndex) + (pos + 1),
        indices.colptr(queryIndex) + pos,
        sizeof(size_t) * len);
  }

  // Now put the new information in the right index.
  products(pos, queryIndex) = distance;
  indices(pos, queryIndex) = neighbor;
}
Ejemplo n.º 7
0
void MainWindow::mousePressed(QFloatImageItem* self, QGraphicsSceneMouseEvent* event) {
    QPoint pos = event->pos().toPoint();

    int lg = pos.x();
    int lt = pos.y();

    if (lg < 91) {
        lg = -180 + (91 - lg) * 2;
    } else {
        lg = 180 - (lg - 91) * 2;
    }

    if (lt < 45) {
        lt = (45 - lt) * 2;
    } else {
        lt = -(lt - 45) * 2;
    }

    cout << "Long: " << lg << " / Lati: " << lt << endl;

    if (ui.showCorr->isChecked()) {
        int idx = pos.y() * _imageBuffer.n_rows + pos.x();
        selectCorr(idx);

        clearGraphs();
    } else if (ui.showMonth->isChecked()) {

        if (_tracePath.elementCount() == 0) {
            _tracePath.moveTo(pos);
        } else {
            _tracePath.lineTo(pos);
        }
        _traceItem->setPath(_tracePath);

        int idx = pos.y() * _imageBuffer.n_rows + pos.x();

        ui.customPlot->xAxis->setLabel("month");
        ui.customPlot->yAxis->setLabel("Temp");

        QVector<double> xTicks;
        QVector<QString> xLabels;
        for (int i = 0; i < _dataT.n_rows; i += _dataT.n_rows / 10) {
            xTicks << i;
            xLabels << QString("%1/%2").arg(i / 12 + ui.startingYear->value()).arg(i % 12 + 1, 2, 10, QChar('0'));
        }

        ui.customPlot->xAxis->setAutoTicks(false);
        ui.customPlot->xAxis->setAutoTickStep(false);
        ui.customPlot->xAxis->setAutoTickLabels(false);
        ui.customPlot->xAxis->setTickVector(xTicks);
        ui.customPlot->xAxis->setTickVectorLabels(xLabels);


        int mapId = _mapid(idx) - 1;
        float *colData = _dataT.colptr(mapId);

        QVector<double> xdata, ydata;
        for (int i = 0; i < _dataT.n_rows; i++) {
            xdata.append(i);
            ydata.append(colData[i]);
        }

        ui.customPlot->addGraph(ui.customPlot->xAxis, ui.customPlot->yAxis);

        int lastGraph = ui.customPlot->graphCount() - 1;
        ui.customPlot->graph(lastGraph)->setData(xdata, ydata);

        QPen lineColor(__hsv100[(lastGraph) % 100] & 0xaaffffff);
        ui.customPlot->graph(lastGraph)->setPen(lineColor);

        ui.customPlot->graph(lastGraph)->setName(QString("(%1,%2)").arg(lg).arg(lt));
        ui.customPlot->graph(lastGraph)->setSelectable(true);

        ui.customPlot->graph(lastGraph)->setProperty("x", QVariant(pos.x()));
        ui.customPlot->graph(lastGraph)->setProperty("y", QVariant(pos.y()));
        ui.customPlot->graph(lastGraph)->setProperty("mapid", QVariant(mapId));
        ui.customPlot->graph(lastGraph)->setProperty("graphid", QVariant(lastGraph));


        ui.customPlot->rescaleAxes();
        ui.customPlot->replot();
    }
}
Ejemplo n.º 8
0
 arma::Col<eT> Element(arma::Mat<eT>& input, const size_t colNum)
 {
   return arma::Col<eT>(input.colptr(colNum), input.n_rows, false, true);
 }