Examples of DenseDoubleVector


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

   *
   * @param inputInstance
   * @return The compressed information.
   */
  private DoubleVector transform(DoubleVector inputInstance, int inputLayer) {
    DoubleVector internalInstance = new DenseDoubleVector(inputInstance.getDimension() + 1);
    internalInstance.set(0, 1);
    for (int i = 0; i < inputInstance.getDimension(); ++i) {
      internalInstance.set(i + 1, inputInstance.get(i));
    }
    DoubleFunction squashingFunction = model
        .getSquashingFunction(inputLayer);
    DoubleMatrix weightMatrix = null;
    if (inputLayer == 0) {
View Full Code Here

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

        double[] vals = new double[tokens.length];
        for (int i = 0; i < tokens.length; ++i) {
          vals[i] = Double.parseDouble(tokens[i]);
        }
        writer.append(new LongWritable(), new VectorWritable(
            new DenseDoubleVector(vals)));
      }
      writer.close();
      br.close();
    } catch (IOException e1) {
      e1.printStackTrace();
View Full Code Here

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

   * The model meta-data is stored in memory.
   */
  public DoubleVector outputWrapper(DoubleVector featureVector) {
    List<double[]> outputCache = this.outputInternal(featureVector);
    // the output of the last layer is the output of the MLP
    return new DenseDoubleVector(outputCache.get(outputCache.size() - 1));
  }
View Full Code Here

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

    double[] trainingFeature = this.featureTransformer.transform(
        trainingInstance.sliceUnsafe(0, this.layerSizeArray[0] - 1)).toArray();
    double[] trainingLabels = Arrays.copyOfRange(trainingVec,
        this.layerSizeArray[0], trainingVec.length);

    DoubleVector trainingFeatureVec = new DenseDoubleVector(trainingFeature);
    List<double[]> outputCache = this.outputInternal(trainingFeatureVec);

    // calculate the delta of output layer
    double[] delta = new double[this.layerSizeArray[this.layerSizeArray.length - 1]];
    double[] outputLayerOutput = outputCache.get(outputCache.size() - 1);
View Full Code Here

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

        this.layerSizeList.get(0) - 1));
    // transform the features to another space
    DoubleVector transformedInstance = this.featureTransformer
        .transform(instance);
    // add bias feature
    DoubleVector instanceWithBias = new DenseDoubleVector(
        transformedInstance.getDimension() + 1);
    instanceWithBias.set(0, 0.99999); // set bias to be a little bit less than
                                      // 1.0
    for (int i = 1; i < instanceWithBias.getDimension(); ++i) {
      instanceWithBias.set(i, transformedInstance.get(i - 1));
    }

    List<DoubleVector> outputCache = getOutputInternal(instanceWithBias);
    // return the output of the last layer
    DoubleVector result = outputCache.get(outputCache.size() - 1);
View Full Code Here

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

    DoubleVector vec = weightMatrix.multiplyVectorUnsafe(intermediateOutput);
    vec = vec.applyToElements(this.squashingFunctionList.get(fromLayer));

    // add bias
    DoubleVector vecWithBias = new DenseDoubleVector(vec.getDimension() + 1);
    vecWithBias.set(0, 1);
    for (int i = 0; i < vec.getDimension(); ++i) {
      vecWithBias.set(i + 1, vec.get(i));
    }
    return vecWithBias;
  }
View Full Code Here

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

              .format(
                  "The dimension of training instance is %d, but requires %d.",
                  trainingInstance.getDimension(), inputDimension
                      + outputDimension));

      inputInstance = new DenseDoubleVector(this.layerSizeList.get(0));
      inputInstance.set(0, 1); // add bias
      // get the features from the transformed vector
      for (int i = 0; i < inputDimension; ++i) {
        inputInstance.set(i + 1, transformedVector.get(i));
      }
      // get the labels from the original training instance
      labels = trainingInstance.sliceUnsafe(inputInstance.getDimension() - 1,
          trainingInstance.getDimension() - 1);
    } else if (this.learningStyle == LearningStyle.UNSUPERVISED) {
      // labels are identical to input features
      outputDimension = inputDimension;
      // validate training instance
      Preconditions.checkArgument(inputDimension == trainingInstance
          .getDimension(), String.format(
          "The dimension of training instance is %d, but requires %d.",
          trainingInstance.getDimension(), inputDimension));

      inputInstance = new DenseDoubleVector(this.layerSizeList.get(0));
      inputInstance.set(0, 1); // add bias
      // get the features from the transformed vector
      for (int i = 0; i < inputDimension; ++i) {
        inputInstance.set(i + 1, transformedVector.get(i));
      }
View Full Code Here

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

        .size()];
    for (int m = 0; m < weightUpdateMatrices.length; ++m) {
      weightUpdateMatrices[m] = new DenseDoubleMatrix(this.weightMatrixList
          .get(m).getRowCount(), this.weightMatrixList.get(m).getColumnCount());
    }
    DoubleVector deltaVec = new DenseDoubleVector(
        this.layerSizeList.get(this.layerSizeList.size() - 1));

    DoubleFunction squashingFunction = this.squashingFunctionList
        .get(this.squashingFunctionList.size() - 1);

    DoubleMatrix lastWeightMatrix = this.weightMatrixList
        .get(this.weightMatrixList.size() - 1);
    for (int i = 0; i < deltaVec.getDimension(); ++i) {
      double costFuncDerivative = this.costFunction.applyDerivative(
          labels.get(i), output.get(i + 1));
      // add regularization
      costFuncDerivative += this.regularizationWeight
          * lastWeightMatrix.getRowVector(i).sum();
      deltaVec.set(i, costFuncDerivative);
      deltaVec.set(
          i,
          deltaVec.get(i)
              * squashingFunction.applyDerivative(output.get(i + 1)));
    }

    // start from previous layer of output layer
    for (int layer = this.layerSizeList.size() - 2; layer >= 0; --layer) {
View Full Code Here

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

        key = new Text(split[0]);
        value = new VectorWritable();
        double[] values = new double[2];
        values[0] = Double.valueOf(split[1]);
        values[1] = Double.valueOf(split[2]);
        DenseDoubleVector dd = new DenseDoubleVector(values);
        value.set(dd);
      }
    });

    final HashMap<String, Integer> genreIndexes = new HashMap<String, Integer>();
    genreIndexes.put("action", 0);
    genreIndexes.put("animation", 1);
    genreIndexes.put("children", 2);
    genreIndexes.put("comedy", 3);
    genreIndexes.put("crime", 4);
    genreIndexes.put("documentary", 5);
    genreIndexes.put("drama", 6);
    genreIndexes.put("fantasy", 7);
    genreIndexes.put("film-noir", 8);
    genreIndexes.put("horror", 9);
    genreIndexes.put("musical", 10);
    genreIndexes.put("mystery", 11);
    genreIndexes.put("romance", 12);
    genreIndexes.put("sci-fi", 13);
    genreIndexes.put("thriller", 14);
    genreIndexes.put("war", 15);
    genreIndexes.put("western", 16);
    genreIndexes.put("imax", 17);
    genreIndexes.put("adventure", 18);

    conv.setInputItemFeatures(itemFeaturesPath,
        new KeyValueParser<Text, VectorWritable>() {
      public void parseLine(String ln) {
        String[] split = ln.split("::");
        key = new Text(split[0]);
        String[] genres = split[2].toLowerCase().split("[|]");
        value = new VectorWritable();
       
        DenseDoubleVector values = new DenseDoubleVector(genreIndexes.size());
        for (int i=0; i<genres.length; i++) {
          Integer id = genreIndexes.get(genres[i]);
          if (id == null) {
            continue;
          }
          values.set(id, 1);
        }
        value.set(values);
      }
    });
    return conv.convert(outputPath);
View Full Code Here

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

  public OutputStructure compute(InputStructure e) {
    OutputStructure res = new OutputStructure();

    int rank = e.user.getVector().getLength();
    if (zeroVector == null) {
      zeroVector = new DenseDoubleVector(rank, 0);
    }
    // below vectors are all size of MATRIX_RANK
    DoubleVector vl_yb_item = zeroVector;
    DoubleVector ml_xa_user = zeroVector;
    DoubleVector bbl_vl_yb = null;
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.