Example #1
0
                public bool Update(IReadOnlyList <IVector> data)
                {
                    // check if the cluster has been updated
                    if (data.Count == _data.Count)
                    {
                        var isChanged = false;
                        var existing  = new HashSet <IVector>(_data);
                        foreach (var item in data)
                        {
                            if (!existing.Contains(item))
                            {
                                isChanged = true;
                                break;
                            }
                        }
                        if (!isChanged)
                        {
                            return(false);
                        }
                    }

                    Current.Dispose();
                    Current = null;
                    _data.Clear();
                    var denominator = 1f / data.Count;

                    var isFirst = true;

                    foreach (var item in data)
                    {
                        if (Current == null)
                        {
                            Current = item.Clone();
                        }
                        else
                        {
                            Current.AddInPlace(item, isFirst ? denominator : 1, denominator);
                            isFirst = false;
                        }
                        _data.Add(item);
                    }
                    return(true);
                }