Ejemplo n.º 1
0
 public double[][] getTransiton(int segmentId, int sngSerialId, String startTime, String endTime) {
   if (!isSetTrans) {
     setPara();
     ArrayList<Integer> array = getIc(segmentId, sngSerialId, startTime, endTime);
     toTransTensor(array, order);
     Matrix.transpose(transition, stateSpace);
     isSetTrans = true;
   }
   return transition;
 }
Ejemplo n.º 2
0
  @Override
  public void toTransTensor(ArrayList<Integer> array, int order) {
    // TODO Auto-generated method stub
    transition = new double[stateSpace][stateSpace];
    while (order > 0) {
      double[] sum = new double[stateSpace];
      double[][] transitionN = new double[stateSpace][stateSpace];
      for (int i = 0; i < array.size() - order; i++) {
        if (array.get(i) / mode >= stateSpace && array.get(i + order) / mode >= stateSpace) {

          sum[stateSpace - 1] += 1;
          transitionN[stateSpace - 1][stateSpace - 1] += 1;
        } else if (array.get(i) / mode >= stateSpace) {
          sum[stateSpace - 1] += 1;
          transitionN[stateSpace - 1][array.get(i + order)] += 1;
        } else if (array.get(i + order) / mode >= stateSpace) {
          sum[array.get(i) / mode] += 1;
          transitionN[array.get(i) / mode][stateSpace - 1] += 1;
        } else {
          sum[array.get(i) / mode] += 1;
          transitionN[array.get(i) / mode][array.get(i + order) / mode] += 1;
        }
      }
      for (int i = 0; i < stateSpace; i++) {
        for (int j = 0; j < stateSpace; j++) {
          if (sum[i] > 0) transitionN[i][j] /= sum[i];
          // else transition[i][i] =1;
          else {
            transition[i][i] = 1.0 / stateSpace;
            // transitionN[i][i] = 0.0;
          }
        }
      }
      Matrix.add(transition, transitionN, stateSpace, para[order - 1]);
      order--;
    }
  }