You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel.ML/Clusterization/FeatureClusterBulder.cs

34 lines
1.1 KiB

using System;
using System.Collections.Generic;
namespace ZeroLevel.ML
{
public class FeatureClusterBulder
{
public FeatureClusterCollection<T> Build<T>(IEnumerable<T> items, Func<T, float[]> vectorExtractor, Func<float[], float[], double> similarityFunction, float threshold)
{
var collection = new FeatureClusterCollection<T>();
foreach (var item in items)
{
bool isAdded = false;
foreach (var cluster in collection.Clusters)
{
if (cluster.Value.IsNeighbor(item, similarityFunction, threshold))
{
cluster.Value.Append(item);
isAdded = true;
break;
}
}
if (false == isAdded)
{
var cluster = new FeatureCluster<T>(vectorExtractor);
cluster.Append(item);
collection.Add(cluster);
}
}
return collection;
}
}
}

Powered by TurnKey Linux.