コード例 #1
0
  public void update() {
    stressBeforeUpdate = stressAfterUpdate;

    computeBofCoordinates();
    BZ.multiply(newPositionMatrix, positionMatrix);
    positionMatrix.set(newPositionMatrix);
    vPlus.substituteBack(positionMatrix);
    distances.set(new DistanceMatrix(positions));
    stressAfterUpdate = stress();

    iterations++;
  }
コード例 #2
0
  public void initialize(
      Space space, Matrix dissimilarities, List<Vector> positions, Matrix weights)
      throws Exception {
    this.space = space;
    dimensions = positions.size();
    positionSpace = new ListSpace(positions);

    distances = new RowArrayMatrix(positionSpace, positionSpace);
    distances.set(new DistanceMatrix(positions));

    this.dissimilarities = new RowArrayMatrix(dissimilarities);
    this.positions = positions;

    if (weights != null) this.weights = new RowArrayMatrix(weights);
    else {
      this.weights = new RowArrayMatrix(positionSpace, positionSpace);
      this.weights.ones();
    }

    newPositions = new ArrayList<Vector>();

    for (int i = 0; i < positions.size(); i++) newPositions.add(new ArrayVector(space));

    positionMatrix = new RowVectorMatrix(positions, space);
    newPositionMatrix = new RowVectorMatrix(newPositions, space);

    normalizeWeights();

    vPlus = computeVPlus(this.weights);
    stressBeforeUpdate = Double.MAX_VALUE;
    stressAfterUpdate = stress();
    iterations = 0;
    BZ = new RowArrayMatrix(positionSpace, positionSpace);
  }
コード例 #3
0
  public void dump() {
    System.out.println("Distances:");
    distances.dump();

    System.out.println("Coordinates:");
    for (Vector coordinate : positions) coordinate.dump();

    System.out.println("Stress: " + stressAfterUpdate);
  }
コード例 #4
0
  private PermutedLUDecomposition computeVPlus(RowArrayMatrix weights) throws Exception {
    RowArrayMatrix V = new RowArrayMatrix(positionSpace, positionSpace);

    for (int i = 0; i < dimensions; i++) {
      for (int j = 0; j < dimensions; j++) {
        if (i == j) {
          double sum = 0;

          for (int k = 0; k < dimensions; k++) if (k != i) sum += weights.values[i][k];

          V.values[i][j] = sum;
        } else V.values[i][j] = -weights.values[i][j];
      }
    }

    V.add(1);

    return new PermutedLUDecomposition(V);
  }
コード例 #5
0
 private void normalizeWeights() {
   weights.setMainDiagonal(0);
   weights.divide(weights.maximum());
   weights.setMainDiagonal(1);
 }