unique items in search result
pull/1/head
unknown 3 years ago
parent b55ae7d814
commit 9f083d049f

@ -9,8 +9,6 @@ namespace HNSWDemo
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
new LALTest().Run(); new LALTest().Run();
// new AutoClusteringMNISTTest().Run(); // new AutoClusteringMNISTTest().Run();
// new AccuracityTest().Run(); // new AccuracityTest().Run();

@ -10,8 +10,7 @@ namespace HNSWDemo.Tests
internal class LALTest internal class LALTest
: ITest : ITest
{ {
private const int count = 5000; private const int count = 20000;
private const int testCount = 100;
private const int dimensionality = 128; private const int dimensionality = 128;
public void Run() public void Run()
@ -83,19 +82,24 @@ namespace HNSWDemo.Tests
} }
var contexts = mappers.CreateContext(null, entries); var contexts = mappers.CreateContext(null, entries);
var result = worlds.KNearest(10, contexts); var result = worlds.KNearest(5000, contexts);
Console.WriteLine("Entries:"); Console.WriteLine($"Found: {result.Sum(r=>r.Value.Count)}");
/*Console.WriteLine("Entries:");
foreach (var n in entries) foreach (var n in entries)
{ {
Console.WriteLine($"\t{n}"); Console.WriteLine($"\t{n}");
} }
Console.WriteLine("Extensions:"); Console.WriteLine("Extensions:");
foreach (var n in mappers.ConvertIdsToFeatures(result)) foreach (var r in result)
{
foreach (var n in mappers.ConvertIdsToFeatures(r.Key, r.Value))
{ {
Console.WriteLine($"\t[{n}]"); Console.WriteLine($"\t[{n}]");
} }
}*/
} }
} }
} }

@ -17,16 +17,13 @@ namespace ZeroLevel.HNSW
_mappers.Add(c, map); _mappers.Add(c, map);
} }
public IEnumerable<TFeature> ConvertIdsToFeatures(IEnumerable<int> ids) public IEnumerable<TFeature> ConvertIdsToFeatures(int c, IEnumerable<int> ids)
{ {
foreach (var map in _mappers) foreach (var feature in _mappers[c].ConvertIdsToFeatures(ids))
{
foreach (var feature in map.Value.ConvertIdsToFeatures(ids))
{ {
yield return feature; yield return feature;
} }
} }
}
public IDictionary<int, SearchContext> CreateContext(IEnumerable<TFeature> activeNodes, IEnumerable<TFeature> entryPoints) public IDictionary<int, SearchContext> CreateContext(IEnumerable<TFeature> activeNodes, IEnumerable<TFeature> entryPoints)
{ {

@ -28,7 +28,7 @@ namespace ZeroLevel.HNSW
{ {
var v = new VisitedBitSet(_links.Count, 1); var v = new VisitedBitSet(_links.Count, 1);
var C = new Queue<int>(); var C = new Queue<int>();
var W = new List<int>(); var W = new HashSet<int>();
var entryPoints = context.EntryPoints; var entryPoints = context.EntryPoints;
do do
@ -55,7 +55,7 @@ namespace ZeroLevel.HNSW
if (W.Count > k) if (W.Count > k)
{ {
var loser_id = DefaultRandomGenerator.Instance.Next(0, W.Count - 1); var loser_id = DefaultRandomGenerator.Instance.Next(0, W.Count - 1);
W.RemoveAt(loser_id); W.Remove(W.First());
} }
} }
} }

@ -11,16 +11,17 @@ namespace ZeroLevel.HNSW
_graphs.Add(c, graph); _graphs.Add(c, graph);
} }
public IEnumerable<int> KNearest(int k, IDictionary<int, SearchContext> contexts) public IDictionary<int, List<int>> KNearest(int k, IDictionary<int, SearchContext> contexts)
{ {
var partial_k = 1 + (k / _graphs.Count); var partial_k = 1 + (k / _graphs.Count);
var result = new List<int>(); var result = new Dictionary<int, List<int>>();
foreach (var graph in _graphs) foreach (var graph in _graphs)
{ {
result.Add(graph.Key, new List<int>());
var context = contexts[graph.Key]; var context = contexts[graph.Key];
if (context.EntryPoints != null) if (context.EntryPoints != null)
{ {
result.AddRange(graph.Value.KNearest(partial_k, context)); result[graph.Key].AddRange(graph.Value.KNearest(partial_k, context));
} }
} }
return result; return result;

@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Version>1.0.0.1</Version> <Version>1.0.0.3</Version>
<Company>ogoun</Company> <Company>ogoun</Company>
<Authors>Ogoun</Authors> <Authors>Ogoun</Authors>
<Copyright>Copyright Ogoun 2022</Copyright> <Copyright>Copyright Ogoun 2022</Copyright>
@ -13,6 +13,7 @@
<PackageIcon>zero.png</PackageIcon> <PackageIcon>zero.png</PackageIcon>
<RepositoryUrl>https://github.com/ogoun/Zero</RepositoryUrl> <RepositoryUrl>https://github.com/ogoun/Zero</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<PackageReleaseNotes>Fix search output.</PackageReleaseNotes>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

Loading…
Cancel
Save

Powered by TurnKey Linux.