Exemplo n.º 1
0
        public Antecedent?CreateAntecedent(int seedIndex, ReadOnlySpan <int> nearestInstancesIndices)
        {
            var builder = HyperRectangleBuilder.InitializeWithSeed(
                dataset: _dataset,
                seedIndex: seedIndex);

            for (int i = 0; i < nearestInstancesIndices.Length; i++)
            {
                var index = nearestInstancesIndices[i];
                EnlargeToCoverInstance(
                    builder: builder,
                    instanceIndex: index);
            }

            var box = builder.TryBuild();

            if (box is null)
            {
                return(null);
            }

            var featureTests = _converter.FromHyperRectangle(box);

            return(new Antecedent(featureTests));
        }
        public HyperRectangle?TryCreateLargestNonIntersectingRectangle(int seedIndex, Array <HyperRectangle> existingHyperRectangles, NaturalRange dimensionExpansionOrder)
        {
            if (dimensionExpansionOrder.Length != Dataset.FeatureCount)
            {
                throw new InvalidOperationException();
            }

            if (existingHyperRectangles.IsEmpty)
            {
                var tempBuilder    = HyperRectangleBuilder.InitializeWithLargestRectangle(Dataset);
                var hyperRectangle = tempBuilder.TryBuild();

                if (hyperRectangle is null)
                {
                    throw new InvalidOperationException();
                }
                else
                {
                    return(hyperRectangle);
                }
            }

            var builder = HyperRectangleBuilder.InitializeWithSeed(
                dataset: Dataset,
                seedIndex: seedIndex);

            var seed = Dataset.GetInstanceData(seedIndex);

            for (int i = 0; i < dimensionExpansionOrder.Length; i++)
            {
                var dimensionIndex = dimensionExpansionOrder[i];

                switch (Dataset.GetFeatureType(dimensionIndex))
                {
                case FeatureType.Continuous:
                    UpdateContinuousDimension(
                        builder: builder,
                        existingHyperRectangles: existingHyperRectangles,
                        dimensionIndex: dimensionIndex,
                        seed: seed);
                    break;

                default:
                    throw CommonExceptions.UnknownFeatureType;
                }
            }

            var largestHyperRectangle = builder.TryBuild();

            return(largestHyperRectangle);
        }