partial work on DNN-Circular (not ready for merge to main)

This commit is contained in:
Jonathan Shook 2024-02-05 15:39:36 -06:00
parent 663a3e08ea
commit caaed7f884
30 changed files with 7145 additions and 81 deletions

View File

@ -330,7 +330,7 @@
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.5.1.Final</version>
<version>2.5.2.Final</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>

View File

@ -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>

View File

@ -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.library.basics.shared.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)
*/

View File

@ -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.library.basics.shared.vectors.dnn.angular;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;

View File

@ -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-&gt;(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

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 312 KiB

View File

@ -0,0 +1,141 @@
/*
* 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.library.basics.shared.vectors.dnn.circular;
/**
* <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 = 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 = 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)};
}
private static final int[] msbs = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
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];
}
}

View File

@ -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.library.basics.shared.vectors.dnn.circular;
import io.nosqlbench.virtdata.library.basics.shared.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];
}
}

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 133 KiB

View File

@ -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.library.basics.shared.vectors.dnn.euclidean;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;

View File

@ -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.library.basics.shared.vectors.dnn.euclidean;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;

View File

@ -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.library.basics.shared.vectors.dnn.euclidean;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;

View File

@ -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.library.basics.shared.vectors.dnn.euclidean;
import io.nosqlbench.virtdata.api.annotations.Categories;
import io.nosqlbench.virtdata.api.annotations.Category;

View File

@ -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.library.basics.shared.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);
}

View File

@ -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.library.basics.shared.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);
}

View File

@ -16,6 +16,7 @@
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.angular.DNN_angular1_neighbors;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -16,10 +16,9 @@
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.angular.DNN_angular1_v;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
class DNNAngular1VTest {

View File

@ -16,6 +16,7 @@
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.euclidean.DNN_euclidean_neighbors;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -16,6 +16,9 @@
package io.nosqlbench.virtdata.library.basics.shared.vectors.dnn;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.euclidean.DNN_euclidean_v;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.euclidean.DNN_euclidean_v_series;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.euclidean.DNN_euclidean_v_wrap;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -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.library.basics.shared.vectors.dnn;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.angular.DNN_angular1_neighbors;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.angular.DNN_angular1_v;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
class DNN_Macro_Tests {
@Test
public void loopBackPrecisionTest() {
DNN_angular1_neighbors dnnan = new DNN_angular1_neighbors(3, 1_000_000, 7);
int[] indices = dnnan.apply(500);
System.out.println("neighbor indices:\n"+Arrays.toString(indices));
DNN_angular1_v dnnav = new DNN_angular1_v(10,1_000_000,7);
for (int index : indices) {
float[] v = dnnav.apply(index);
System.out.println("n["+index+"]: " + Arrays.toString(v));
}
}
}

View File

@ -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.library.basics.shared.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());
}
}

View File

@ -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.library.basics.shared.vectors.dnn;
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;
}
}

View File

@ -0,0 +1,69 @@
/*
* 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.library.basics.shared.vectors.dnn;
import io.nosqlbench.virtdata.library.basics.shared.vectors.dnn.angular.DNN_angular1_v;
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);
DNN_angular1_v v_fp = new DNN_angular1_v(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() {
}
}

View File

@ -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.library.basics.shared.vectors.dnn;
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;
}
}

View File

@ -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.library.basics.shared.vectors.dnn;
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;
}
}

View File

@ -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.library.basics.shared.vectors.dnn;
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;
}
}

View File

@ -0,0 +1,124 @@
/*
* 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.library.basics.shared.vectors.dnn.circular;
import org.apfloat.Apfloat;
import org.apfloat.ApfloatMath;
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(CircularPartitioner.getMsbPosition(1)).isEqualTo(1);
assertThat(CircularPartitioner.getMsbPosition(2)).isEqualTo(2);
assertThat(CircularPartitioner.getMsbPosition(7)).isEqualTo(3);
assertThat(CircularPartitioner.getMsbPosition(8)).isEqualTo(4);
assertThat(CircularPartitioner.getMsbPosition(Integer.MAX_VALUE)).isEqualTo(31);
}
@Test
public void assertBoundaryErrors() {
assertThat(CircularPartitioner.getMsbPosition(0)).isEqualTo(0);
assertThrows(RuntimeException.class, () -> CircularPartitioner.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,15);
int[] remapped = remap(cp16,
ordinals
);
assertThat(remapped).containsExactly(
new int[]{16,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 lowIncl, int highExcl) {
int[] ints = new int[highExcl - lowIncl];
for (int i = 0; i < ints.length; i++) {
ints[i]=lowIncl+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,15);
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[]{0,16});
assertThat(fractions[15]).isEqualTo(new int[]{0,16});
}
}

View File

@ -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>