Ejemplo n.º 1
0
void MinToTotal::consume() {
  const vector<Real>& envelope = *((const vector<Real>*)_envelope.getTokens());

  int minIdx = argmin(envelope);
  if (envelope[minIdx] < _min) {
    _min = envelope[minIdx];
    _minIdx = minIdx + _size;
  }

  _size += envelope.size();
}
Ejemplo n.º 2
0
void MinToTotal::compute() {

  const vector<Real>& envelope = _envelope.get();
  Real& minToTotal = _minToTotal.get();

  if (envelope.empty()) {
    throw EssentiaException("MinToTotal: envelope is empty, minToTotal is not defined for an empty envelope");
  }

  minToTotal = Real(argmin(envelope)) / envelope.size();
}
Ejemplo n.º 3
0
double LineSearch::argmax(Function& f, double minx, double maxx)
{
  NegateFunction nf(f);
  return argmin(nf, minx, maxx);
}
Ejemplo n.º 4
0
int main() {
  int a[5] = {2, -3, 5, -7, 11};
  std::cout << argmin(a, 5) << std::endl;
}
Ejemplo n.º 5
0
void TempoTapDegara::decodeBeats(map<Real,
                                 vector<vector<Real> > >& transitionMatrix,
                                 const vector<Real>& beatPeriods,
                                 const vector<Real>& beatEndPositions,
                                 const vector<vector<Real> >& biy,
                                 vector<int>& sequenceStates) {
  // Transition probability matrix at the begining of the track
  size_t currentIndex = 0;

  // Best transition information for backtracking
  vector<vector<int> > stateBacktracking(_numberStates, vector<int>(_numberFrames));

  // HMM cost for each state for the current time
  vector<Real> cost(_numberStates, numeric_limits<Real>::max());
  cost[0] = 0;
  vector<Real> costOld = cost;
  vector<Real> diff(_numberStates);

  // Dynamic programming
  for (size_t t=0; t<_numberFrames; ++t) {
    // Evaluate transitions from any state to state event (state 0)

    // Look for the minimum cost
    for (int i=0; i<_numberStates; ++i) {
      diff[i] = costOld[i] - transitionMatrix[beatPeriods[currentIndex]][i][0];
    }
    int bestState = argmin(diff);
    Real bestPath = diff[bestState];

    if (bestPath==numeric_limits<Real>::max()) {
      bestState = -1;
    }

    // Save best transtions information for backtracking
    stateBacktracking[0][t] = bestState;
    // Update cost; the only possible transition is from state to state+1
    cost[0] = - biy[0][t] + bestPath;
    for (int state=1; state<_numberStates; ++state) {
      cost[state] = costOld[state-1]
                    - transitionMatrix[beatPeriods[currentIndex]][state-1][state]
                    - biy[state][t];
      stateBacktracking[state][t] = state-1;
    }

    // Update cost at t-1
    costOld = cost;

    // Find the transition matrix corresponding to next frame
    if (t+1 < _numberFrames) {
      Real currentTime = (t+1) * _resolutionODF;
      for (size_t i=currentIndex+1; i < beatEndPositions.size() &&
                         beatEndPositions[i] <= currentTime; ++i) {
        currentIndex = i;
      }
    }
  }

  // Decide which of the final states is the most probable

  int finalState = argmin(cost);
  // Backtrace through the model
  sequenceStates.resize(_numberFrames);
  sequenceStates.back() = finalState;
  if (_numberFrames >= 2) {
    for (size_t t=_numberFrames-2; ; --t) {
      sequenceStates[t] = stateBacktracking[sequenceStates[t+1]][t+1];
      if (t==0) {
        break;
      }
    }
  }
}