本文整理汇总了Java中org.nd4j.linalg.ops.transforms.Transforms.allEuclideanDistances方法的典型用法代码示例。如果您正苦于以下问题:Java Transforms.allEuclideanDistances方法的具体用法?Java Transforms.allEuclideanDistances怎么用?Java Transforms.allEuclideanDistances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.nd4j.linalg.ops.transforms.Transforms
的用法示例。
在下文中一共展示了Transforms.allEuclideanDistances方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmbedding
import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Test
public void testEmbedding(){
INDArray z1 = Nd4j.randn(2000, 400);
INDArray z2 = z1.dup();
INDArray result = Transforms.allEuclideanDistances(z1, z2, 1);
RandomProjection rp = new RandomProjection(0.5);
INDArray zp = rp.project(z1);
INDArray zp2 = zp.dup();
INDArray projRes = Transforms.allEuclideanDistances(zp, zp2, 1);
// check that the automatically tuned values for the density respect the
// contract for eps: pairwise distances are preserved according to the
// Johnson-Lindenstrauss lemma
INDArray ratios = projRes.div(result);
for (int i = 0; i < ratios.length(); i++){
double val = ratios.getDouble(i);
// this avoids the NaNs we get along the diagonal
if (val == val) {
assertTrue(ratios.getDouble(i) < 1.5);
}
}
}
示例2: testAllDistances1
import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Test
public void testAllDistances1() throws Exception {
INDArray initialX = Nd4j.create(5, 10);
INDArray initialY = Nd4j.create(7, 10);
for (int i = 0; i < initialX.rows(); i++) {
initialX.getRow(i).assign(i + 1);
}
for (int i = 0; i < initialY.rows(); i++) {
initialY.getRow(i).assign(i + 101);
}
INDArray result = Transforms.allEuclideanDistances(initialX, initialY, 1);
Nd4j.getExecutioner().commit();
assertEquals(5 * 7, result.length());
for (int x = 0; x < initialX.rows(); x++) {
INDArray rowX = initialX.getRow(x).dup();
for (int y = 0; y < initialY.rows(); y++) {
double res = result.getDouble(x, y);
double exp = Transforms.euclideanDistance(rowX, initialY.getRow(y).dup());
assertEquals("Failed for [" + x + ", " + y + "]", exp, res, 0.001);
}
}
}
示例3: testAllDistances3_Large
import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Test
public void testAllDistances3_Large() throws Exception {
INDArray initialX = Nd4j.create(5, 2000);
INDArray initialY = Nd4j.create(7, 2000);
for (int i = 0; i < initialX.rows(); i++) {
initialX.getRow(i).assign(i + 1);
}
for (int i = 0; i < initialY.rows(); i++) {
initialY.getRow(i).assign(i + 101);
}
INDArray result = Transforms.allEuclideanDistances(initialX, initialY, 1);
assertEquals(5 * 7, result.length());
for (int x = 0; x < initialX.rows(); x++) {
INDArray rowX = initialX.getRow(x).dup();
for (int y = 0; y < initialY.rows(); y++) {
double res = result.getDouble(x, y);
double exp = Transforms.euclideanDistance(rowX, initialY.getRow(y).dup());
assertEquals("Failed for [" + x + ", " + y + "]", exp, res, 0.001);
}
}
}
示例4: testAllDistances3_Large_Columns
import org.nd4j.linalg.ops.transforms.Transforms; //导入方法依赖的package包/类
@Test
public void testAllDistances3_Large_Columns() throws Exception {
INDArray initialX = Nd4j.create(2000, 5);
INDArray initialY = Nd4j.create(2000, 7);
for (int i = 0; i < initialX.columns(); i++) {
initialX.getColumn(i).assign(i + 1);
}
for (int i = 0; i < initialY.columns(); i++) {
initialY.getColumn(i).assign(i + 101);
}
INDArray result = Transforms.allEuclideanDistances(initialX, initialY, 0);
assertEquals(5 * 7, result.length());
for (int x = 0; x < initialX.columns(); x++) {
INDArray colX = initialX.getColumn(x).dup();
for (int y = 0; y < initialY.columns(); y++) {
double res = result.getDouble(x, y);
double exp = Transforms.euclideanDistance(colX, initialY.getColumn(y).dup());
assertEquals("Failed for [" + x + ", " + y + "]", exp, res, 0.001);
}
}
}