Documentation
¶
Overview ¶
Package kan implements a generic Kolmogorov–Arnold Networks, as described in https://arxiv.org/pdf/2404.19756
Start with New(scope, x, numOutputNodes). Configure further as desired. When finished, call Config.Done, and it will return KAN(x), per configuration.
The original KAN paper used B-Spline functions as the univariate functions. This package implements the B-Spline and the following alternatives: Discrete-KAN (aka. piecewise-constant functions or "staircase functions"), GR-KAN (using rational functions, in the form w.P(x)/Q(x) where P(x) and Q(x) are learnable polynomial functions).
It is highly customizable, each class of univariate function has several hyperparameters.
TODO: Implement "the good" variants from https://github.com/mintisan/awesome-kan
Index ¶
- Constants
- Variables
- func NormalDistributionCDF(x, stddev *Node) *Node
- func PerturbationTypeStrings() []string
- func PiecewiseConstantFunction(input, controlPoints, splitPoints *Node) *Node
- func PiecewiseConstantFunctionWithInputPerturbation(input, controlPoints, splitPoints *Node, perturbation PerturbationType, ...) *Node
- func SoftnessScheduleTypeStrings() []string
- type Config
- func (c *Config) Activation(activation activation.Type) *Config
- func (c *Config) BSpline() *Config
- func (c *Config) Discrete() *Config
- func (c *Config) DiscreteInitialSplitPoints(initialValues *tensors.Tensor) *Config
- func (c *Config) DiscreteInputRange(rangeMin, rangeMax float64) *Config
- func (c *Config) DiscreteSoftness(softness float64) *Config
- func (c *Config) DiscreteSoftnessScheduleType(schedule SoftnessScheduleType) *Config
- func (c *Config) DiscreteSplitsFrozen(frozen bool) *Config
- func (c *Config) DiscreteSplitsTrainable(trainable bool) *Config
- func (c *Config) Done() *Node
- func (c *Config) InputGroupSize(inputGroupSize int) *Config
- func (c *Config) NumControlPoints(numControlPoints int) *Config
- func (c *Config) NumHiddenLayers(numLayers, numHiddenNodes int) *Config
- func (c *Config) PWLExtrapolate(useLinear bool) *Config
- func (c *Config) PWLInitialSplitPoints(initialValues *tensors.Tensor) *Config
- func (c *Config) PWLInputRange(rangeMin, rangeMax float64) *Config
- func (c *Config) PiecewiseLinear() *Config
- func (c *Config) Rational() *Config
- func (c *Config) Regularizer(regularizer regularizer.Regularizer) *Config
- func (c *Config) UseMean(useMean bool) *Config
- func (c *Config) UseResidual(useResidual bool) *Config
- func (c *Config) WithBSplineMagnitudeRegularizer(regularizer regularizer.Regularizer) *Config
- type PerturbationType
- func (i PerturbationType) IsAPerturbationType() bool
- func (i PerturbationType) MarshalJSON() ([]byte, error)
- func (i PerturbationType) MarshalText() ([]byte, error)
- func (i PerturbationType) MarshalYAML() (interface{}, error)
- func (i PerturbationType) String() string
- func (i *PerturbationType) UnmarshalJSON(data []byte) error
- func (i *PerturbationType) UnmarshalText(text []byte) error
- func (i *PerturbationType) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (PerturbationType) Values() []string
- type SoftnessScheduleType
- func (i SoftnessScheduleType) IsASoftnessScheduleType() bool
- func (i SoftnessScheduleType) MarshalJSON() ([]byte, error)
- func (i SoftnessScheduleType) MarshalText() ([]byte, error)
- func (i SoftnessScheduleType) MarshalYAML() (interface{}, error)
- func (i SoftnessScheduleType) String() string
- func (i *SoftnessScheduleType) UnmarshalJSON(data []byte) error
- func (i *SoftnessScheduleType) UnmarshalText(text []byte) error
- func (i *SoftnessScheduleType) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (SoftnessScheduleType) Values() []string
Constants ¶
const ( // ParamNumHiddenLayers is the hyperparameter that defines the default number of hidden layers. // The default is 0, so no hidden layers. ParamNumHiddenLayers = "kan_num_hidden_layers" // ParamNumHiddenNodes is the hyperparameter that defines the default number of hidden nodes for KAN hidden layers. // Default is 10. ParamNumHiddenNodes = "kan_num_hidden_nodes" // ParamNumControlPoints is the hyperparameter that defines the default number of control points // for the KAN versions that use that. // // It works for both B-Splines KAN (the original) and Discrete-KAN. // // Default is 20. ParamNumControlPoints = "kan_num_points" // ParamMean instructs KAN to use mean instead of the sum of the various individual univariate functions. // See https://arxiv.org/abs/2407.20667. // // Default is true. ParamMean = "kan_mean" // ParamResidual defines whether to use residual connection between the layers. Default to true. ParamResidual = "kan_residual" // ParamInputGroupSize defines the size of groups in this inputs should be split. Inputs on the same // group share weights. Setting this to 2 will effectively divide the number of parameters by 2, // but force some inputs to use the same weights. // // The last dimension of the input must be divisible by this number. // // Only implemented by Discrete-KAN for now. // // Default is 0, which means no grouping. ParamInputGroupSize = "kan_input_group_size" // ParamConstantRegularizationL1 adds a regularization of the difference among the different control points, pushing // the learned function to be a constant. // // It works for both B-Splines KAN (the original) and Discrete-KAN. // // Default 0.0 ParamConstantRegularizationL1 = "kan_const_l1_reg" )
Variables ¶
var ( // ParamBSplineDegree is the hyperparameter that defines the default value for the bspline degree used in // the univariate KAN functions. // Default is 2. ParamBSplineDegree = "kan_bspline_degree" // ParamBSplineMagnitudeL2 is the hyperparameter that defines the default L2 regularization amount for the bspline // learned magnitude parameters. // Default is 0. ParamBSplineMagnitudeL2 = "kan_bspline_magnitude_l2" // ParamBSplineMagnitudeL1 is the hyperparameter that defines the default L1 regularization amount for the bspline // learned magnitude parameters. // Default is 0. ParamBSplineMagnitudeL1 = "kan_bspline_magnitude_l1" )
var ( // ParamDiscrete indicates whether to use Discrete-KAN as the univariate function to learn. ParamDiscrete = "kan_discrete" // ParamDiscretePerturbation selects the type of input perturbation used to make the Discrete-KAN differentiable // during training. // // It can take 2 values: "triangular", "normal". The default is "triangular". ParamDiscretePerturbation = "kan_discrete_perturbation" // ParamDiscreteSoftness indicates how much to soften the PCF (piecewise constant functions) during training, // and by how much. // // For triangular perturbation, this is a factor that multiplied by the distance from the first and last // split points, defines the base of the triangle. // // For normal perturbation, this is multiplied by the distance from the first and last split points to // define the standard deviation. // // The default value is 0.1. ParamDiscreteSoftness = "kan_discrete_softness" // ParamDiscreteSoftnessSchedule allows one to have a dynamic softness schedule during training. // // Current valid values are "none", "cosine", "linear", "exponential". Default is "none". ParamDiscreteSoftnessSchedule = "kan_discrete_softness_schedule" // ParamDiscreteSoftnessScheduleMin sets the minimum softness for the softness schedule. // // Default is 1e-5 ParamDiscreteSoftnessScheduleMin = "kan_discrete_min_softness" // ParamDiscreteSplitPointsTrainable is a boolean that indicates whether the split points are trainable and can move around. // // Notice that this is unstable (NaN) for small values of softness -- or at the later stages or training if // using a softness schedule -- because the gradients go to infinity close to the split points. // The recommend way of using it is training in multiple stages, with a fixed softness and trainable splits // first, and later freezing the split points (see ParamDiscreteSplitPointsFrozen). // // Default is false. ParamDiscreteSplitPointsTrainable = "kan_discrete_splits_trainable" // ParamDiscreteSplitPointsFrozen is a boolean that indicates whether the trained split-points should be frozen. // // This only has an effect if the split points are set to trainable (see ParamDiscreteSplitPointsTrainable). // This is useful if after training the split points, one is going to use a softness schedule, and the // softness is going to get very small (which leads to NaNs in the split points). ParamDiscreteSplitPointsFrozen = "kan_discrete_splits_frozen" // ParamDiscreteSplitsMargin is the minimum distance between consecutive split points. // Only applies if the split points are trainable, in which case they are always projected to // monotonicity with this minimum margin -- it can be set to 0.0, in which case split points can merge. // Default is 0.01. ParamDiscreteSplitsMargin = "kan_discrete_splits_margin" )
var ( // ParamPiecewiseLinear indicates whether to use PWL-KAN as the univariate function to learn. ParamPiecewiseLinear = "kan_pwl" // ParamPWLExtrapolate indicates whether to extrapolate linearly outside the range of the split points. // If set to false, the function becomes a constant at the extremes. ParamPWLExtrapolate = "kan_pwl_extrapolate" // ParamPWLSplitPointsTrainable is a boolean that indicates whether the split points are trainable and can move around. // // Default is false. ParamPWLSplitPointsTrainable = "kan_pwl_splits_trainable" // ParamPWLSplitPointsFrozen is a boolean that indicates whether the trained split-points should be frozen. // // This only has an effect if the split points are set to trainable (see ParamPWLSplitPointsTrainable). // This is useful if after training the split points, one is going to use a softness schedule, and the // softness is going to get very small (which leads to NaNs in the split points). ParamPWLSplitPointsFrozen = "kan_pwl_splits_frozen" // ParamPWLSplitsMargin is the minimum distance between consecutive split points. // Only applies if the split points are trainable, in which case they are always projected to // monotonicity with this minimum margin -- it can be set to 0.0, in which case split points can merge. // Default is 0.01. ParamPWLSplitsMargin = "kan_pwl_splits_margin" )
var ( // ParamRational indicates whether to use GR-KAN (KAN with rational functions) as the univariate function to learn. ParamRational = "kan_rational" // ParamRationalNumeratorDegree configures the default value for the numerator degree for GR-KAN. ParamRationalNumeratorDegree = "kan_rational_num" // ParamRationalDenominatorDegree configures the default value for the numerator degree for GR-KAN. ParamRationalDenominatorDegree = "kan_rational_den" // ParamRationalInitialApproximation configures how to initialize the values of the rational functions. // Valid values are "identity", "swish", "relu". See rational if the approximation is not given for the // given the degrees combination. ParamRationalInitialApproximation = "kan_rational_approximate" )
Functions ¶
func NormalDistributionCDF ¶ added in v0.13.0
func NormalDistributionCDF(x, stddev *Node) *Node
NormalDistributionCDF calculates the CDF for a normal distribution centered in zero and with the given standard deviation.
func PerturbationTypeStrings ¶ added in v0.13.0
func PerturbationTypeStrings() []string
PerturbationTypeStrings returns a slice of all String values of the enum
func PiecewiseConstantFunction ¶
func PiecewiseConstantFunction(input, controlPoints, splitPoints *Node) *Node
PiecewiseConstantFunction (PCF) generates a PCF output for a cross of numInputNodes x numOutputNodes, defined as the dimensions of its inputs, as follows:
- input to be transformed, shaped [batchSize, numInputNodes]. If using input grouping, the input should be shaped [batchSize, numInputGroups, inputGroupSize], otherwise assume numInputGroups == numInputNodes.
- controlPoints are the output values of the PCFs, and should be shaped [numOutputNodes, numInputGroups, NumControlPoints]
- splitPoints are the splitting values of the inputs, shaped [numOutputNodes or 1, numInputGroups or 1, NumControlPoints-1], but if the first or the second axes are set to 1, they are broadcast accordingly.
The output will be shaped [batchSize, numOutputPoints, numInputNodes]. Presumably, the caller will graph.ReduceMean (or ReduceSum) on the last axis (after residual value is added) for a shape [batchSize, numOutputPoints].
func PiecewiseConstantFunctionWithInputPerturbation ¶
func PiecewiseConstantFunctionWithInputPerturbation(input, controlPoints, splitPoints *Node, perturbation PerturbationType, softness *Node) *Node
PiecewiseConstantFunctionWithInputPerturbation works similarly to PiecewiseConstantFunction but adds a "perturbation" of the inputs by a noise distribution of the value, controlled by smoothness.
The shapes and inputs are the same as PiecewiseConstantFunction, with the added perturbation type and smoothness parameters. The smoothness should be a scalar with suggested values from 0 to 1.0.
The smoothness softens the function by perturbing the input using a triangular (or normal) distribution, whose base is given by softness * 2 * (splitPoint[-1] - splitPoint[0]). If softness is 0, the function is back to being piece-wise constant.
The softening makes it differentiable with respect to the splitPoints, and hence can be used for training. One can control the softness as a form of annealing on the split points. As it reaches 0, the split points are no longer changed (only the control points).
The output will be shaped [batchSize, numOutputPoints, numInputNodes]. Presumably, the caller will graph.ReduceMean (or ReduceSum) on the last axis (after residual value is added) for a shape [batchSize, numOutputPoints].
func SoftnessScheduleTypeStrings ¶ added in v0.13.0
func SoftnessScheduleTypeStrings() []string
SoftnessScheduleTypeStrings returns a slice of all String values of the enum
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is created with New and can be configured with its methods, or simply setting the corresponding hyperparameters in the model.
func New ¶
New returns the configuration for a KAN bsplineLayer(s) to be applied to the input x. See methods for optional configurations. When finished configuring call Done, and it will return "KAN(x)".
The input is expected to have shape `[<batch dimensions...>, <featureDimension>]`, the output will have shape `[<batch dimensions...>, <numOutputNodes>]`.
It will apply KAN-like transformations to the last axis (the "feature axis") of x, while preserving all leading axes (we'll call them "batch axes").
func (*Config) Activation ¶
func (c *Config) Activation(activation activation.Type) *Config
Activation sets the activation for the KAN, which is applied after the sum.
Following the paper, it defaults to "none", but it will be overridden if the hyperparameter layers.ParamActivation (="activation") is set in the model.
Most KAN functions are already non-linear, and don't require activation.
func (*Config) BSpline ¶
BSpline configures the KAN to use b-splines to model \phi(x), the univariate function described in the KAN the paper. It also sets the number of control points to use to model the function.
This is default KAN function.
func (*Config) Discrete ¶
Discrete configures the KAN to use a "piecewise-constant" functions (as opposed to splines) to model \phi(x), the univariate function used in the pape, and set the number of control points to use for the function.
Discrete-KAN is a variation of KAN that uses a piecewise-constant function (PCF for short) as its univariate function family -- as opposed to the original spline functions.
The number of control points used can be set up with Config.Para These PCFs (piecewise-constant functions) have "split points", where the function change values, and "control points" which are the outputs of the function between the corresponding split points. For N split points, there are N+1 split points. The first and last regions extend to -/+ infinity, so it extrapolates as a constant.
The goal is to train models that for inference require no multiplications, only additions and a max(x, 0) for the relu activations, and can be executed efficiently in any cheap hardware -- not requiring specialized accelerators.
in order to make the split points of the PCFs trainable, and regularize, during training we can "soften" the PCFs, by implicitly converting the input of a PCF (let's call it x) to a probability distribution (aka. "input perturbation"). Then integrate over the distribution over x to calculate the result of the softened PCF. See details for this in [1].
Notice that the regularizer set with Config.Regularizer applies only to the "control points".
[1] Learning Representations for Axis-Aligned Decision Forests through Input Perturbation - Sebastian Bruch, Jan Pfeifer, Mathieu Guillame-Bert - https://arxiv.org/pdf/2007.14761
func (*Config) DiscreteInitialSplitPoints ¶ added in v0.13.0
DiscreteInitialSplitPoints sets the initialValues to the split-points. initialValues should be shaped [n-1], where n is the number of control points. This also sets the number of control points to n.
The default is to initialize the split points as a uniform range. See also DiscreteInputRange.
Enable Discrete-KAN with Discrete(true).
func (*Config) DiscreteInputRange ¶ added in v0.13.0
DiscreteInputRange defines how to initialize the split-points: they are uniformly taken from the given range, with the first split point at rangeMin, and the last split point at rangeMax. It requires rangeMax > rangeMin.
The default range is [-1, 1.0]. See also DiscreteInitialSplitPoints.
Enable Discrete-KAN with Discrete(true).
func (*Config) DiscreteSoftness ¶
DiscreteSoftness sets how much softness to use during training. If set to 0 softness is disabled.
The default is 0.1, and it can be set with the hyperparameter ParamDiscreteSoftness ("kan_discrete_softness").
func (*Config) DiscreteSoftnessScheduleType ¶ added in v0.13.0
func (c *Config) DiscreteSoftnessScheduleType(schedule SoftnessScheduleType) *Config
DiscreteSoftnessScheduleType configures the type of schedule of the softness for Discrete-KAN.
It defaults to SoftnessScheduleNone (0)
func (*Config) DiscreteSplitsFrozen ¶ added in v0.13.0
DiscreteSplitsFrozen is a boolean that indicates whether the trained split-points should be frozen.
This only has an effect if the split points are set to trainable (see ParamDiscreteSplitPointsTrainable). This is useful if after training the split points, one is going to use a softness schedule, and the softness is going to get very small (which leads to NaNs in the split points).
Default is false and can be set with the scope hyperparameter ParamDiscreteSplitPointsFrozen.
func (*Config) DiscreteSplitsTrainable ¶ added in v0.13.0
DiscreteSplitsTrainable defines whether the split points are trainable.
Notice that this is unstable (NaN) for small values of softness -- or at the later stages or training if using a softness schedule -- because the gradients go to infinity close to the split points. The recommend way of using it is training in multiple stages, with a fixed softness and trainable splits first, and later freezing the split points (see ParamDiscreteSplitPointsFrozen).
Default is false, and can be set with the scope hyperparameter ParamDiscreteSplitPointsTrainable.
func (*Config) Done ¶
func (c *Config) Done() *Node
Done takes the configuration and apply the KAN bsplineLayer(s) configured.
func (*Config) InputGroupSize ¶ added in v0.13.0
InputGroupSize defines the size of groups in this inputs should be split. Inputs on the same group share weights. Setting this to 2 will effectively divide the number of parameters by 2, but force some inputs to use the same weights.
The last dimension of the input must be divisible by this number.
Only implemented by Discrete-KAN and GR-KAN for now.
The default is 0, which means no grouping. It can be configured with the ParamInputGroupSize hyperparameter.
func (*Config) NumControlPoints ¶ added in v0.13.0
NumControlPoints is used by BSpline (standard) KAN and Discrete-KAN to define the number of points used to control the univariate functions.
The default is 10, and it can be configured with the ParamNumControlPoints hyperparameter.
func (*Config) NumHiddenLayers ¶
NumHiddenLayers configure the number of hidden layers between the input and the output. Each bsplineLayer will have numHiddenNodes nodes.
The default is 0 (no hidden layers), but it will be overridden if the hyperparameter ParamNumHiddenLayers is set in the scope (scope). The value for numHiddenNodes can also be configured with the hyperparameter ParamNumHiddenNodes.
func (*Config) PWLExtrapolate ¶ added in v0.13.0
PWLExtrapolate configures whether the PWL-KAN should extrapolate linearly outside the split-points. If useLinear is set to false, it extrapolates as a constant value.
Default is false (constant extrapolation), and it is set by the hyperparameter ParamPWLExtrapolate.
func (*Config) PWLInitialSplitPoints ¶ added in v0.13.0
PWLInitialSplitPoints sets the initialValues shaped [n] to the split-points. This also sets the number of control points to n, the dimension of the tensor.
The default is to initialize the split points as a uniform range. See also PWLInputRange.
Enable PWL-KAN with Config.Piecewise(true).
func (*Config) PWLInputRange ¶ added in v0.13.0
PWLInputRange defines how to initialize the split-points: they are uniformly taken from the given range, with the first split point at rangeMin, and the last split point at rangeMax. It requires rangeMax > rangeMin.
The default range is [-1, 1.0]. See also PWLInitialSplitPoints.
Enable PWL-KAN with PWL(true).
func (*Config) PiecewiseLinear ¶ added in v0.13.0
PiecewiseLinear configures for a PWL-KAN (PieceWise-Linear), as opposed to the default BSpline.
This can also be set using the hyperparameter ParamPiecewiseLinear.
func (*Config) Rational ¶ added in v0.13.0
Rational configures for GR-KAN, in which rational functions (as opposed to b-splines) are used to model \phi(x), the univariate function. See description in [1].
See implementation details in package ml/layers/rational, [2] and [3].
[1] "Kolmogorov-Arnold Transformer" by Xingyi Yang and Xinchao Wang, https://arxiv.org/abs/2409.10594 [2] https://github.com/ml-research/rational_activations/ [3] "Padé Activation Units: End-to-end Learning of Flexible Activation Functions in Deep Networks" by
func (*Config) Regularizer ¶
func (c *Config) Regularizer(regularizer regularizer.Regularizer) *Config
Regularizer to be applied to the learned weights. Default is none.
To use more than one type of Regularizer, use regularizers.Combine, and set the returned combined regularizer here.
For BSpline models it applies the regularizer to the control-points.
The default is no regularizer, but it can be configured by regularizers.ParamL1 and regularizers.ParamL2.
func (*Config) UseMean ¶ added in v0.13.0
UseMean instead of sum when reducing the outputs.
The original paper uses sum, but mean is more stable in many scenarios.
The default is true. It can be configured with the ParamMean hyperparameter.
func (*Config) UseResidual ¶ added in v0.13.0
UseResidual sets the flag to determine the use of residuals and returns the updated configuration object.
Residual connections are used to reduce the number of parameters, and to improve the performance of the model.
The residual connections are implemented by adding a residual connection to the output of the previous layer, and then adding the residual to the output of the current layer.
The default is true. It can be configured with the ParamResidual hyperparameter.
func (*Config) WithBSplineMagnitudeRegularizer ¶
func (c *Config) WithBSplineMagnitudeRegularizer(regularizer regularizer.Regularizer) *Config
WithBSplineMagnitudeRegularizer to be applied to the magnitude weights for BSpline. Default is none, but can be changed with hyperparameters ParamBSplineMagnitudeL2 and ParamBSplineMagnitudeL1.
For BSpline models it applies the regularizer to the control-points.
type PerturbationType ¶ added in v0.13.0
type PerturbationType int
PerturbationType used by PiecewiseConstantFunctionWithInputPerturbation
const ( PerturbationTriangular PerturbationType = iota PerturbationNormal )
func PerturbationTypeString ¶ added in v0.13.0
func PerturbationTypeString(s string) (PerturbationType, error)
PerturbationTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func PerturbationTypeValues ¶ added in v0.13.0
func PerturbationTypeValues() []PerturbationType
PerturbationTypeValues returns all values of the enum
func (PerturbationType) IsAPerturbationType ¶ added in v0.13.0
func (i PerturbationType) IsAPerturbationType() bool
IsAPerturbationType returns "true" if the value is listed in the enum definition. "false" otherwise
func (PerturbationType) MarshalJSON ¶ added in v0.13.0
func (i PerturbationType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for PerturbationType
func (PerturbationType) MarshalText ¶ added in v0.13.0
func (i PerturbationType) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for PerturbationType
func (PerturbationType) MarshalYAML ¶ added in v0.13.0
func (i PerturbationType) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for PerturbationType
func (PerturbationType) String ¶ added in v0.13.0
func (i PerturbationType) String() string
func (*PerturbationType) UnmarshalJSON ¶ added in v0.13.0
func (i *PerturbationType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for PerturbationType
func (*PerturbationType) UnmarshalText ¶ added in v0.13.0
func (i *PerturbationType) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for PerturbationType
func (*PerturbationType) UnmarshalYAML ¶ added in v0.13.0
func (i *PerturbationType) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for PerturbationType
func (PerturbationType) Values ¶ added in v0.13.0
func (PerturbationType) Values() []string
type SoftnessScheduleType ¶ added in v0.13.0
type SoftnessScheduleType int
SoftnessScheduleType describes the type of schedule of the softness for Discrete-KAN.
const ( // SoftnessScheduleNone indicates no schedule, that is a constant softness during training. SoftnessScheduleNone SoftnessScheduleType = iota // SoftnessScheduleCosine uses softness*(Cos(π.progress)+1.0)/2.0 + epsilon). SoftnessScheduleCosine // SoftnessScheduleLinear uses softness*((1.0-progress) + epsilon). SoftnessScheduleLinear // SoftnessScheduleExponential uses softness*e^(-lambda*progress), where lambda = log(100), so it is 1/100 of the // original softness at the end of the training. SoftnessScheduleExponential // SoftnessScheduleLast indicates the last valid enum value -> keep this last. SoftnessScheduleLast )
func SoftnessScheduleTypeString ¶ added in v0.13.0
func SoftnessScheduleTypeString(s string) (SoftnessScheduleType, error)
SoftnessScheduleTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func SoftnessScheduleTypeValues ¶ added in v0.13.0
func SoftnessScheduleTypeValues() []SoftnessScheduleType
SoftnessScheduleTypeValues returns all values of the enum
func (SoftnessScheduleType) IsASoftnessScheduleType ¶ added in v0.13.0
func (i SoftnessScheduleType) IsASoftnessScheduleType() bool
IsASoftnessScheduleType returns "true" if the value is listed in the enum definition. "false" otherwise
func (SoftnessScheduleType) MarshalJSON ¶ added in v0.13.0
func (i SoftnessScheduleType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for SoftnessScheduleType
func (SoftnessScheduleType) MarshalText ¶ added in v0.13.0
func (i SoftnessScheduleType) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for SoftnessScheduleType
func (SoftnessScheduleType) MarshalYAML ¶ added in v0.13.0
func (i SoftnessScheduleType) MarshalYAML() (interface{}, error)
MarshalYAML implements a YAML Marshaler for SoftnessScheduleType
func (SoftnessScheduleType) String ¶ added in v0.13.0
func (i SoftnessScheduleType) String() string
func (*SoftnessScheduleType) UnmarshalJSON ¶ added in v0.13.0
func (i *SoftnessScheduleType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for SoftnessScheduleType
func (*SoftnessScheduleType) UnmarshalText ¶ added in v0.13.0
func (i *SoftnessScheduleType) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for SoftnessScheduleType
func (*SoftnessScheduleType) UnmarshalYAML ¶ added in v0.13.0
func (i *SoftnessScheduleType) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements a YAML Unmarshaler for SoftnessScheduleType
func (SoftnessScheduleType) Values ¶ added in v0.13.0
func (SoftnessScheduleType) Values() []string