Examples of DoubleMatrix


Examples of org.apache.hama.commons.math.DoubleMatrix

    // get layer related information
    DoubleFunction squashingFunction = this.squashingFunctionList
        .get(curLayerIdx);
    DoubleVector curLayerOutput = outputCache.get(curLayerIdx);
    DoubleMatrix weightMatrix = this.weightMatrixList.get(curLayerIdx);
    DoubleMatrix prevWeightMatrix = this.prevWeightUpdatesList.get(curLayerIdx);

    // next layer is not output layer, remove the delta of bias neuron
    if (curLayerIdx != this.layerSizeList.size() - 2) {
      nextLayerDelta = nextLayerDelta.slice(1,
          nextLayerDelta.getDimension() - 1);
    }

    DoubleVector delta = weightMatrix.transpose()
        .multiplyVector(nextLayerDelta);
    for (int i = 0; i < delta.getDimension(); ++i) {
      delta.set(
          i,
          delta.get(i)
              * squashingFunction.applyDerivative(curLayerOutput.get(i)));
    }

    // update weights
    for (int i = 0; i < weightUpdateMatrix.getRowCount(); ++i) {
      for (int j = 0; j < weightUpdateMatrix.getColumnCount(); ++j) {
        weightUpdateMatrix.set(i, j,
            -learningRate * nextLayerDelta.get(i) * curLayerOutput.get(j)
                + this.momentumWeight * prevWeightMatrix.get(i, j));
      }
    }

    return delta;
  }
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleMatrix

    int offset = 1;
    while (offset < matrix_size) {
      slices.add(vc.slice(offset, matrix_rank));
      offset += matrix_rank;
    }
    DoubleMatrix res = new DenseDoubleMatrix((DoubleVector[])slices.toArray());
    return res;
  }
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleMatrix

    //
    // ν_ld, μ_lc (V) is type of matrix,
    // but 2τ * y_bd (α_al + μ_l: * x_a:)(r − R) (M later) will be type of vector
    // in order to add vector values to matrix
    // we create matrix with MMMMM and then transpose it.
    DoubleMatrix tmp = null;
    if (isAvailableItemFeature) {
      DoubleVector[] Mtransposed = new DenseDoubleVector[rank];
      for (int i = 0; i<rank; i++) {
        Mtransposed[i] = e.itemFeatureFactorized.getRowVector(i).multiply(aal_ml_xa.get(i));
      }
      tmp = new DenseDoubleMatrix(Mtransposed);
      tmp = tmp.multiply(2*TETTA*scoreDifference);
      res.itemFeatureFactorized = e.itemFeatureFactorized.add(tmp);
    }

    if (isAvailableUserFeature) {
      DoubleVector[] Mtransposed = new DenseDoubleVector[rank];
      for (int i = 0; i<rank; i++) {
        Mtransposed[i] = e.userFeatureFactorized.getRowVector(i).multiply(bbl_vl_yb.get(i));
      }
      tmp = new DenseDoubleMatrix(Mtransposed);
      tmp = tmp.multiply(2*TETTA*scoreDifference);
      res.userFeatureFactorized = e.userFeatureFactorized.add(tmp);
    }
    return res;
  }
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleMatrix

    String master = peer.getPeerName(peer.getNumPeers()/2);
    peer.send(master, msg);
    peer.sync();

    // normalize
    DoubleMatrix res = null;
    if (peer.getPeerName().equals(master)) {
      res = new DenseDoubleMatrix(featureMatrix.getRowCount(),
                                  featureMatrix.getColumnCount(), 0);
      int incomingMsgCount = 0;
      while ( (msg = peer.getCurrentMessage()) != null) {
        MatrixWritable tmp = (MatrixWritable) msg.get(msgFeatureMatrix);
        res.add(tmp.getMatrix());
        incomingMsgCount++;
      }
      res.divide(incomingMsgCount);
    }

    if (broadcast) {
      if (peer.getPeerName().equals(master)) {
        // broadcast to all
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleMatrix

      // save item features
      for (Map.Entry<String, VectorWritable> feature : inpItemsFeatures.entrySet()) {
        peer.write(new Text(OnlineCF.Settings.DFLT_MODEL_ITEM_FEATURES_DELIM+feature.getKey()), feature.getValue());
      }
      // item feature factorized values should be normalized
      DoubleMatrix res = normalizeMatrix(peer, itemFeatureMatrix,
          OnlineCF.Settings.MSG_ITEM_FEATURE_MATRIX, false);
     
      if (res != null) {
        Text key = new Text(OnlineCF.Settings.DFLT_MODEL_ITEM_MTX_FEATURES_DELIM +
            OnlineCF.Settings.MSG_ITEM_FEATURE_MATRIX.toString());
        peer.write(key, convertMatrixToVector(res));
      }
    }

    if (userFeatureMatrix != null) {
      // save user features
   // save item features
      for (Map.Entry<String, VectorWritable> feature : inpUsersFeatures.entrySet()) {
        peer.write(new Text(OnlineCF.Settings.DFLT_MODEL_USER_FEATURES_DELIM+feature.getKey()), feature.getValue());
      }
      // user feature factorized values should be normalized
      DoubleMatrix res = normalizeMatrix(peer, userFeatureMatrix,
          OnlineCF.Settings.MSG_USER_FEATURE_MATRIX, false);
     
      if (res != null) {
        Text key = new Text(OnlineCF.Settings.DFLT_MODEL_USER_MTX_FEATURES_DELIM +
            OnlineCF.Settings.MSG_USER_FEATURE_MATRIX.toString());
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleMatrix

      }
    }
  }

  public static DoubleMatrix read(DataInput in) throws IOException {
    DoubleMatrix mat = new DenseDoubleMatrix(in.readInt(), in.readInt());
    for (int row = 0; row < mat.getRowCount(); row++) {
      for (int col = 0; col < mat.getColumnCount(); col++) {
        mat.set(row, col, in.readDouble());
      }
    }
    return mat;
  }
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleMatrix

    assertEquals(LearningStyle.UNSUPERVISED, annCopy.getLearningStyle());

    // compare weights
    DoubleMatrix[] weightsMatrices = annCopy.getWeightMatrices();
    for (int i = 0; i < weightsMatrices.length; ++i) {
      DoubleMatrix expectMat = matrices[i];
      DoubleMatrix actualMat = weightsMatrices[i];
      for (int j = 0; j < expectMat.getRowCount(); ++j) {
        for (int k = 0; k < expectMat.getColumnCount(); ++k) {
          assertEquals(expectMat.get(j, k), actualMat.get(j, k), 0.000001);
        }
      }
    }
   
    FeatureTransformer copyTransformer = annCopy.getFeatureTransformer();
View Full Code Here

Examples of org.apache.hama.ml.math.DoubleMatrix

      }
    }
  }

  public static DoubleMatrix read(DataInput in) throws IOException {
    DoubleMatrix mat = new DenseDoubleMatrix(in.readInt(), in.readInt());
    for (int row = 0; row < mat.getRowCount(); row++) {
      for (int col = 0; col < mat.getColumnCount(); col++) {
        mat.set(row, col, in.readDouble());
      }
    }
    return mat;
  }
View Full Code Here

Examples of org.jblas.DoubleMatrix

public class JBLASNativeJavaInterface {

    //  Computes the eigenvalues of a general matrix.
public static ComplexDoubleMatrix jblas_eigenvalues(double [][]dM) {
    return org.jblas.Eigen.eigenvalues(new DoubleMatrix(dM));
}
View Full Code Here

Examples of org.jblas.DoubleMatrix

   //   Computes the eigenvalues and eigenvectors of a general matrix.
   //   returns an array of ComplexDoubleMatrix objects containing the eigenvectors
   //          stored as the columns of the first matrix, and the eigenvalues as the
   //         diagonal elements of the second matrix.
public static ComplexDoubleMatrix[]  jblas_eigenvectors(double [][]dM) {
    return org.jblas.Eigen.eigenvectors(new DoubleMatrix(dM));
}
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.