Merge branch 'jshook/vector_precision'
56
pom.xml
@ -19,6 +19,20 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nosqlbench</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>virtdata-api</artifactId>
|
||||
<version>5.21.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>virtdata-lib-basics</artifactId>
|
||||
<version>5.21.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<parent>
|
||||
<artifactId>mvn-defaults</artifactId>
|
||||
@ -34,47 +48,6 @@
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<!-- CORE MODULES -->
|
||||
<module.mvn-defaults>mvn-defaults</module.mvn-defaults>
|
||||
<module.nb-api>nb-api</module.nb-api>
|
||||
<module.nb-annotations>nb-annotations</module.nb-annotations>
|
||||
<module.adapters-api>adapters-api</module.adapters-api>
|
||||
<module.engine-api>engine-api</module.engine-api>
|
||||
|
||||
<module.engine-extensions>engine-extensions</module.engine-extensions>
|
||||
<module.engine-docker>engine-docker</module.engine-docker>
|
||||
<module.engine-cli>engine-cli</module.engine-cli>
|
||||
|
||||
<module.nb5>nb5</module.nb5>
|
||||
<module.nbr>nbr</module.nbr>
|
||||
|
||||
<module.nb-spectest>nb-spectest</module.nb-spectest>
|
||||
<!-- <module.nbr-examples>nbr-examples</module.nbr-examples>-->
|
||||
|
||||
<!-- driver modules -->
|
||||
<module.adapter-diag>adapter-diag</module.adapter-diag>
|
||||
<module.adapter-stdout>adapter-stdout</module.adapter-stdout>
|
||||
<module.adapter-cqld4>adapter-cqld4</module.adapter-cqld4>
|
||||
<module.adapter-http>adapter-http</module.adapter-http>
|
||||
<module.adapter-tcp>adapter-tcp</module.adapter-tcp>
|
||||
<module.adapter-dynamodb>adapter-dynamodb</module.adapter-dynamodb>
|
||||
<module.adapter-mongodb>adapter-mongodb</module.adapter-mongodb>
|
||||
<module.adapter-pulsar>adapter-pulsar</module.adapter-pulsar>
|
||||
<module.adapter-s4j>adapter-s4j</module.adapter-s4j>
|
||||
<module.adapter-kafka>adapter-kafka</module.adapter-kafka>
|
||||
<module.adapter-kafka>adapter-amqp</module.adapter-kafka>
|
||||
<module.adapter-jdbc>adapter-jdbc</module.adapter-jdbc>
|
||||
|
||||
<!-- VIRTDATA MODULES -->
|
||||
<module.virtdata-api>virtdata-api</module.virtdata-api>
|
||||
<module.virtdata-lang>virtdata-lang</module.virtdata-lang>
|
||||
<module.virtdata-realdata>virtdata-realdata</module.virtdata-realdata>
|
||||
<module.virtdata-lib-basics>virtdata-lib-basics</module.virtdata-lib-basics>
|
||||
<module.virtdata-lib-random>virtdata-lib-random</module.virtdata-lib-random>
|
||||
<module.virtdata-lib-curves4>virtdata-lib-curves4</module.virtdata-lib-curves4>
|
||||
<module.virtdata-lib-realer>virtdata-lib-realer</module.virtdata-lib-realer>
|
||||
<module.virtdata-lib-realer>virtdata-lib-hdf5</module.virtdata-lib-realer>
|
||||
<module.virtdata-userlibs>virtdata-userlibs</module.virtdata-userlibs>
|
||||
</properties>
|
||||
<modules>
|
||||
|
||||
@ -119,6 +92,7 @@
|
||||
<module>virtdata-lib-curves4</module>
|
||||
<module>virtdata-lib-realer</module>
|
||||
<module>virtdata-lib-hdf5</module>
|
||||
<module>virtdata-lib-vectors</module>
|
||||
<module>virtdata-userlibs</module>
|
||||
|
||||
<!-- Documentation -->
|
||||
|
@ -76,6 +76,36 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-statistics-distribution</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apfloat</groupId>
|
||||
<artifactId>apfloat</artifactId>
|
||||
<version>1.13.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.matheclipse</groupId>
|
||||
<artifactId>matheclipse-core</artifactId>
|
||||
<version>3.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.matheclipse</groupId>
|
||||
<artifactId>matheclipse-gpl</artifactId>
|
||||
<version>3.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>snapshots-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
@ -30,11 +30,12 @@ public class DocForFunc implements DocFuncData {
|
||||
private String inType;
|
||||
private String outType;
|
||||
private final ArrayList<DocCtorData> ctors = new ArrayList<>();
|
||||
private Category[] categories = new Category[] { };
|
||||
private Category[] categories = new Category[]{};
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
@ -48,6 +49,7 @@ public class DocForFunc implements DocFuncData {
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return className;
|
||||
@ -56,6 +58,7 @@ public class DocForFunc implements DocFuncData {
|
||||
public void setClassJavadoc(String classJavadoc) {
|
||||
this.classJavadoc = classJavadoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassJavadoc() {
|
||||
return classJavadoc;
|
||||
@ -64,6 +67,7 @@ public class DocForFunc implements DocFuncData {
|
||||
public void setInType(String inType) {
|
||||
this.inType = inType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInType() {
|
||||
return inType;
|
||||
@ -72,13 +76,14 @@ public class DocForFunc implements DocFuncData {
|
||||
public void setOutType(String outType) {
|
||||
this.outType = outType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOutType() {
|
||||
return outType;
|
||||
}
|
||||
|
||||
public void addCtor(String ctorDoc, LinkedHashMap<String, String> args, List<List<String>> examples) {
|
||||
if (this.className==null || this.className.isEmpty()) {
|
||||
if (this.className == null || this.className.isEmpty()) {
|
||||
throw new RuntimeException("Unable to document ctor without known class name first.");
|
||||
}
|
||||
DocForFuncCtor ctor = new DocForFuncCtor(getClassName(), ctorDoc, args, examples);
|
||||
@ -93,16 +98,19 @@ public class DocForFunc implements DocFuncData {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DocForFunction{" +
|
||||
"packageName='" + packageName + '\'' +
|
||||
", className='" + className + '\'' +
|
||||
", classJavadoc='" + classJavadoc + '\'' +
|
||||
", inType='" + inType + '\'' +
|
||||
", outType='" + outType + '\'' +
|
||||
", ctors=" + ctors +
|
||||
'}';
|
||||
"(" + className + ")" +
|
||||
"packageName='" + packageName + '\'' +
|
||||
", className='" + className + '\'' +
|
||||
", classJavadoc='" + classJavadoc + '\'' +
|
||||
", inType='" + inType + '\'' +
|
||||
", outType='" + outType + '\'' +
|
||||
", ctors=" + ctors +
|
||||
'}';
|
||||
}
|
||||
|
||||
public void addCategories(Category[] categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,9 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
|
72
virtdata-lib-vectors/pom.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<!--
|
||||
~ Copyright (c) 2023-2024 nosqlbench
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>mvn-defaults</artifactId>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../mvn-defaults</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>virtdata-lib-vectors</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>virtdata-lib-vectors</name>
|
||||
<url>http://nosqlbench.io/</url>
|
||||
|
||||
<description>With inspiration from other libraries</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>virtdata-lib-basics</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>virtdata-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.md</include>
|
||||
<include>**/*.yaml</include>
|
||||
<include>**/*.txt</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
</resource>
|
||||
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms;
|
||||
package io.nosqlbench.virtdata.lib.vectors.algorithms;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms;
|
||||
package io.nosqlbench.virtdata.lib.vectors.algorithms;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms;
|
||||
package io.nosqlbench.virtdata.lib.vectors.algorithms;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
@ -39,7 +39,7 @@ public class DNN_angular1_neighbors implements IntFunction<int[]> {
|
||||
* The size of neighborhood
|
||||
* @param N
|
||||
* The number of total vectors, necessary for boundary conditions of defined vector
|
||||
* @param module
|
||||
* @param modulus
|
||||
* The modulus used during training of angular1 data; this corresponds to how periodically we cycle back
|
||||
* to vectors with the same angle (hence have angular distance zero between them)
|
||||
*/
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
@ -25,7 +25,7 @@ import java.util.function.LongFunction;
|
||||
|
||||
@ThreadSafeMapper
|
||||
@Categories(Category.experimental)
|
||||
public class DNN_angular1_v implements LongFunction<float[]> {
|
||||
public class DnnAngular1V implements LongFunction<float[]> {
|
||||
|
||||
private final int d;
|
||||
private final long n;
|
||||
@ -39,7 +39,7 @@ public class DNN_angular1_v implements LongFunction<float[]> {
|
||||
* @param M
|
||||
* The modulo which is used to construct equivalence classes
|
||||
*/
|
||||
public DNN_angular1_v(int D, long N, long M) {
|
||||
public DnnAngular1V(int D, long N, long M) {
|
||||
d = D;
|
||||
n = N;
|
||||
m = M;
|
After Width: | Height: | Size: 54 KiB |
@ -9,6 +9,9 @@
|
||||
id="svg1"
|
||||
inkscape:version="1.3 (0e150ed, 2023-07-21)"
|
||||
sodipodi:docname="dnn_angular.svg"
|
||||
inkscape:export-filename="dnn_angular.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
@ -25,13 +28,13 @@
|
||||
inkscape:document-units="mm"
|
||||
showgrid="true"
|
||||
inkscape:zoom="0.82130594"
|
||||
inkscape:cx="97.405846"
|
||||
inkscape:cy="563.12755"
|
||||
inkscape:window-width="1830"
|
||||
inkscape:window-height="1141"
|
||||
inkscape:cx="312.91628"
|
||||
inkscape:cy="560.6924"
|
||||
inkscape:window-width="3440"
|
||||
inkscape:window-height="1487"
|
||||
inkscape:window-x="774"
|
||||
inkscape:window-y="2278"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:window-y="2336"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="layer1">
|
||||
<inkscape:grid
|
||||
id="grid1"
|
||||
@ -567,6 +570,17 @@
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
style="display:inline">
|
||||
<rect
|
||||
style="font-variation-settings:normal;opacity:1;fill:#ffffff;fill-opacity:1;stroke:#0000ff;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
id="rect21"
|
||||
width="140"
|
||||
height="260"
|
||||
x="30.000002"
|
||||
y="9.999999"
|
||||
ry="10"
|
||||
inkscape:export-filename="dnn_angular1.png"
|
||||
inkscape:export-xdpi="185.45169"
|
||||
inkscape:export-ydpi="185.45169" />
|
||||
<path
|
||||
style="fill:none;fill-opacity:0.549119;stroke:#0000ff;stroke-width:0.25;stroke-linecap:butt;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#DartArrow)"
|
||||
d="M 39.995908,260.002 119.9959,180.00201"
|
||||
@ -701,59 +715,59 @@
|
||||
id="tspan21">11->(12,24)</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
style="font-size:5.64444px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="48.354424"
|
||||
y="258.95441"
|
||||
id="text17"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
style="font-weight:bold;font-size:5.64444px;stroke-width:0.25"
|
||||
x="48.354424"
|
||||
y="258.95441">0</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="57.732384"
|
||||
y="240.00201"
|
||||
x="56.121635"
|
||||
y="239.92148"
|
||||
id="text17-8"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="57.732384"
|
||||
y="240.00201">1</tspan></text>
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="56.121635"
|
||||
y="239.92148">1</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="67.824463"
|
||||
y="200.00203"
|
||||
x="66.213715"
|
||||
y="199.76042"
|
||||
id="text17-8-4"><tspan
|
||||
id="tspan17-8-9"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="67.824463"
|
||||
y="200.00203"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="66.213715"
|
||||
y="199.76042"
|
||||
sodipodi:role="line">2</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="87.786362"
|
||||
y="209.4633"
|
||||
x="86.175613"
|
||||
y="209.78545"
|
||||
id="text17-8-8"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-92"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="87.786362"
|
||||
y="209.4633">4</tspan></text>
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="86.175613"
|
||||
y="209.78545">4</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="97.898849"
|
||||
y="139.84259"
|
||||
x="95.402191"
|
||||
y="139.24033"
|
||||
id="text17-8-9"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-5"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="97.898849"
|
||||
y="139.84259">5</tspan></text>
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="95.402191"
|
||||
y="139.24033">5</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
@ -762,18 +776,17 @@
|
||||
id="text17-8-7"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-1"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="78.44133"
|
||||
y="258.70441">3</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
style="font-size:5.64444px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;white-space:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4);font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;line-height:normal;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;text-indent:0;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;opacity:1;vector-effect:none;-inkscape-stroke:none;stop-color:#000000;stop-opacity:1"
|
||||
x="108.40641"
|
||||
y="258.70425"
|
||||
id="text17-8-2"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-2"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
style="font-weight:bold;stroke-width:0.25;font-style:normal;font-variant:normal;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="108.40641"
|
||||
y="258.70425">6</tspan></text>
|
||||
<text
|
||||
@ -784,63 +797,52 @@
|
||||
id="text17-8-2-8"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-2-8"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="138.40323"
|
||||
y="258.70438">9</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="146.44943"
|
||||
y="149.95441"
|
||||
x="142.01988"
|
||||
y="150.43764"
|
||||
id="text17-8-6"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-15"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="146.44943"
|
||||
y="149.95441">10</tspan></text>
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="142.01988"
|
||||
y="150.43764">10</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="117.38301"
|
||||
y="179.99886"
|
||||
x="115.93333"
|
||||
y="179.83778"
|
||||
id="text17-8-2-1"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-2-5"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="117.38301"
|
||||
y="179.99886">7</tspan></text>
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="115.93333"
|
||||
y="179.83778">7</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="126.85303"
|
||||
y="80.485207"
|
||||
x="125.24228"
|
||||
y="79.915329"
|
||||
id="text17-8-9-4"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-5-8"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="126.85303"
|
||||
y="80.485207">8</tspan></text>
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="125.24228"
|
||||
y="79.915329">8</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-size:3.175px;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variation-settings:normal;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
x="154.92737"
|
||||
y="20.943657"
|
||||
x="153.69518"
|
||||
y="20"
|
||||
id="text17-8-9-4-1"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan17-8-5-8-7"
|
||||
style="font-weight:bold;stroke-width:0.25"
|
||||
x="154.92737"
|
||||
y="20.943657">11</tspan></text>
|
||||
<rect
|
||||
style="font-variation-settings:normal;opacity:1;fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker-start:url(#ColoredDot);marker-end:url(#marker4)"
|
||||
id="rect21"
|
||||
width="140"
|
||||
height="260"
|
||||
x="30.000002"
|
||||
y="9.999999"
|
||||
ry="10"
|
||||
inkscape:export-filename="dnn_angular1.png"
|
||||
inkscape:export-xdpi="185.45169"
|
||||
inkscape:export-ydpi="185.45169" />
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:5.64444px;line-height:normal;font-family:FreeMono;-inkscape-font-specification:FreeMono;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;white-space:normal;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;marker-start:url(#ColoredDot);marker-end:url(#marker4);stop-color:#000000;stop-opacity:1"
|
||||
x="153.69518"
|
||||
y="20">11</tspan></text>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 54 KiB |
After Width: | Height: | Size: 103 KiB |
After Width: | Height: | Size: 312 KiB |
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circlefield;
|
||||
|
||||
import io.nosqlbench.virtdata.lib.vectors.util.BitFields;
|
||||
|
||||
public class CFVectorMapper {
|
||||
private final CFVectorSpace space;
|
||||
private final int bits;
|
||||
|
||||
public CFVectorMapper(CFVectorSpace space) {
|
||||
this.space = space;
|
||||
this.bits = space.bits();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ord
|
||||
* The ordinal value which is the stable enumeration of a vector
|
||||
* @return
|
||||
*/
|
||||
public double[] vectorForOrdinal(int ord) {
|
||||
int offset = BitFields.reverseIntBitsUnsigned(ord);
|
||||
double unitFraction = unitFraction(offset, 0x4FFF_FFFF);
|
||||
return vecOnCircle(unitFraction);
|
||||
}
|
||||
|
||||
private double unitFraction(int offset, int maxvalue) {
|
||||
int[] fraction = BitFields.alignReducedBits(new int[]{offset, space.maxExcluded()});
|
||||
double unitFraction = ((double) fraction[0]) / ((double) fraction[1]);
|
||||
return unitFraction;
|
||||
}
|
||||
|
||||
public double[] vecOnCircle(double unit) {
|
||||
double radians = 2.0d * Math.PI * unit;
|
||||
return new double[]{Math.cos(radians), Math.sin(radians)};
|
||||
}
|
||||
|
||||
public int[] neighbors(int center, int k) {
|
||||
if (center >= space.maxExcluded()) {
|
||||
throw new RuntimeException("Ordinal value " + center + " must fall within interval [" +
|
||||
space.minIncluded() + "," + space.maxExcluded() + ")" +
|
||||
" for vector space " + space.toString());
|
||||
}
|
||||
int neighborhoodSize = Math.min(space.size, k);
|
||||
if ((neighborhoodSize & 1) == 1) {
|
||||
throw new RuntimeException("neighborhood size must be an even number for now, not " + neighborhoodSize);
|
||||
}
|
||||
int[] neighborhood = new int[neighborhoodSize];
|
||||
|
||||
for (int i = 0; i < neighborhood.length/2; i++) {
|
||||
int ccw = BitFields.rotateBitspace(center, i,30-(space.bits));
|
||||
neighborhood[i<<1]=BitFields.reverseIntBitsUnsigned(ccw);
|
||||
int cw = BitFields.rotateBitspace(center, -i,30-(space.bits));
|
||||
neighborhood[(i<<1)+1]=BitFields.reverseIntBitsUnsigned(cw);
|
||||
}
|
||||
return neighborhood;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circlefield;
|
||||
|
||||
import io.nosqlbench.virtdata.lib.vectors.util.BitFields;
|
||||
|
||||
public class CFVectorSpace {
|
||||
|
||||
/**
|
||||
* The size determines the cardinality of unique vectors within this space.
|
||||
* It is the maximum value exclusive, or the next value after the maximum
|
||||
* value included in the set of ordinals.
|
||||
*/
|
||||
public final int size;
|
||||
/**
|
||||
* The number of bits which are needed to represent the maximum value.
|
||||
*/
|
||||
public final int bits;
|
||||
|
||||
/**
|
||||
* A mask which is used to limit the counting resolution to the bit size;
|
||||
*/
|
||||
public final int mask;
|
||||
|
||||
public CFVectorSpace(int size) {
|
||||
if (size>0x4000_0000) {
|
||||
throw new RuntimeException("Size must be less than or equal to " + 0x4000_0000 + "(0x4000_0000)" +
|
||||
", since all values must fall at perfect divisions of 0x4000_0000");
|
||||
}
|
||||
this.size = size;
|
||||
this.bits = BitFields.getMsbPosition(size);
|
||||
this.mask = 0xFFFFFFFF >> (32-bits);
|
||||
}
|
||||
public int mask() {
|
||||
return this.mask;
|
||||
}
|
||||
public int bits() {
|
||||
return this.bits;
|
||||
}
|
||||
public int minIncluded() {
|
||||
return 0;
|
||||
}
|
||||
public int maxExcluded() {
|
||||
return 1<<30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("CFVectorSpace{");
|
||||
sb.append("size=").append(size);
|
||||
sb.append(" bits=").append(bits());
|
||||
sb.append(" [").append(minIncluded()).append(",").append(maxExcluded()).append(")");
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is an experimental package based on the DNN or "Das/Direct Nearest Neighbor" method.
|
||||
*/
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circlefield;
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circular;
|
||||
|
||||
import io.nosqlbench.virtdata.lib.vectors.util.BitFields;
|
||||
|
||||
/**
|
||||
* <hr/>
|
||||
* <H2>Examples</H2>
|
||||
* <p>
|
||||
* One bit represents the possibility of subdividing the space in one of two ways,
|
||||
* either once at angle 0 from the fixed reference point at (1,0), or twice, at
|
||||
* the initial point and the half-way point around the unit circle.
|
||||
* </P>
|
||||
* <P>Adding a bit of resolution represents a possibility of 4 subdivisions of the
|
||||
* unit circle, and so on, doubling (subdividing) teach previous range for each bit
|
||||
* added. However, it is not strictly required that the space be divided by only
|
||||
* Some 2^n possible spaces. Any value represented by the bit field can represent a
|
||||
* number of subdivisions, whereas the actual last value known to be used determines
|
||||
* how many of the smallest intervals are subdivided and how many further are not.
|
||||
* not.</P>
|
||||
* <HR/>
|
||||
* <H2>Space Filling Curve Calculations</H2>
|
||||
* Here are the steps to mapping an ordinal to it's effective offset with the
|
||||
* representable values for a given width of register.
|
||||
* For some of these operations, you may need to mask to only retain values that properly
|
||||
* fit within the register size for the maximum value, such as the zero case.
|
||||
* <OL>
|
||||
* <LI>Level of Subdivision -Determine the strata of resolution from the most significant bit in
|
||||
* the ordinal. This is simply the leftmost bit which is set. For 0b101, the
|
||||
* MSB is 3.</LI>
|
||||
* <LI>Phase Bits - Determine the number of bits which represent all distinct points
|
||||
* at that resolution. This is calculated as one less than the msb of the ordinal.
|
||||
* For example ordinal 5 (0b101) has msb of 3, so within this level of resolution,
|
||||
* the number of significant bits is 2 (3-1) or (max msb - ordinal msb)</LI>
|
||||
* <LI>Phase Bit Shift - Determine how far the phase index image needs to shift left,
|
||||
* to align the bits at the outer most level rotation. Every strata is aligned
|
||||
* to the unit circle, only with a different initial position and step size.
|
||||
* This is calculated as 2^(max msb - ordinal msb)</LI>
|
||||
* </OL>
|
||||
*/
|
||||
public class CircularPartitioner {
|
||||
|
||||
/**
|
||||
* <p>The number of significant binary bits in the subdivided space. There has to be
|
||||
* at least one bit, which represents the minimum divisible space. Each division
|
||||
* point which is active represents the address of a single vector from the
|
||||
* origin to the the unit circle at a position relative to the total space.
|
||||
* </p>
|
||||
*/
|
||||
private final int msb;
|
||||
/**
|
||||
* The index after the last actual ordinal in the set, or in other words, the end
|
||||
* of the {@code [closed,open)} interval of ordinals.
|
||||
*/
|
||||
private final int maxOrdinalExcluded;
|
||||
private final int mask;
|
||||
|
||||
public CircularPartitioner(int maxOrdinalExcluded) {
|
||||
this.maxOrdinalExcluded = maxOrdinalExcluded;
|
||||
this.msb = BitFields.getMsbPosition(maxOrdinalExcluded - 1);
|
||||
this.mask = (1<<msb) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the number of Return the value within the unit interval
|
||||
*
|
||||
* @param ordinal
|
||||
* @return
|
||||
*/
|
||||
public double unitIntervalOf(int ordinal) {
|
||||
return ((double) ordinal) / ((double) maxOrdinalExcluded);
|
||||
}
|
||||
|
||||
public int ordinalToOffset(int ordinal) {
|
||||
|
||||
int ordMsb = BitFields.getMsbPosition(ordinal);
|
||||
int phaseBits = ordMsb - 1;
|
||||
int phaseMask = ((1 << phaseBits) - 1) & mask;
|
||||
int floorShift = msb - ordMsb;
|
||||
int phaseFloor = (1 << floorShift) & mask;
|
||||
int phaseIndex = ordinal & phaseMask;
|
||||
|
||||
int phasePosition = phaseIndex << (msb-phaseBits);
|
||||
|
||||
int value = phaseFloor + phasePosition;
|
||||
return value;
|
||||
}
|
||||
|
||||
public int[] ordinalToFraction(int ordinal) {
|
||||
return new int[]{ordinalToOffset(ordinal), maxOrdinalExcluded};
|
||||
}
|
||||
|
||||
public double ordinalToUnitInterval(int ordinal) {
|
||||
int remapped = ordinalToOffset(ordinal);
|
||||
|
||||
return ((double) remapped) / (double) maxOrdinalExcluded;
|
||||
}
|
||||
|
||||
public double[] vecOnCircle(double unit) {
|
||||
double radians = 2.0d * Math.PI * unit;
|
||||
return new double[]{Math.cos(radians), Math.sin(radians)};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circular;
|
||||
|
||||
import io.nosqlbench.virtdata.lib.vectors.dnn.types.DNN_IntDoubleVectorSpace;
|
||||
|
||||
public class DNN_CircularSpace implements DNN_IntDoubleVectorSpace {
|
||||
|
||||
private final int dimensions;
|
||||
private final int count;
|
||||
|
||||
public DNN_CircularSpace(int dimensions, int count) {
|
||||
this.dimensions = dimensions;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] vectorOfOrdinal(int ordinal) {
|
||||
return new double[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int ordinalOfVector(double[] vector) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] neighborsOfOrdinal(int ordinal) {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 133 KiB |
After Width: | Height: | Size: 315 KiB |
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* <P>This package contains an implementation of
|
||||
* {@link io.nosqlbench.virtdata.lib.vectors.dnn.circular.CircularPartitioner},
|
||||
* a space-filling curve which maps ordinals onto 2-d vectors which fall on the unit circle
|
||||
* with increasing density. This allows vector values to get progressive closer together radially
|
||||
* as the arc intervals are divided in half at each level of resolution.</P>
|
||||
*
|
||||
*/
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circular;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.euclidean;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.euclidean;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.euclidean;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.euclidean;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* <P>This package contains experimental support for new methods for testing vector stores.
|
||||
* The primary method employed is functional mapping of ordinal spaces to vector spaces.
|
||||
* In this way, closed-form functions can be used to synthesize vectors and provably correct neighborhoods
|
||||
* as if they were defined in a static dataset. This allows for arbitrary testing scenarios to be
|
||||
* created and used immediately and with no need to regenerate or compute any data beforehand.</P>
|
||||
*
|
||||
* <P>The original concept for this was derived by Shaunak Das, in the form of (Das) Direct Nearest Neighbor.
|
||||
* Additional methods have been implemented using this technique to include additional space mappings
|
||||
* for other vector distance functions.</P>
|
||||
*
|
||||
* <P>The testing methods enabled by this approach include:
|
||||
* <OL>
|
||||
* <LI>Generation of a population of vectors which are enumerable and stable with respect to their
|
||||
* ordinal addresses.</LI>
|
||||
* <LI>Generation of ordered subsets of this population which maintain a unique local ordering in
|
||||
* terms of the selected distance function, otherwise known as rank for KNN queries.</LI>
|
||||
* <LI>Validation of results for nearest neighborhood queries, using synthetic results computed on the fly as the
|
||||
* basis for correctness.</LI>
|
||||
* </OL>
|
||||
* </P>
|
||||
*
|
||||
* <P>The vector spaces constructed in this way are not intended nor guaranteed to be dimensionally disperse.
|
||||
* They are meant to provide an algebraic basis for exercising vector storage systems with increasing
|
||||
* cardinality of vectors. This means that vector stores can be tested to incrementally higher limits
|
||||
* while their performance and accuracy are both measured.</P>
|
||||
*
|
||||
* <P>Each vector scheme in this method has the following properties:
|
||||
* <UL>
|
||||
* <LI>Each virtual vector space is defined by a set of parameters which are used as inputs to the
|
||||
* mapping functions. The space, and the definition of valid vectors in a neighborhood depend on these
|
||||
* for stability and correctness. Thus each space is explicitly defined by and inseparable from its parameters.</LI>
|
||||
* <LI>All vectors within the space are enumerable. Each increasing ordinal value describes a new and distinct
|
||||
* vector. The value of this vector is deterministic within the parameters of the space.</LI>
|
||||
* <LI>Each vector within a space is a valid query vector which implies a correct set of distance-ranked
|
||||
* neighbors up to some neighborhood size for the related distance function.</LI>
|
||||
* <LI>Nearest neighbors may have equal distance in some cases, for which ties are accommodated in testing
|
||||
* assertions. Suppose the distance from v<sub>10</sub> to v<sub>5</sub> is the same as the distance from
|
||||
* v<sub>10</sub> to v<sub>15</sub>, then both v<sub>5</sub> and v<sub>15</sub> should be interchangeable as
|
||||
* correct elements in any KNN results for query vector v<sub>10</sub>, provided that their distances are within
|
||||
* the top K results as otherwise expected.
|
||||
* </LI>
|
||||
* </UL>
|
||||
*
|
||||
* <P>TBD: Explain the above in terms of specific implementations and parameters.</P>
|
||||
* </P>
|
||||
*/
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.types;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms.CircleAlgorithm;
|
||||
import io.nosqlbench.virtdata.lib.vectors.algorithms.CircleAlgorithm;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.types;
|
||||
|
||||
/**
|
||||
* Implementations of this type represent the ordinals of vectors as integers,
|
||||
* and the component values as doubles.
|
||||
*/
|
||||
public interface DNN_IntDoubleVectorSpace {
|
||||
public double[] vectorOfOrdinal(int ordinal);
|
||||
public int ordinalOfVector(double[] vector);
|
||||
public int[] neighborsOfOrdinal(int ordinal);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.types;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public interface DNN_LongVectorSpace<ScalarType> {
|
||||
public ScalarType[] forOrdinal(long ordinal);
|
||||
public long ordinalFor(ScalarType[] vector);
|
||||
public long[] neighborsOfOrdinal(long centroid);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import java.util.function.LongToDoubleFunction;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
public class GoldenAngleDoubleVectors extends VectorSequence {
|
||||
private final static double goldenAngle = 137.5;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
public class UnitSteps extends DoubleSequence {
|
||||
public UnitSteps(long cardinality) {
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.util;
|
||||
|
||||
public class BitFields {
|
||||
|
||||
/**
|
||||
* Reduce the discrete magnitude of values by the same amount,
|
||||
* to allow any IEEE floating point values to remain closer to
|
||||
* the higher-precision part of the value space. This will reduce
|
||||
* rounding error for downstream operations which are based on
|
||||
* floating point casts of integer values.
|
||||
* @param values An array of integers
|
||||
* @return A scaled-down array of integers
|
||||
*/
|
||||
public static int[] alignReducedBits(int[] values) {
|
||||
int bits=32;
|
||||
for (int value : values) {
|
||||
bits=Math.min(bits,getLsbZeroBits(value));
|
||||
}
|
||||
int[] shifted = new int[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
shifted[i]=values[i]>>bits;
|
||||
}
|
||||
return shifted;
|
||||
}
|
||||
|
||||
private static final int[] zeros = {
|
||||
8, 0, 1, 0,
|
||||
2, 0, 1, 0,
|
||||
3, 0, 1, 0,
|
||||
2, 0, 1, 0
|
||||
};
|
||||
|
||||
/**
|
||||
* @return The number of lower-order bits which are zero in the value
|
||||
*/
|
||||
public static int getLsbZeroBits(int value) {
|
||||
int b = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((value & 0xF)>0) {
|
||||
b+=zeros[value&0xF];
|
||||
break;
|
||||
}
|
||||
b+=4;
|
||||
value>>=4;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The position of the most significant bit, with the lsb
|
||||
* represented as 1.
|
||||
*/
|
||||
public static int getMsbPosition(int value) {
|
||||
if (value < 0) {
|
||||
throw new RuntimeException("Only values between 1 and " + Integer.MAX_VALUE +
|
||||
" are supported, and you tried to get the MSB position for value " + value +
|
||||
" or possible overflowed to a negative value."
|
||||
);
|
||||
}
|
||||
int r = 0;
|
||||
if ((value & 0x00000000FFFF0000L) > 0) {
|
||||
r += 16;
|
||||
value >>= 16;
|
||||
}
|
||||
if ((value & 0x000000000000FF00L) > 0) {
|
||||
r += 8;
|
||||
value >>= 8;
|
||||
}
|
||||
if ((value & 0x00000000000000F0) > 0) {
|
||||
r += 4;
|
||||
value >>= 4;
|
||||
}
|
||||
return r + msbs[(int) value];
|
||||
}
|
||||
private static final int[] msbs = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
|
||||
|
||||
public static int reverseBits(int x) {
|
||||
return reverseBits2(x);
|
||||
}
|
||||
public static int reverseIntBitsUnsigned(int x) {
|
||||
return reverseBitsSave2(x);
|
||||
}
|
||||
|
||||
static int reverseBits1(int x, int bits) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < bits; i++) {
|
||||
result = (result << 1) | (x & 1);
|
||||
x >>= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int reverseBitsSave2(int v) {
|
||||
if (v>=0x4000_0000) {
|
||||
throw new RuntimeException("unsigned bit reversal must remain in lower 31 bits. input=" + v);
|
||||
}
|
||||
long x = (long)v;
|
||||
// Masks for bit swapping
|
||||
|
||||
x = ((x >>> 1) & MASK1) | ((x & MASK1) << 1);
|
||||
x = ((x >>> 2) & MASK2) | ((x & MASK2) << 2);
|
||||
x = ((x >>> 4) & MASK3) | ((x & MASK3) << 4);
|
||||
x = ((x >>> 8) & MASK4) | ((x & MASK4) << 8);
|
||||
int signed = (int) ((x >>> 16) | (x << 16));
|
||||
return signed>>>2;
|
||||
}
|
||||
final static int MASK1 = 0x55555555; // 0b01010101010101010101010101010101
|
||||
final static int MASK2 = 0x33333333; // 0b00110011001100110011001100110011
|
||||
final static int MASK3 = 0x0F0F0F0F; // 0b00001111000011110000111100001111
|
||||
final static int MASK4 = 0x00FF00FF; // 0b00000000111111110000000011111111
|
||||
static int reverseBits2(int x) {
|
||||
// Masks for bit swapping
|
||||
|
||||
x = ((x >>> 1) & MASK1) | ((x & MASK1) << 1);
|
||||
x = ((x >>> 2) & MASK2) | ((x & MASK2) << 2);
|
||||
x = ((x >>> 4) & MASK3) | ((x & MASK3) << 4);
|
||||
x = ((x >>> 8) & MASK4) | ((x & MASK4) << 8);
|
||||
return (x >>> 16) | (x << 16);
|
||||
}
|
||||
|
||||
static int reverseBits3(int x) {
|
||||
return (BIT_REVERSE_TABLE[x & 0xFF] << 24) |
|
||||
(BIT_REVERSE_TABLE[(x >>> 8) & 0xFF] << 16) |
|
||||
(BIT_REVERSE_TABLE[(x >>> 16) & 0xFF] << 8) |
|
||||
BIT_REVERSE_TABLE[(x >>> 24) & 0xFF];
|
||||
}
|
||||
private static final int[] BIT_REVERSE_TABLE = buildReverseTable(8); // For byte reversal
|
||||
private static int[] buildReverseTable(int bits) {
|
||||
int size = 1 << bits;
|
||||
int[] table = new int[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
table[i] = reverseBits1(i, bits);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment or decrement the initial bitfield value by some amount,
|
||||
* offset into higher 2^scale resolution.
|
||||
* @param initial The initial bitfield image
|
||||
* @param amount The value to add (positive or negative) to the initial value
|
||||
* @param shift The number of bits to shift left before, and right after the increment
|
||||
* @return The initial value incremented by the amount at some scale determined by shift
|
||||
*/
|
||||
public static int rotateBitspace(int initial, int amount, int shift) {
|
||||
return ((initial<<shift)+amount)>>shift;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.matheclipse.core.eval.ExprEvaluator;
|
||||
import org.matheclipse.core.expression.F;
|
||||
import org.matheclipse.core.interfaces.IExpr;
|
||||
import org.matheclipse.core.interfaces.ISymbol;
|
||||
import org.matheclipse.core.interfaces.IAST;
|
||||
|
||||
public class DNN_Symbolic_Tests {
|
||||
|
||||
@Test
|
||||
public void testExactRepresentation() {
|
||||
ExprEvaluator util = new ExprEvaluator(false, (short)10);
|
||||
|
||||
// Convert an expression to the internal Java form:
|
||||
// Note: single character identifiers are case sensitive
|
||||
// (the "D()" function identifier must be written as upper case
|
||||
// character)
|
||||
String javaForm = util.toJavaForm("D(sin(x)*cos(x),x)");
|
||||
// prints: D(Times(Sin(x),Cos(x)),x)
|
||||
System.out.println("Out[1]: " + javaForm.toString());
|
||||
|
||||
// Use the Java form to create an expression with F.* static
|
||||
// methods:
|
||||
ISymbol x = F.Dummy("x");
|
||||
IAST function = F.D(F.Times(F.Sin(x), F.Cos(x)), x);
|
||||
IExpr result = util.eval(function);
|
||||
// print: Cos(x)^2-Sin(x)^2
|
||||
System.out.println("Out[2]: " + result.toString());
|
||||
|
||||
// Note "diff" is an alias for the "D" function
|
||||
result = util.eval("diff(sin(x)*cos(x),x)");
|
||||
// print: Cos(x)^2-Sin(x)^2
|
||||
System.out.println("Out[3]: " + result.toString());
|
||||
|
||||
// evaluate the last result (% contains "last answer")
|
||||
result = util.eval("%+cos(x)^2");
|
||||
// print: 2*Cos(x)^2-Sin(x)^2
|
||||
System.out.println("Out[4]: " + result.toString());
|
||||
|
||||
// evaluate an Integrate[] expression
|
||||
result = util.eval("integrate(sin(x)^5,x)");
|
||||
// print: 2/3*Cos(x)^3-1/5*Cos(x)^5-Cos(x)
|
||||
System.out.println("Out[5]: " + result.toString());
|
||||
|
||||
// set the value of a variable "a" to 10
|
||||
result = util.eval("a=10");
|
||||
// print: 10
|
||||
System.out.println("Out[6]: " + result.toString());
|
||||
|
||||
// do a calculation with variable "a"
|
||||
result = util.eval("a*3+b");
|
||||
// print: 30+b
|
||||
System.out.println("Out[7]: " + result.toString());
|
||||
|
||||
// Do a calculation in "numeric mode" with the N() function
|
||||
// Note: single character identifiers are case sensistive
|
||||
// (the "N()" function identifier must be written as upper case
|
||||
// character)
|
||||
result = util.eval("N(sinh(5))");
|
||||
// print: 74.20321057778875
|
||||
System.out.println("Out[8]: " + result.toString());
|
||||
|
||||
// define a function with a recursive factorial function definition.
|
||||
// Note: fac(0) is the stop condition.
|
||||
result = util.eval("fac(x_Integer):=x*fac(x-1);fac(0)=1");
|
||||
// now calculate factorial of 10:
|
||||
result = util.eval("fac(10)");
|
||||
// print: 3628800
|
||||
System.out.println("Out[9]: " + result.toString());
|
||||
|
||||
function = F.Function(F.Divide(F.Gamma(F.Plus(F.C1, F.Slot1)), F.Gamma(F.Plus(F.C1, F.Slot2))));
|
||||
// eval function ( Gamma(1+#1)/Gamma(1+#2) ) & [23,20]
|
||||
result = util.evalFunction(function, "23", "20");
|
||||
// print: 10626
|
||||
System.out.println("Out[10]: " + result.toString());
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,12 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DNNAngular1VTest {
|
||||
@ -32,7 +30,7 @@ class DNNAngular1VTest {
|
||||
|
||||
@Test
|
||||
public void testSimpleGeneration() {
|
||||
DNN_angular1_v vs = new DNN_angular1_v(2, 100, 3);
|
||||
DnnAngular1V vs = new DnnAngular1V(2, 100, 3);
|
||||
assertThat(vs.apply(0)).isEqualTo(new float[]{1, 0});
|
||||
assertThat(vs.apply(1)).isEqualTo(new float[]{2, 2});
|
||||
assertThat(vs.apply(2)).isEqualTo(new float[]{3, 6});
|
||||
@ -45,7 +43,7 @@ class DNNAngular1VTest {
|
||||
@Test
|
||||
public void testBasicAngularVectors() {
|
||||
int M = 7;
|
||||
DNN_angular1_v vf = new DNN_angular1_v(10, 100, M);
|
||||
DnnAngular1V vf = new DnnAngular1V(10, 100, M);
|
||||
// populate 100 training cycles of DNN angular
|
||||
float[][] vectors = new float[100][];
|
||||
for (int i = 0; i < 100; i++) {
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public class DNN_angular_distance_decimal implements BiFunction<BigDecimal[],BigDecimal[],BigDecimal> {
|
||||
private final static MathContext mc = new MathContext(256, RoundingMode.HALF_EVEN);
|
||||
@Override
|
||||
public BigDecimal apply(BigDecimal[] v1, BigDecimal[] v2) {
|
||||
BigDecimal dot = dot(v1, v2);
|
||||
BigDecimal normv1 = norm(v1);
|
||||
BigDecimal normv2 = norm(v2);
|
||||
BigDecimal norm = normv1.multiply(normv2);
|
||||
BigDecimal cos_theta = dot.divide(norm,mc);
|
||||
return cos_theta;
|
||||
}
|
||||
|
||||
public static BigDecimal dot(BigDecimal[] vectorA, BigDecimal[] vectorB) {
|
||||
BigDecimal dotProduct = BigDecimal.ZERO;
|
||||
for (int i = 0; i < vectorA.length; i++) {
|
||||
BigDecimal product = vectorA[i].multiply(vectorB[i]);
|
||||
dotProduct = dotProduct.add(product);
|
||||
}
|
||||
return dotProduct;
|
||||
}
|
||||
|
||||
public static BigDecimal norm(BigDecimal[] v) {
|
||||
BigDecimal sum= BigDecimal.ZERO;
|
||||
for (BigDecimal dim : v) {
|
||||
sum=sum.add(dim.multiply(dim));
|
||||
}
|
||||
BigDecimal norm = sum.sqrt(mc);
|
||||
return norm;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DNN_angular_distance_decimalTest {
|
||||
|
||||
@Test
|
||||
public void testBigDecimalDotProduct() {
|
||||
DNN_angular_v_decimal v_dec = new DNN_angular_v_decimal(10, 100_000, 100);
|
||||
DnnAngular1V v_fp = new DnnAngular1V(10, 100_000, 100);
|
||||
|
||||
var v1d = v_dec.apply(90000);
|
||||
var v1f = v_fp.apply(90000);
|
||||
|
||||
System.out.println("v1d:"+ Arrays.toString(v1d));
|
||||
System.out.println("v1f:"+ Arrays.toString(v1f));
|
||||
|
||||
var v2d = v_dec.apply(90001);
|
||||
var v2f = v_fp.apply(90001);
|
||||
|
||||
System.out.println("v2d:"+ Arrays.toString(v2d));
|
||||
System.out.println("v2f:"+ Arrays.toString(v2f));
|
||||
|
||||
var v3d = v_dec.apply(90002);
|
||||
var v3f = v_fp.apply(90003);
|
||||
System.out.println("v3d:"+ Arrays.toString(v3d));
|
||||
System.out.println("v3f:"+ Arrays.toString(v3f));
|
||||
|
||||
DNN_angular_distance_decimal ddiffer = new DNN_angular_distance_decimal();
|
||||
DNN_angular_distance_float fdiffer = new DNN_angular_distance_float();
|
||||
|
||||
var diff_1_2 = ddiffer.apply(v1d,v2d);
|
||||
System.out.println("diff(1->2)" + diff_1_2);
|
||||
var fdiff_1_2 = fdiffer.apply(v1f,v2f);
|
||||
|
||||
var diff_1_3 = ddiffer.apply(v1d,v3d);
|
||||
System.out.println("diff(1->3)" + diff_1_3);
|
||||
|
||||
var diff_2_3 = ddiffer.apply(v2d,v3d);
|
||||
System.out.println("diff(2->3)" + diff_2_3);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigDecimalNorm() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class DNN_angular_distance_double implements BiFunction<double[],double[],Double> {
|
||||
private final static MathContext mc = new MathContext(256, RoundingMode.HALF_EVEN);
|
||||
@Override
|
||||
public Double apply(double[] v1, double[] v2) {
|
||||
double dot = dot(v1, v2);
|
||||
double normv1 = norm(v1);
|
||||
double normv2 = norm(v2);
|
||||
double norm = normv1*normv2;
|
||||
double cos_theta = dot/norm;
|
||||
return cos_theta;
|
||||
}
|
||||
|
||||
public static double dot(double[] vectorA, double[] vectorB) {
|
||||
double dotProduct = 0.0d;
|
||||
for (int i = 0; i < vectorA.length; i++) {
|
||||
double product = vectorA[i] * vectorB[i];
|
||||
dotProduct += product;
|
||||
}
|
||||
return dotProduct;
|
||||
}
|
||||
|
||||
public static double norm(double[] v) {
|
||||
double sum= 0.0d;
|
||||
for (double dim : v) {
|
||||
sum+=(dim*dim);
|
||||
}
|
||||
double norm = Math.sqrt(sum);
|
||||
return norm;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class DNN_angular_distance_float implements BiFunction<float[],float[],Float> {
|
||||
private final static MathContext mc = new MathContext(256, RoundingMode.HALF_EVEN);
|
||||
@Override
|
||||
public Float apply(float[] v1, float[] v2) {
|
||||
double dot = dot(v1, v2);
|
||||
double normv1 = norm(v1);
|
||||
double normv2 = norm(v2);
|
||||
double norm = normv1*normv2;
|
||||
double cos_theta = dot/norm;
|
||||
return (float)cos_theta;
|
||||
}
|
||||
|
||||
public static double dot(float[] vectorA, float[] vectorB) {
|
||||
double dotProduct = 0.0f;
|
||||
for (int i = 0; i < vectorA.length; i++) {
|
||||
double product = vectorA[i] * vectorB[i];
|
||||
dotProduct += product;
|
||||
}
|
||||
return dotProduct;
|
||||
}
|
||||
|
||||
public static double norm(float[] v) {
|
||||
float sum= 0.0f;
|
||||
for (float dim : v) {
|
||||
sum+=(dim*dim);
|
||||
}
|
||||
double norm = Math.sqrt(sum);
|
||||
return norm;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.angular;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public class DNN_angular_v_decimal implements LongFunction<BigDecimal[]> {
|
||||
private final int d;
|
||||
private final long n;
|
||||
private final long m;
|
||||
|
||||
public DNN_angular_v_decimal(int d, long n, long m) {
|
||||
this.d = d;
|
||||
this.n = n;
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal[] apply(long i) {
|
||||
BigDecimal[] vector = new BigDecimal[d];
|
||||
BigDecimal fillValue = BigDecimal.valueOf(i + 1);
|
||||
Arrays.fill(vector, fillValue);
|
||||
vector[vector.length - 1] = BigDecimal.valueOf(i).multiply(BigDecimal.valueOf(i%m));
|
||||
return vector;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circlefield;
|
||||
|
||||
import org.assertj.core.data.Offset;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CFVectorMapperTest {
|
||||
|
||||
private final static CFVectorSpace vs32 = new CFVectorSpace(32);
|
||||
private final static CFVectorMapper vm32 = new CFVectorMapper(vs32);
|
||||
|
||||
private final static CFVectorSpace vs16bits = new CFVectorSpace(65536);
|
||||
private final static CFVectorMapper vm16bits = new CFVectorMapper(vs16bits);
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicIndex() {
|
||||
CFVectorSpace vs32 = new CFVectorSpace(32);
|
||||
CFVectorMapper vm32 = new CFVectorMapper(vs32);
|
||||
|
||||
double[] v_1_0 = vm32.vectorForOrdinal(0);
|
||||
isCloseTo(v_1_0,new double[]{1.0d,0.0d},Offset.offset(0.000001d));
|
||||
|
||||
double[] v_n1_0 = vm32.vectorForOrdinal(1);
|
||||
isCloseTo(v_n1_0,new double[]{-1.0d,0.0d},Offset.offset(0.000001d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeighborhoods() {
|
||||
int[] neighbors = vm16bits.neighbors(0, 10);
|
||||
assertThat(neighbors).containsExactly(new int[]{32768});
|
||||
// TODO continue here
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void isCloseTo(double[] values, double[] expected, Offset<Double> offset) {
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
assertThat(values[i]).isCloseTo(expected[i],offset);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circular;
|
||||
|
||||
import io.nosqlbench.virtdata.lib.vectors.dnn.types.CircleVectors;
|
||||
import io.nosqlbench.virtdata.lib.vectors.algorithms.GoldenAngle;
|
||||
import io.nosqlbench.virtdata.lib.vectors.algorithms.LatLonBased;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CircleVectorsTest {
|
||||
@ -27,12 +28,12 @@ public class CircleVectorsTest {
|
||||
@Test
|
||||
public void testCircleVectors() {
|
||||
try {
|
||||
CircleVectors circleVectors = new CircleVectors(10,
|
||||
"io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms.GoldenAngle");
|
||||
CircleVectors circleVectors = new CircleVectors(10, GoldenAngle.class.getCanonicalName());
|
||||
|
||||
|
||||
assert (circleVectors.getCircleCount() == 10);
|
||||
assert (circleVectors.getAlgorithm() instanceof
|
||||
io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms.GoldenAngle);
|
||||
GoldenAngle);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -52,8 +53,7 @@ public class CircleVectorsTest {
|
||||
@Test
|
||||
public void testGoldenAngle() {
|
||||
try {
|
||||
CircleVectors circleVectors = new CircleVectors(10,
|
||||
"io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms.GoldenAngle");
|
||||
CircleVectors circleVectors = new CircleVectors(10, GoldenAngle.class.getCanonicalName());
|
||||
|
||||
List<Object> result = circleVectors.apply(1000);
|
||||
assert (result.size() == 3);
|
||||
@ -68,8 +68,7 @@ public class CircleVectorsTest {
|
||||
@Test
|
||||
public void testLatLonBased() {
|
||||
try {
|
||||
CircleVectors circleVectors = new CircleVectors(10,
|
||||
"io.nosqlbench.virtdata.library.basics.shared.vectors.algorithms.LatLonBased");
|
||||
CircleVectors circleVectors = new CircleVectors(10, LatLonBased.class.getCanonicalName());
|
||||
|
||||
List<Object> result = circleVectors.apply(1000);
|
||||
assert (result.size() == 3);
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.circular;
|
||||
|
||||
import io.nosqlbench.virtdata.lib.vectors.util.BitFields;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.Arrays;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CircularPartitionerTest {
|
||||
|
||||
@Test
|
||||
public void testMsbPositions() {
|
||||
assertThat(BitFields.getMsbPosition(1)).isEqualTo(1);
|
||||
assertThat(BitFields.getMsbPosition(2)).isEqualTo(2);
|
||||
assertThat(BitFields.getMsbPosition(7)).isEqualTo(3);
|
||||
assertThat(BitFields.getMsbPosition(8)).isEqualTo(4);
|
||||
assertThat(BitFields.getMsbPosition(Integer.MAX_VALUE)).isEqualTo(31);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertBoundaryErrors() {
|
||||
assertThat(BitFields.getMsbPosition(0)).isEqualTo(0);
|
||||
assertThrows(RuntimeException.class, () -> BitFields.getMsbPosition(-1));
|
||||
}
|
||||
|
||||
private int[] remap(CircularPartitioner cp, int[] inputs) {
|
||||
int[] outputs = new int[inputs.length];
|
||||
for (int i = 0; i < inputs.length; i++) {
|
||||
outputs[i]=cp.ordinalToOffset(inputs[i]);
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
// private double[][] ordinalsToVecs(CircularPartitioner cp, int[] ordinals) {
|
||||
// double[][] vecs = new double[ordinals.length][];
|
||||
// for (int i = 0; i < ordinals.length; i++) {
|
||||
// int intOffset = cp.ordinalToOffset(ordinals[i]);
|
||||
// double unitInterval = cp.unitIntervalOf(intOffset);
|
||||
// vecs[i]=cp.vecOnCircle(unitInterval);
|
||||
// }
|
||||
// return vecs;
|
||||
// }
|
||||
@Test
|
||||
public void assertOrdMapping() {
|
||||
CircularPartitioner cp16 = new CircularPartitioner(16);
|
||||
int[] ordinals = range(0,16);
|
||||
int[] remapped = remap(cp16,
|
||||
ordinals
|
||||
);
|
||||
assertThat(remapped).containsExactly(
|
||||
new int[]{0,8,4,12,2,6,10,14,1,3,5,7,9,11,13,15}
|
||||
);
|
||||
|
||||
double[] unitLens = this.intOffsetsToUnitLen(cp16, remapped);
|
||||
double[][] vecs = this.unitLensToVecs(cp16, unitLens);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < ordinals.length; i++) {
|
||||
sb.append("O:").append(i)
|
||||
.append(" R:").append(remapped[i])
|
||||
.append(" U:").append(String.format("%3.3f",unitLens[i]))
|
||||
.append(" v:").append(Arrays.toString(vecs[i])).append("\n");
|
||||
}
|
||||
System.out.println(sb);
|
||||
|
||||
}
|
||||
|
||||
private int[] range(int lowestIncluded, int highestExcluded) {
|
||||
int[] ints = new int[highestExcluded - lowestIncluded];
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
ints[i]=lowestIncluded+i;
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
private double[][] unitLensToVecs(CircularPartitioner cp16, double[] unitLens) {
|
||||
double[][] vecs = new double[unitLens.length][];
|
||||
for (int i = 0; i < unitLens.length; i++) {
|
||||
vecs[i]= cp16.vecOnCircle(unitLens[i]);
|
||||
}
|
||||
return vecs;
|
||||
}
|
||||
|
||||
private double[] intOffsetsToUnitLen(CircularPartitioner cp, int[] remapped) {
|
||||
double[] unitLens = new double[remapped.length];
|
||||
for (int i = 0; i < remapped.length; i++) {
|
||||
unitLens[i]=cp.unitIntervalOf(remapped[i]);
|
||||
}
|
||||
return unitLens;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrdinalFractions() {
|
||||
CircularPartitioner cp16 = new CircularPartitioner(16);
|
||||
int[] ordinals = range(0,16);
|
||||
int[][] fractions = new int[ordinals.length][];
|
||||
for (int i = 0; i <ordinals.length; i++) {
|
||||
int ord = ordinals[i];
|
||||
fractions[i]=cp16.ordinalToFraction(ord);
|
||||
}
|
||||
assertThat(fractions[0]).isEqualTo(new int[]{0,16});
|
||||
assertThat(fractions[7]).isEqualTo(new int[]{14,16});
|
||||
assertThat(fractions[15]).isEqualTo(new int[]{15,16});
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,10 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.euclidean;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DNNEuclideanNeighborsTest {
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
|
||||
package io.nosqlbench.virtdata.lib.vectors.dnn.euclidean;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
* Copyright (c) 2023-2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.vectors.primitive;
|
||||
package io.nosqlbench.virtdata.lib.vectors.primitive;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.util;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public class BitFieldsJMHTest {
|
||||
|
||||
@Param({"1"})
|
||||
public int inputs;
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.AverageTime})
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Threads(1)
|
||||
@Warmup(iterations=1, timeUnit= TimeUnit.SECONDS,time=10)
|
||||
@Measurement(iterations=1,timeUnit=TimeUnit.SECONDS,time=10)
|
||||
public void reverseBits1() {
|
||||
inputs*=37;
|
||||
BitFields.reverseBits1(inputs,32);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.AverageTime})
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Threads(1)
|
||||
@Warmup(iterations=1, timeUnit= TimeUnit.SECONDS,time=10)
|
||||
@Measurement(iterations=1,timeUnit=TimeUnit.SECONDS,time=10)
|
||||
public void reverseBits2() {
|
||||
inputs*=37;
|
||||
BitFields.reverseBits2(inputs);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.AverageTime})
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Threads(1)
|
||||
@Warmup(iterations=1, timeUnit= TimeUnit.SECONDS,time=10)
|
||||
@Measurement(iterations=1,timeUnit=TimeUnit.SECONDS,time=10)
|
||||
public void reverseBits3() {
|
||||
inputs*=37;
|
||||
BitFields.reverseBits3(inputs);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.virtdata.lib.vectors.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class BitFieldsTest {
|
||||
|
||||
@Test
|
||||
public void testZeros() {
|
||||
assertThat(BitFields.getLsbZeroBits(0)).isEqualTo(32);
|
||||
assertThat(BitFields.getLsbZeroBits(1)).isEqualTo(0);
|
||||
assertThat(BitFields.getLsbZeroBits(2)).isEqualTo(1);
|
||||
assertThat(BitFields.getLsbZeroBits(6)).isEqualTo(1);
|
||||
assertThat(BitFields.getLsbZeroBits(16)).isEqualTo(4);
|
||||
assertThat(BitFields.getLsbZeroBits(32)).isEqualTo(5);
|
||||
assertThat(BitFields.getLsbZeroBits(128)).isEqualTo(7);
|
||||
assertThat(BitFields.getLsbZeroBits(512)).isEqualTo(9);
|
||||
assertThat(BitFields.getLsbZeroBits(2049)).isEqualTo(0);
|
||||
assertThat(BitFields.getLsbZeroBits(8192)).isEqualTo(13);
|
||||
assertThat(BitFields.getLsbZeroBits(16384)).isEqualTo(14);
|
||||
assertThat(BitFields.getLsbZeroBits(4_000_000)).isEqualTo(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAligned() {
|
||||
assertThat(BitFields.alignReducedBits(new int[]{0,0})).isEqualTo(new int[]{0,0});
|
||||
assertThat(BitFields.alignReducedBits(new int[]{8,16})).isEqualTo(new int[]{1,2});
|
||||
assertThat(BitFields.alignReducedBits(new int[]{8,15})).isEqualTo(new int[]{8,15});
|
||||
assertThat(BitFields.alignReducedBits(new int[]{32768,16384})).isEqualTo(new int[]{2,1});
|
||||
assertThat(BitFields.alignReducedBits(new int[]{0,15})).isEqualTo(new int[]{0,15});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -73,6 +73,12 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>virtdata-lib-vectors</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>docsys</artifactId>
|
||||
|