Fix partial lal graph

pull/1/head
unknown 3 years ago
parent 9f083d049f
commit 8fab18b0f6

@ -30,15 +30,19 @@ namespace ZeroLevel.HNSW
var C = new Queue<int>(); var C = new Queue<int>();
var W = new HashSet<int>(); var W = new HashSet<int>();
var entryPoints = context.EntryPoints; var entryPoints = context.EntryPoints;
var nextEntry = new HashSet<int>();
do do
{ {
foreach (var ep in entryPoints) foreach (var ep in entryPoints)
{ {
var neighboursIds = _links.FindNeighbors(ep); var neighboursIds = _links.FindNeighbors(ep);
for (int i = 0; i < neighboursIds.Length; ++i) for (int i = 0; i < neighboursIds.Length; ++i)
{
if (v.Contains(neighboursIds[i]) == false)
{ {
C.Enqueue(neighboursIds[i]); C.Enqueue(neighboursIds[i]);
nextEntry.Add(neighboursIds[i]);
}
} }
v.Add(ep); v.Add(ep);
} }
@ -54,13 +58,13 @@ namespace ZeroLevel.HNSW
W.Add(toExpand); W.Add(toExpand);
if (W.Count > k) if (W.Count > k)
{ {
var loser_id = DefaultRandomGenerator.Instance.Next(0, W.Count - 1);
W.Remove(W.First()); W.Remove(W.First());
} }
} }
} }
} }
entryPoints = W.Select(id => id).ToList(); entryPoints = nextEntry.Select(id => id).ToList();
nextEntry.Clear();
} }
while (W.Count < k && entryPoints.Any()); while (W.Count < k && entryPoints.Any());
C.Clear(); C.Clear();

@ -15,14 +15,22 @@ namespace ZeroLevel.HNSW
{ {
var partial_k = 1 + (k / _graphs.Count); var partial_k = 1 + (k / _graphs.Count);
var result = new Dictionary<int, List<int>>(); var result = new Dictionary<int, List<int>>();
int step = 1;
foreach (var graph in _graphs) foreach (var graph in _graphs)
{ {
result.Add(graph.Key, new List<int>()); 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[graph.Key].AddRange(graph.Value.KNearest(partial_k, context)); var r = graph.Value.KNearest(partial_k, context) as HashSet<int>;
if (r.Count < partial_k)
{
var diff = partial_k - r.Count;
partial_k += diff / (_graphs.Count - step);
}
result[graph.Key].AddRange(r);
} }
step++;
} }
return result; return result;
} }

@ -59,6 +59,15 @@ namespace ZeroLevel.Services
return tdict; return tdict;
} }
public static bool HasCyrillicSymbols(string line)
{
foreach (var ch in line)
{
if(gost.ContainsKey(ch.ToString()) || iso.ContainsKey(ch.ToString())) return true;
}
return false;
}
static Transliteration() static Transliteration()
{ {
gost.Add("Є", "EH"); gost.Add("Є", "EH");

Loading…
Cancel
Save

Powered by TurnKey Linux.