Dela via


SearchSpace<T> Class

Definition

This class is used to represent a set of OptionBase, which can be either one of ChoiceOption, UniformNumericOption or another nested search space.

public sealed class SearchSpace<T> : Microsoft.ML.SearchSpace.SearchSpace where T : class, new()
type SearchSpace<'T (requires 'T : null and 'T : (new : unit -> 'T))> = class
    inherit SearchSpace
Public NotInheritable Class SearchSpace(Of T)
Inherits SearchSpace

Type Parameters

T
Inheritance
SearchSpace<T>

Examples

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Text.Json;
using Microsoft.ML.SearchSpace;
using Microsoft.ML.SearchSpace.Option;

namespace Microsoft.ML.AutoML.Samples
{
    public static class SearchSpaceExample
    {
        public static void Run()
        {
            // The following code shows how to create a SearchSpace for MyParameter.
            var myParameterSearchSpace = new SearchSpace<MyParameter>();

            // Equivalently, you can also create myParameterSearchSpace from scratch.
            var myParameterSearchSpace2 = new SearchSpace.SearchSpace();

            // numeric options
            myParameterSearchSpace2["IntOption"] = new UniformIntOption(min: -10, max: 10, logBase: false, defaultValue: 0);
            myParameterSearchSpace2["SingleOption"] = new UniformSingleOption(min: 1, max: 10, logBase: true, defaultValue: 1);
            myParameterSearchSpace2["DoubleOption"] = new UniformDoubleOption(min: -10, max: 10, logBase: false, defaultValue: 0);

            // choice options
            myParameterSearchSpace2["BoolOption"] = new ChoiceOption(true, false);
            myParameterSearchSpace2["StrOption"] = new ChoiceOption("a", "b", "c");

            // nest options
            var nestedSearchSpace = new SearchSpace.SearchSpace();
            nestedSearchSpace["IntOption"] = new UniformIntOption(min: -10, max: 10, logBase: false, defaultValue: 0);
            myParameterSearchSpace2["Nest"] = nestedSearchSpace;

            // the two search space should be equal
            Debug.Assert(myParameterSearchSpace.GetHashCode() == myParameterSearchSpace2.GetHashCode());
        }

        public class MyParameter
        {
            [Range((int)-10, 10, 0, false)]
            public int IntOption { get; set; }

            [Range(1f, 10f, 1f, true)]
            public float SingleOption { get; set; }

            [Range(-10, 10, false)]
            public double DoubleOption { get; set; }

            [BooleanChoice]
            public bool BoolOption { get; set; }

            [Choice("a", "b", "c")]
            public string StrOption { get; set; }

            [NestOption]
            public NestParameter Nest { get; set; }
        }

        public class NestParameter
        {
            [Range((int)-10, 10, 0, false)]
            public int IntOption { get; set; }
        }
    }
}

Constructors

SearchSpace<T>()

Create SearchSpace<T> from T. This initializer search for the NestOptionAttribute in T and create searching space accordingly.

SearchSpace<T>(T)

Create SearchSpace<T> from T and defaultOption. This initializer search for the NestOptionAttribute in T and create searching space accordingly.

Properties

Count (Inherited from SearchSpace)
Default

Gets the default value which is mapping to feature space (if exists).

(Inherited from SearchSpace)
FeatureSpaceDim

the dimension of feature space, which is equal to the output length of SampleFromFeatureSpace(Double[]).

(Inherited from SearchSpace)
IsReadOnly (Inherited from SearchSpace)
Item[String] (Inherited from SearchSpace)
Keys (Inherited from SearchSpace)
Step

Gets the step of this option. The Step is used to determine the number of grid this option should be divided into. In ChoiceOption, it's always the length of Choices. And in UniformNumericOption, it's always [null]. And in SearchSpace, it's a combination of all Step in its options.

(Inherited from SearchSpace)
Values (Inherited from SearchSpace)

Methods

Add(KeyValuePair<String,OptionBase>) (Inherited from SearchSpace)
Add(String, OptionBase) (Inherited from SearchSpace)
Clear() (Inherited from SearchSpace)
Contains(KeyValuePair<String,OptionBase>) (Inherited from SearchSpace)
ContainsKey(String) (Inherited from SearchSpace)
CopyTo(KeyValuePair<String,OptionBase>[], Int32) (Inherited from SearchSpace)
GetEnumerator() (Inherited from SearchSpace)
GetHashCode() (Inherited from SearchSpace)
MappingToFeatureSpace(Parameter)

mapping value to [0, 1) uniform distribution.

(Inherited from SearchSpace)
MappingToFeatureSpace(T) System.Object.MappingToFeatureSpace(`0)
Remove(KeyValuePair<String,OptionBase>) (Inherited from SearchSpace)
Remove(String) (Inherited from SearchSpace)
SampleFromFeatureSpace(Double[])

sample from [0,1) uniform distribution.

TryGetValue(String, OptionBase) (Inherited from SearchSpace)

Explicit Interface Implementations

IEnumerable.GetEnumerator() (Inherited from SearchSpace)

Applies to