当前位置: 首页>>代码示例>>Java>>正文


Java DoubleMatrix.norm2方法代码示例

本文整理汇总了Java中org.jblas.DoubleMatrix.norm2方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix.norm2方法的具体用法?Java DoubleMatrix.norm2怎么用?Java DoubleMatrix.norm2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jblas.DoubleMatrix的用法示例。


在下文中一共展示了DoubleMatrix.norm2方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: distance

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
public static double distance(DoubleMatrix x, DoubleMatrix y)
{
    return 1 - (x.dot(y) / (x.norm2() * y.norm2()));
}
 
开发者ID:rdspring1,项目名称:LSH_DeepLearning,代码行数:5,代码来源:CosineDistance.java

示例2: computeEmbedding

import org.jblas.DoubleMatrix; //导入方法依赖的package包/类
/**
 * Compute a projection to this.lowDims dimensions. The initial guess for the projection is set to the given matrix.
 * @param dataLowDimInit Initial value for the projection.
 * @return Projection of the high-dimensional data, computed with metric mds.
 */
public DoubleMatrix computeEmbedding(DoubleMatrix dataLowDimInit) {
    this.dataLowDim.copy(dataLowDimInit);
    this.distsLowDim.copy(this.computeLowDimDistances(this.dataLowDim));

    int iterations = 0;
    double cost = this.cost();
    double magnitude;
    double initialCost = cost;
    int convergedCount = 0;
    do {
        /* Compute the gradient */
        DoubleMatrix gradient = this.gradient();
        DoubleMatrix step = this.gradient().mul(this.learningRate / this.numObservations).neg();
        /* Move the low-dimensional points s.t. the cost locally decreases. */
        this.dataLowDim.addi(step);

        magnitude = gradient.norm2() / this.numObservations;
        double newCost = this.cost();
        if (this.verbose) {
            LOG.info(
                String.format(
                    "\n[Iteration %d]\n\tCost:        \t%6.3e\n\tMagnitude:   \t%6.3e\n\tLearning rate:\t%6.3e",
                    iterations,
                    newCost,
                    magnitude,
                    learningRate
                )
            );
        }

        this.learningRate *= this.learningRateDecay;
        iterations++;
        cost = newCost;
        /* Continue while the convergence criterion isn't met and the max # iterations isn't met. */
    } while (Math.abs(magnitude) > MetricMDS.tolerance && iterations < MetricMDS.maxIterations);

    if (Math.abs(magnitude) > MetricMDS.tolerance)
        LOG.warning("Terminated before tolerance was met.");
    LOG.info(String.format("MDS optimization took %d iterations.", iterations));
    LOG.info(String.format("\nCost before optimization: %6.3e\nCost after optimization:  %6.3e", initialCost,
            cost));

    /* Divide by the normalization factor, s.t. the result reflects the original distances. */
    return this.dataLowDim.div(this.scaling);
}
 
开发者ID:vmware,项目名称:hillview,代码行数:51,代码来源:MetricMDS.java


注:本文中的org.jblas.DoubleMatrix.norm2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。