本文整理汇总了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()));
}
示例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);
}