예제 #1
0
  private void convolveAndRelease(
      Beagle beagle,
      int[] firstConvolutionBuffers,
      int[] secondConvolutionBuffers,
      int[] resultConvolutionBuffers,
      int operationsCount) {

    if (RUN_IN_SERIES) {
      if (operationsCount > 1) {
        throw new RuntimeException("Unable to convolve matrices in series");
      }
    }

    beagle.convolveTransitionMatrices(
        firstConvolutionBuffers, // A
        secondConvolutionBuffers, // B
        resultConvolutionBuffers, // C
        operationsCount // count
        );

    for (int i = 0; i < operationsCount; i++) {
      if (firstConvolutionBuffers[i] >= matrixBufferHelper.getBufferCount()
          && firstConvolutionBuffers[i] != reserveBufferIndex) {
        pushAvailableBuffer(firstConvolutionBuffers[i]);
      }
      if (secondConvolutionBuffers[i] >= matrixBufferHelper.getBufferCount()
          && secondConvolutionBuffers[i] != reserveBufferIndex) {
        pushAvailableBuffer(secondConvolutionBuffers[i]);
      }
    }
  } // END: convolveAndRelease
예제 #2
0
  /**
   * Sets the partials from a sequence in an alignment.
   *
   * @param beagle beagle
   * @param patternList patternList
   * @param sequenceIndex sequenceIndex
   * @param nodeIndex nodeIndex
   */
  protected final void setPartials(
      Beagle beagle, PatternList patternList, int sequenceIndex, int nodeIndex) {
    double[] partials = new double[patternCount * stateCount * categoryCount];

    boolean[] stateSet;

    int v = 0;
    for (int i = 0; i < patternCount; i++) {

      int state = patternList.getPatternState(sequenceIndex, i);
      stateSet = dataType.getStateSet(state);

      for (int j = 0; j < stateCount; j++) {
        if (stateSet[j]) {
          partials[v] = 1.0;
        } else {
          partials[v] = 0.0;
        }
        v++;
      }
    }

    // if there is more than one category then replicate the partials for each
    int n = patternCount * stateCount;
    int k = n;
    for (int i = 1; i < categoryCount; i++) {
      System.arraycopy(partials, 0, partials, k, n);
      k += n;
    }

    beagle.setPartials(nodeIndex, partials);
  }
예제 #3
0
  public void updateSubstitutionModels(Beagle beagle) {
    for (int i = 0; i < eigenCount; i++) {
      eigenBufferHelper.flipOffset(i);

      EigenDecomposition ed = substitutionModelList.get(i).getEigenDecomposition();

      beagle.setEigenDecomposition(
          eigenBufferHelper.getOffsetIndex(i),
          ed.getEigenVectors(),
          ed.getInverseEigenVectors(),
          ed.getEigenValues());
    }
  }
예제 #4
0
  /**
   * Sets the partials from a sequence in an alignment.
   *
   * @param beagle beagle
   * @param patternList patternList
   * @param sequenceIndex sequenceIndex
   * @param nodeIndex nodeIndex
   */
  protected final void setStates(
      Beagle beagle, PatternList patternList, int sequenceIndex, int nodeIndex) {
    int i;

    int[] states = new int[patternCount];

    for (i = 0; i < patternCount; i++) {

      states[i] = patternList.getPatternState(sequenceIndex, i);
    }

    beagle.setTipStates(nodeIndex, states);
  }
예제 #5
0
  /** Sets the partials from a sequence in an alignment. */
  protected final void setPartials(Beagle beagle, TipStatesModel tipStatesModel, int nodeIndex) {
    double[] partials = new double[patternCount * stateCount * categoryCount];

    tipStatesModel.getTipPartials(nodeIndex, partials);

    // if there is more than one category then replicate the partials for each
    int n = patternCount * stateCount;
    int k = n;
    for (int i = 1; i < categoryCount; i++) {
      System.arraycopy(partials, 0, partials, k, n);
      k += n;
    }

    beagle.setPartials(nodeIndex, partials);
  }
예제 #6
0
  private void computeTransitionMatrices(
      Beagle beagle, int[][] probabilityIndices, double[][] edgeLengths, int[] counts) {

    Timer timer;
    if (MEASURE_RUN_TIME) {
      timer = new Timer();
      timer.start();
    }

    if (DEBUG) {
      System.out.print("Computing matrices:");
    }

    for (int i = 0; i < eigenCount; i++) {
      if (DEBUG) {
        for (int j = 0; j < counts[i]; j++) {
          //                    System.out.print(" " + probabilityIndices[i][j]);
          System.out.print(" " + probabilityIndices[i][j] + " (" + edgeLengths[i][j] + ")");
        }
      }
      if (counts[i] > 0) {
        beagle.updateTransitionMatrices(
            eigenBufferHelper.getOffsetIndex(i),
            probabilityIndices[i],
            null, // firstDerivativeIndices
            null, // secondDerivativeIndices
            edgeLengths[i],
            counts[i]);
      }
    }

    if (DEBUG) {
      System.out.println();
    }

    if (MEASURE_RUN_TIME) {
      timer.stop();
      double timeInSeconds = timer.toSeconds();
      updateTime += timeInSeconds;
    }
  } // END: computeTransitionMatrices