Update SmallWorld.cs

pull/1/head
unknown 3 years ago
parent 0cef043b26
commit 2ad948688c

@ -298,24 +298,10 @@ namespace ZeroLevel.HNSW
return Enumerable.Empty<(int, float)>();
}
var distance = new Func<int, int, float>((id1, id2) => _options.Distance(_vectors[id1], _vectors[id2]));
// W ← ∅ // set for the current nearest elements
var W = new Dictionary<int, float>(k + 1);
// ep ← get enter point for hnsw
var ep = EntryPoint;
// L ← level of ep // top layer for hnsw
var L = MaxLayer;
// for lc ← L … 1
for (int layer = L; layer > 0; --layer)
{
// W ← SEARCH-LAYER(q, ep, ef = 1, lc)
_layers[layer].KNearestAtLayer(ep, W, 1, context);
// ep ← get nearest element from W to q
ep = W.OrderBy(p => p.Value).First().Key;
W.Clear();
}
// W ← SEARCH-LAYER(q, ep, ef, lc =0)
_layers[0].KNearestAtLayer(ep, W, k, context);
_layers[0].KNearestAtLayer(W, k, context);
// return K nearest elements from W to q
return W.Select(p => (p.Key, p.Value));
}

Loading…
Cancel
Save

Powered by TurnKey Linux.