Skip to content

Commit

Permalink
update msgpack, move enum to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
theolivenbaum committed Sep 18, 2020
1 parent 5953003 commit 86c2f64
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
7 changes: 2 additions & 5 deletions Src/HNSW.Net.Demo/HNSW.Net.Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<ApplicationIcon />
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<StartupObject />
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Src/HNSW.Net.Demo/MetricsEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
return;
}

Console.WriteLine($"[{counterData["Name"]}]: Avg={counterData["Mean"]}; SD={counterData["StandardDeviation"]}; Count={counterData["Count"]}");
Console.WriteLine($"[{counterData["Name"]:n1}]: Avg={counterData["Mean"]:n1}; SD={counterData["StandardDeviation"]:n1}; Count={counterData["Count"]}");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Src/HNSW.Net.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace HNSW.Net.Demo

public static partial class Program
{
private const int SampleSize = 5_000;
private const int SampleIncrSize = 1_000;
private const int SampleSize = 5_00;
private const int SampleIncrSize = 1_00;
private const int TestSize = 10 * SampleSize;
private const int Dimensionality = 128;
private const string VectorsPathSuffix = "vectors.hnsw";
Expand All @@ -34,7 +34,7 @@ public static void Main()

private static void BuildAndSave(string pathPrefix)
{
var world = new SmallWorld<float[], float>(CosineDistance.SIMDForUnits, DefaultRandomGenerator.Instance, new Parameters() { EnableDistanceCacheForConstruction = true, InitialDistanceCacheSize = SampleSize, NeighbourHeuristic = SmallWorld<float[], float>.NeighbourSelectionHeuristic.SelectHeuristic, KeepPrunedConnections = true, ExpandBestSelection = true});
var world = new SmallWorld<float[], float>(CosineDistance.SIMDForUnits, DefaultRandomGenerator.Instance, new Parameters() { EnableDistanceCacheForConstruction = true, InitialDistanceCacheSize = SampleSize, NeighbourHeuristic = NeighbourSelectionHeuristic.SelectHeuristic, KeepPrunedConnections = true, ExpandBestSelection = true});

Console.Write($"Generating {SampleSize} sample vectos... ");
var clock = Stopwatch.StartNew();
Expand Down
2 changes: 1 addition & 1 deletion Src/HNSW.Net.Tests/SmallWorldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void KNNSearchTest()
[DataRow(true, true)]
public void KNNSearchTestAlgorithm4(bool expandBestSelection, bool keepPrunedConnections )
{
var parameters = new SmallWorld<float[], float>.Parameters() { NeighbourHeuristic = SmallWorld<float[], float>.NeighbourSelectionHeuristic.SelectHeuristic, ExpandBestSelection = expandBestSelection, KeepPrunedConnections = keepPrunedConnections };
var parameters = new SmallWorld<float[], float>.Parameters() { NeighbourHeuristic = NeighbourSelectionHeuristic.SelectHeuristic, ExpandBestSelection = expandBestSelection, KeepPrunedConnections = keepPrunedConnections };
var graph = new SmallWorld<float[], float>(CosineDistance.NonOptimized, DefaultRandomGenerator.Instance, parameters);
graph.AddItems(vectors);

Expand Down
4 changes: 2 additions & 2 deletions Src/HNSW.Net/Graph.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ internal Core(Func<TItem, TItem, TDistance> distance, SmallWorld<TItem, TDistanc

switch (Parameters.NeighbourHeuristic)
{
case SmallWorld<TItem, TDistance>.NeighbourSelectionHeuristic.SelectSimple:
case NeighbourSelectionHeuristic.SelectSimple:
{
Algorithm = new Algorithms.Algorithm3<TItem, TDistance>(this);
break;
}
case SmallWorld<TItem, TDistance>.NeighbourSelectionHeuristic.SelectHeuristic:
case NeighbourSelectionHeuristic.SelectHeuristic:
{
Algorithm = new Algorithms.Algorithm4<TItem, TDistance>(this);
break;
Expand Down
4 changes: 2 additions & 2 deletions Src/HNSW.Net/HNSW.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Fork from original at https://github.com/microsoft/HNSW.Net, adds support for in


<ItemGroup>
<PackageReference Include="MessagePack" Version="2.0.270-rc" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="MessagePack" Version="2.2.44-rc" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
</Project>
14 changes: 0 additions & 14 deletions Src/HNSW.Net/SmallWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,7 @@ public SmallWorld(Func<TItem, TItem, TDistance> distance, IProvideRandomValues g
Generator = generator;
}

/// <summary>
/// Type of heuristic to select best neighbours for a node.
/// </summary>
public enum NeighbourSelectionHeuristic
{
/// <summary>
/// Marker for the Algorithm 3 (SELECT-NEIGHBORS-SIMPLE) from the article. Implemented in <see cref="Algorithms.Algorithm3{TItem, TDistance}"/>
/// </summary>
SelectSimple,

/// <summary>
/// Marker for the Algorithm 4 (SELECT-NEIGHBORS-HEURISTIC) from the article. Implemented in <see cref="Algorithms.Algorithm4{TItem, TDistance}"/>
/// </summary>
SelectHeuristic
}

/// <summary>
/// Builds hnsw graph from the items.
Expand Down
23 changes: 23 additions & 0 deletions src/HNSW.Net/NeighbourSelectionHeuristic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <copyright file="SmallWorld.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// </copyright>

namespace HNSW.Net
{
/// <summary>
/// Type of heuristic to select best neighbours for a node.
/// </summary>
public enum NeighbourSelectionHeuristic
{
/// <summary>
/// Marker for the Algorithm 3 (SELECT-NEIGHBORS-SIMPLE) from the article. Implemented in <see cref="Algorithms.Algorithm3{TItem, TDistance}"/>
/// </summary>
SelectSimple,

/// <summary>
/// Marker for the Algorithm 4 (SELECT-NEIGHBORS-HEURISTIC) from the article. Implemented in <see cref="Algorithms.Algorithm4{TItem, TDistance}"/>
/// </summary>
SelectHeuristic
}
}

0 comments on commit 86c2f64

Please sign in to comment.