Ejemplo n.º 1
0
        void ComputeNearestNeighbors()
        {
            lock (_lock)
            {
                if (_trees != null)
                {
                    return;
                }

                using (var ch = _host.Start("Build k-d tree"))
                {
                    ch.Info("ComputeNearestNeighbors: build a k-d tree.");
                    int featureIndex, labelIndex, idIndex, weightIndex;
                    if (!_input.Schema.TryGetColumnIndex(_args.column, out featureIndex))
                    {
                        throw ch.Except("Unable to find column '{0}'.", _args.column);
                    }
                    labelIndex  = GetColumnIndex(ch, _args.labelColumn);
                    weightIndex = GetColumnIndex(ch, _args.weightColumn);
                    idIndex     = GetColumnIndex(ch, _args.colId);

                    Dictionary <long, Tuple <long, float> > merged;
                    _trees = NearestNeighborsBuilder.NearestNeighborsBuild <long>(ch, _input, featureIndex, labelIndex,
                                                                                  idIndex, weightIndex, out merged, _args);
                    ch.Info("Done. Tree size: {0} points.", _trees.Count());
                }
            }
        }
Ejemplo n.º 2
0
        void ComputeNearestNeighbors()
        {
            lock (_lock)
            {
                if (_trees != null)
                {
                    return;
                }

                using (var ch = _host.Start("Build k-d tree"))
                {
                    ch.Info(MessageSensitivity.None, "ComputeNearestNeighbors: build a k-d tree.");
                    int featureIndex, labelIndex, idIndex, weightIndex;
                    featureIndex = GetColumnIndex(ch, _args.column);
                    if (featureIndex == -1)
                    {
                        throw ch.Except($"Unable to find column '{_args.column}' in {SchemaHelper.ToString(Schema)}.");
                    }
                    labelIndex  = GetColumnIndex(ch, _args.labelColumn);
                    weightIndex = GetColumnIndex(ch, _args.weightColumn);
                    idIndex     = GetColumnIndex(ch, _args.colId);

                    Dictionary <long, Tuple <long, float> > merged;
                    _trees = NearestNeighborsBuilder.NearestNeighborsBuild <long>(ch, _input, featureIndex, labelIndex,
                                                                                  idIndex, weightIndex, out merged, _args);
                    ch.Info(MessageSensitivity.UserData, "Done. Tree size: {0} points.", _trees.Count());
                }
            }
        }