public float[] Transform( IVectorPack <float> x, IList <float> weights, bool normalize, float[] result, CancellationToken cancellationToken) { if (result == null) { result = new float[this.K]; } if (weights == null) { for (int i = 0, ii = x.Count, len = x.Length, off = 0; i < ii; i++, off += len) { int cluster = this.Assign(new DenseVectorProxyF(len, x.X, off)); result[cluster] += 1.0f; } } else { if (weights.Count != x.Count) { throw new ArgumentException("The number of weights must match the number of input vectors.", nameof(weights)); } for (int i = 0, ii = x.Count, len = x.Length, off = 0; i < ii; i++, off += len) { int cluster = this.Assign(new DenseVectorProxyF(len, x.X, off)); result[cluster] += weights[i]; } } if (normalize) { float sum = Vectors.Sum(result.Length, result, 0); if (sum != 0.0f) { Mathematics.DivC(result.Length, sum, result, 0); } } return(result); }
private static float[] PrepareVector(KMeans kmeans, IVectorPack <float> x, CancellationToken cancellationToken) { return(kmeans.Transform(x, null, false, null, cancellationToken)); }