public KdTree(ModelLoadContext ctx) { bool hasSeed = ctx.Reader.ReadByte() == 1; if (hasSeed) { var seed = ctx.Reader.ReadInt32(); _rnd = new Random(seed); _seed = seed; } else { _rnd = new Random(); _seed = null; } dimension = ctx.Reader.ReadInt32(); int i = ctx.Reader.ReadInt32(); _distance = (NearestNeighborsDistance)i; root = ReadNode(ctx); byte b = ctx.Reader.ReadByte(); if (b != 168) { throw Contracts.Except("Detected inconsistency in deserializing."); } SetDistanceFunction(); }
public KdTree(IEnumerable <IPointIdFloat> points, int dimension = -1, int?seed = null, NearestNeighborsDistance distance = NearestNeighborsDistance.L2) { _seed = seed; _rnd = seed.HasValue ? new Random(seed.Value) : new Random(); _distance = distance; this.dimension = dimension; if (points.Any()) { ValidatePointsArray(points); root = CreateTree(points.ToList(), _rnd); } else { root = null; } SetDistanceFunction(); }
public virtual void Read(ModelLoadContext ctx, IHost host) { k = ctx.Reader.ReadInt32(); algo = (NearestNeighborsAlgorithm)ctx.Reader.ReadInt32(); weighting = (NearestNeighborsWeights)ctx.Reader.ReadInt32(); distance = (NearestNeighborsDistance)ctx.Reader.ReadInt32(); numThreads = ctx.Reader.ReadInt32(); if (numThreads == -1) { numThreads = null; } seed = ctx.Reader.ReadInt32(); if (seed == -1) { seed = null; } colId = ctx.Reader.ReadString(); if (string.IsNullOrEmpty(colId)) { colId = null; } }
public KdTree(NearestNeighborsDistance distance, int?seed, params IPointIdFloat[] points) : this(points.ToList(), distance : distance, seed : seed) { }