Package org.apache.mahout.math.function

Examples of org.apache.mahout.math.function.DoubleFunction


    List<Vector> internalResults = this.getOutputInternal(inputInstance);

    Vector deltaVec = new DenseVector(this.layerSizeList.get(this.layerSizeList.size() - 1));
    Vector output = internalResults.get(internalResults.size() - 1);

    final DoubleFunction derivativeSquashingFunction =
        NeuralNetworkFunctions.getDerivativeDoubleFunction(this.squashingFunctionList.get(this.squashingFunctionList.size() - 1));

    final DoubleDoubleFunction costFunction = NeuralNetworkFunctions.getDerivativeDoubleDoubleFunction(this.costFunctionName);

    Matrix lastWeightMatrix = this.weightMatrixList.get(this.weightMatrixList.size() - 1);

    for (int i = 0; i < deltaVec.size(); ++i) {
      double costFuncDerivative = costFunction.apply(labels.get(i), output.get(i + 1));
      // add regularization
      costFuncDerivative += this.regularizationWeight * lastWeightMatrix.viewRow(i).zSum();
      deltaVec.set(i, costFuncDerivative);
      deltaVec.set(i, deltaVec.get(i) * derivativeSquashingFunction.apply(output.get(i + 1)));
    }

    // start from previous layer of output layer
    for (int layer = this.layerSizeList.size() - 2; layer >= 0; --layer) {
      deltaVec = backPropagate(layer, deltaVec, internalResults, weightUpdateMatrices[layer]);
View Full Code Here


   */
  private Vector backPropagate(int curLayerIdx, Vector nextLayerDelta,
                               List<Vector> outputCache, Matrix weightUpdateMatrix) {

    // get layer related information
    final DoubleFunction derivativeSquashingFunction =
        NeuralNetworkFunctions.getDerivativeDoubleFunction(this.squashingFunctionList.get(curLayerIdx));
    Vector curLayerOutput = outputCache.get(curLayerIdx);
    Matrix weightMatrix = this.weightMatrixList.get(curLayerIdx);
    Matrix 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.viewPart(1, nextLayerDelta.size() - 1);
    }

    Vector delta = weightMatrix.transpose().times(nextLayerDelta);

    delta = delta.assign(curLayerOutput, new DoubleDoubleFunction() {
      @Override
      public double apply(double deltaElem, double curLayerOutputElem) {
        return deltaElem * derivativeSquashingFunction.apply(curLayerOutputElem);
      }
    });

    // update weights
    for (int i = 0; i < weightUpdateMatrix.rowSize(); ++i) {
View Full Code Here

        Vector viewC1 = mx.viewColumn(c1);
        col.assign(col.minus(viewC1.times(viewC1.dot(col))));

      }
      final double norm2 = col.norm(2);
      col.assign(new DoubleFunction() {
        @Override
        public double apply(double x) {
          return x / norm2;
        }
      });
View Full Code Here

    }
    return corpus;
  }

  public static Matrix randomStructuredModel(int numTopics, int numTerms) {
    return randomStructuredModel(numTopics, numTerms, new DoubleFunction() {
      @Override public double apply(double d) {
        return 1.0 / (1 + Math.abs(d));
      }
    });
  }
View Full Code Here

    final Random rand = RandomUtils.getRandom();

    // build a vector full of sample from exponential distribuiton
    // this will have lots of little positive values and a few big ones
    Vector p1 = new DenseVector(25)
      .assign(new DoubleFunction() {
        @Override
        public double apply(double arg1) {
          return -Math.log1p(-rand.nextDouble());
        }
      });
View Full Code Here

    updateSteps.assign(other.updateSteps);
    updateCounts.assign(other.updateCounts);
  }

  public boolean validModel() {
    double k = beta.aggregate(Functions.PLUS, new DoubleFunction() {
      @Override
      public double apply(double v) {
        return Double.isNaN(v) || Double.isInfinite(v) ? 1 : 0;
      }
    });
View Full Code Here

    }
  }

  private static Vector randomVector(final Random gen, int n) {
    Vector x = new DenseVector(n);
    x.assign(new DoubleFunction() {
      @Override
      public double apply(double v) {
        return gen.nextGaussian();
      }
    });
View Full Code Here

    check("EigenvalueDecomposition (evil)...", x.times(v), v.times(d));
  }

  @Test
  public void testDeficientRank() {
    Matrix a = new DenseMatrix(10, 3).assign(new DoubleFunction() {
      Random gen = RandomUtils.getRandom();

      @Override
      public double apply(double arg1) {
        return gen.nextGaussian();
View Full Code Here

      // finish off pending regularization
      model.close();

      Matrix beta = model.getBeta();
      maxBeta = beta.aggregate(Functions.MAX, Functions.ABS);
      nonZeros = beta.aggregate(Functions.PLUS, new DoubleFunction() {
        @Override
        public double apply(double v) {
          return Math.abs(v) > 1.0e-6 ? 1 : 0;
        }
      });
      positive = beta.aggregate(Functions.PLUS, new DoubleFunction() {
        @Override
        public double apply(double v) {
          return v > 0 ? 1 : 0;
        }
      });
View Full Code Here

    for (int i=0; i<terms.length; i++) {
      terms[i] = String.valueOf((char) (i + 'a'));
    }
    int numGeneratingTopics = 3;
    int numTerms = 26;
    Matrix matrix = ClusteringTestUtils.randomStructuredModel(numGeneratingTopics, numTerms, new DoubleFunction() {
      @Override public double apply(double d) {
        return 1.0 / Math.pow(d + 1.0, 2);
      }
    });
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.function.DoubleFunction

Copyright © 2018 www.massapicom. 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.