added optional scale factor to v

This commit is contained in:
Jonathan Shook 2023-12-08 11:29:39 -06:00
parent 83812ef8d3
commit 2db38fb041
2 changed files with 15 additions and 1 deletions

View File

@ -28,10 +28,16 @@ public class DNN_euclidean_v implements LongFunction<float[]> {
private final int D; private final int D;
private final long N; private final long N;
private final double scale;
public DNN_euclidean_v(int D, long N) { public DNN_euclidean_v(int D, long N) {
this(D,N,1.0d);
}
public DNN_euclidean_v(int D, long N, double scale) {
this.D = D; this.D = D;
this.N = N; this.N = N;
this.scale = scale;
} }
@Override @Override
@ -41,7 +47,7 @@ public class DNN_euclidean_v implements LongFunction<float[]> {
} }
float[] vector = new float[D]; float[] vector = new float[D];
for (int idx = 0; idx < vector.length; idx++) { for (int idx = 0; idx < vector.length; idx++) {
vector[idx]= (float)idx+value; vector[idx]= (float)((idx+value)*scale);
} }
return vector; return vector;
} }

View File

@ -30,6 +30,14 @@ class DNNEuclideanVTest {
assertThrows(RuntimeException.class, () -> vf.apply(7)); assertThrows(RuntimeException.class, () -> vf.apply(7));
} }
@Test
public void testBasicVectorsScaled() {
DNN_euclidean_v vf = new DNN_euclidean_v(5, 7, 3.0);
assertThat(vf.apply(3L)).isEqualTo(new float[]{9f,12f,15f,18f,21f});
assertThrows(RuntimeException.class, () -> vf.apply(7));
}
@Test @Test
public void testWrappingVectors() { public void testWrappingVectors() {
DNN_euclidean_v_wrap vf = new DNN_euclidean_v_wrap(5, 7); DNN_euclidean_v_wrap vf = new DNN_euclidean_v_wrap(5, 7);