Ejemplo n.º 1
0
  // initialize the matrices
  public void Initialize() {
    // compute the histogram matrix
    ComputeHistogram();

    // create the extended Y
    YExtended = new Matrix(numTotalInstances, numLabels);

    // set all the cells to zero initially
    for (int i = 0; i < numTrainInstances; i++)
      for (int l = 0; l < numLabels; l++) YExtended.set(i, l, 0.0);

    // set to 1 only the column corresponding to the label
    for (int i = 0; i < numTotalInstances; i++) YExtended.set(i, (int) Y.get(i), 1.0);

    // randomly initialize the latent matrices
    S = new Matrix(numTotalInstances, D);
    S.RandomlyInitializeCells(0, 1);

    P = new Matrix(D, numPatterns);
    P.RandomlyInitializeCells(0, 1);

    biasP = new double[numPatterns];
    for (int l = 0; l < numPatterns; l++) biasP[l] = H.GetColumnMean(l);

    W = new Matrix(D, numLabels);
    W.RandomlyInitializeCells(0, 1);

    biasW = new double[numLabels];
    for (int l = 0; l < numLabels; l++) biasW[l] = YExtended.GetColumnMean(l);

    // record the observed histogram values
    HObserved = new ArrayList<Tripple>();
    for (int i = 0; i < H.getDimRows(); i++)
      for (int j = 0; j < H.getDimColumns(); j++)
        if (H.get(i, j) != GlobalValues.MISSING_VALUE) HObserved.add(new Tripple(i, j));

    Collections.shuffle(HObserved);

    // record the observed label values
    YObserved = new ArrayList<Tripple>();
    for (int i = 0; i < numTrainInstances; i++)
      for (int l = 0; l < YExtended.getDimColumns(); l++)
        if (YExtended.get(i, l) != GlobalValues.MISSING_VALUE) YObserved.add(new Tripple(i, l));

    Collections.shuffle(YObserved);
  }
Ejemplo n.º 2
0
  // compute the histogram matrix
  public void ComputeHistogram() {
    BagOfPatterns bop = new BagOfPatterns();

    bop.representationType = RepresentationType.Polynomial;

    bop.slidingWindowSize = slidingWindowSize;

    bop.representationType = RepresentationType.Polynomial;
    bop.innerDimension = innerDimension;
    bop.alphabetSize = alphabetSize;
    bop.polyDegree = degree;

    H = bop.CreateWordFrequenciesMatrix(X);
    numPatterns = H.getDimColumns();

    for (int i = 0; i < H.getDimRows(); i++)
      for (int j = 0; j < H.getDimColumns(); j++)
        if (H.get(i, j) == 0) {
          // H.set(i, j, GlobalValues.MISSING_VALUE);
        }

    Logging.println("Histogram Sparsity: " + H.GetSparsityRatio(), LogLevel.DEBUGGING_LOG);
  }