diff --git a/TestHNSW/HNSWDemo/Program.cs b/TestHNSW/HNSWDemo/Program.cs index 10a62bf..2d946e5 100644 --- a/TestHNSW/HNSWDemo/Program.cs +++ b/TestHNSW/HNSWDemo/Program.cs @@ -98,7 +98,7 @@ namespace HNSWDemo static void Main(string[] args) { - AccuracityTest(); + TransformToCompactWorldTestWithAccuracity(); Console.ReadKey(); } @@ -423,7 +423,7 @@ namespace HNSWDemo var sw = new Stopwatch(); var test = new VectorsDirectCompare(samples, CosineDistance.ForUnits); - var world = new SmallWorld(NSWOptions.Create(32, 15, 200, 200, CosineDistance.ForUnits, true, true, selectionHeuristic: NeighbourSelectionHeuristic.SelectSimple)); + var world = new SmallWorld(NSWOptions.Create(8, 15, 200, 200, CosineDistance.ForUnits, true, true, selectionHeuristic: NeighbourSelectionHeuristic.SelectSimple)); sw.Start(); var ids = world.AddItems(samples.ToArray()); diff --git a/ZeroLevel.HNSW/Utils/ProbabilityLayerNumberGenerator.cs b/ZeroLevel.HNSW/Utils/ProbabilityLayerNumberGenerator.cs index 2af5225..f37b664 100644 --- a/ZeroLevel.HNSW/Utils/ProbabilityLayerNumberGenerator.cs +++ b/ZeroLevel.HNSW/Utils/ProbabilityLayerNumberGenerator.cs @@ -4,19 +4,16 @@ namespace ZeroLevel.HNSW.Services { internal sealed class ProbabilityLayerNumberGenerator { - private const float DIVIDER = 3.361f; private readonly float[] _probabilities; - private float _mL; internal ProbabilityLayerNumberGenerator(int maxLayers, int M) { _mL = maxLayers; _probabilities = new float[maxLayers]; - var probability = 1.0f / DIVIDER; + var m_L = 1.0f / Math.Log(M); for (int i = 0; i < maxLayers; i++) { - _probabilities[i] = probability; - probability /= DIVIDER; + _probabilities[i] = (float)(Math.Exp(-i / m_L) * (1 - Math.Exp(-1 / m_L))); } }