diff --git a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/ForecastingWithConfidenceInterval.cs b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/ForecastingWithConfidenceInterval.cs index f9e7f891f3..c8a3be9305 100644 --- a/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/ForecastingWithConfidenceInterval.cs +++ b/docs/samples/Microsoft.ML.Samples/Dynamic/Transforms/TimeSeries/ForecastingWithConfidenceInterval.cs @@ -48,8 +48,8 @@ public static void Example() // Instantiate the forecasting model. var model = ml.Forecasting.ForecastBySsa(outputColumnName, inputColumnName, 5, 11, data.Count, 5, confidenceLevel: 0.95f, - lowerBoundConfidenceColumn: "ConfidenceLowerBound", - upperBoundConfidenceColumn: "ConfidenceUpperBound"); + confidenceLowerBoundColumn: "ConfidenceLowerBound", + confidenceUpperBoundColumn: "ConfidenceUpperBound"); // Train. var transformer = model.Fit(dataView); diff --git a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs index 2581347b3c..11ffa01017 100644 --- a/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs +++ b/src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs @@ -167,8 +167,8 @@ public static SrCnnAnomalyEstimator DetectAnomalyBySrCnn(this TransformsCatalog /// The flag determining whether the model should be stabilized. /// The flag determining whether the meta information for the model needs to be maintained. /// The maximum growth on the exponential trend. - /// The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated. - /// The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated. + /// The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated. + /// The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated. /// The confidence level for forecasting. /// Set this to true if horizon will change after training(at prediction time). /// @@ -182,10 +182,10 @@ public static SrCnnAnomalyEstimator DetectAnomalyBySrCnn(this TransformsCatalog public static SsaForecastingEstimator ForecastBySsa( this ForecastingCatalog catalog, string outputColumnName, string inputColumnName, int windowSize, int seriesLength, int trainSize, int horizon, bool isAdaptive = false, float discountFactor = 1, RankSelectionMethod rankSelectionMethod = RankSelectionMethod.Exact, int? rank = null, - int? maxRank = null, bool shouldStabilize = true, bool shouldMaintainInfo = false, GrowthRatio? maxGrowth = null, string lowerBoundConfidenceColumn = null, - string upperBoundConfidenceColumn = null, float confidenceLevel = 0.95f, bool variableHorizon = false) => + int? maxRank = null, bool shouldStabilize = true, bool shouldMaintainInfo = false, GrowthRatio? maxGrowth = null, string confidenceLowerBoundColumn = null, + string confidenceUpperBoundColumn = null, float confidenceLevel = 0.95f, bool variableHorizon = false) => new SsaForecastingEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnName, inputColumnName, windowSize, seriesLength, trainSize, - horizon, isAdaptive, discountFactor, rankSelectionMethod, rank, maxRank, shouldStabilize, shouldMaintainInfo, maxGrowth, lowerBoundConfidenceColumn, - upperBoundConfidenceColumn, confidenceLevel, variableHorizon); + horizon, isAdaptive, discountFactor, rankSelectionMethod, rank, maxRank, shouldStabilize, shouldMaintainInfo, maxGrowth, confidenceLowerBoundColumn, + confidenceUpperBoundColumn, confidenceLevel, variableHorizon); } } diff --git a/src/Microsoft.ML.TimeSeries/SSaForecasting.cs b/src/Microsoft.ML.TimeSeries/SSaForecasting.cs index d6e7f9e8ab..8dc9c981b3 100644 --- a/src/Microsoft.ML.TimeSeries/SSaForecasting.cs +++ b/src/Microsoft.ML.TimeSeries/SSaForecasting.cs @@ -42,10 +42,10 @@ internal sealed class Options : TransformInputBase public string Name; [Argument(ArgumentType.AtMostOnce, HelpText = "The name of the confidence interval lower bound column.", ShortName = "cnfminname", SortOrder = 3)] - public string LowerBoundConfidenceColumn; + public string ConfidenceLowerBoundColumn; [Argument(ArgumentType.AtMostOnce, HelpText = "The name of the confidence interval upper bound column.", ShortName = "cnfmaxnname", SortOrder = 3)] - public string UpperBoundConfidenceColumn; + public string ConfidenceUpperBoundColumn; [Argument(ArgumentType.AtMostOnce, HelpText = "The discount factor in [0,1] used for online updates.", ShortName = "disc", SortOrder = 5)] public float DiscountFactor = 1; @@ -97,8 +97,8 @@ public BaseArguments(Options options) { Source = options.Source; Name = options.Name; - LowerBoundConfidenceColumn = options.LowerBoundConfidenceColumn; - UpperBoundConfidenceColumn = options.UpperBoundConfidenceColumn; + ConfidenceLowerBoundColumn = options.ConfidenceLowerBoundColumn; + ConfidenceUpperBoundColumn = options.ConfidenceUpperBoundColumn; WindowSize = options.WindowSize; DiscountFactor = options.DiscountFactor; IsAdaptive = options.IsAdaptive; @@ -258,8 +258,8 @@ public sealed class SsaForecastingEstimator : IEstimatorThe flag determining whether the model should be stabilized. /// The flag determining whether the meta information for the model needs to be maintained. /// The maximum growth on the exponential trend. - /// The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated. - /// The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated. + /// The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated. + /// The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated. /// The confidence level for forecasting. /// Set this to true if horizon will change after training. internal SsaForecastingEstimator(IHostEnvironment env, @@ -277,8 +277,8 @@ internal SsaForecastingEstimator(IHostEnvironment env, bool shouldStabilize = true, bool shouldMaintainInfo = false, GrowthRatio? maxGrowth = null, - string lowerBoundConfidenceColumn = null, - string upperBoundConfidenceColumn = null, + string confidenceLowerBoundColumn = null, + string confidenceUpperBoundColumn = null, float confidenceLevel = 0.95f, bool variableHorizon = false) : this(env, new SsaForecastingTransformer.Options @@ -295,8 +295,8 @@ internal SsaForecastingEstimator(IHostEnvironment env, ShouldMaintainInfo = shouldMaintainInfo, MaxGrowth = maxGrowth, ConfidenceLevel = confidenceLevel, - LowerBoundConfidenceColumn = lowerBoundConfidenceColumn, - UpperBoundConfidenceColumn = upperBoundConfidenceColumn, + ConfidenceLowerBoundColumn = confidenceLowerBoundColumn, + ConfidenceUpperBoundColumn = confidenceUpperBoundColumn, SeriesLength = seriesLength, TrainSize = trainSize, VariableHorizon = variableHorizon, @@ -344,14 +344,14 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema) resultDic[_options.Name] = new SchemaShape.Column( _options.Name, SchemaShape.Column.VectorKind.Vector, NumberDataViewType.Single, false); - if (!string.IsNullOrEmpty(_options.UpperBoundConfidenceColumn)) + if (!string.IsNullOrEmpty(_options.ConfidenceUpperBoundColumn)) { - resultDic[_options.LowerBoundConfidenceColumn] = new SchemaShape.Column( - _options.LowerBoundConfidenceColumn, SchemaShape.Column.VectorKind.Vector, + resultDic[_options.ConfidenceLowerBoundColumn] = new SchemaShape.Column( + _options.ConfidenceLowerBoundColumn, SchemaShape.Column.VectorKind.Vector, NumberDataViewType.Single, false); - resultDic[_options.UpperBoundConfidenceColumn] = new SchemaShape.Column( - _options.UpperBoundConfidenceColumn, SchemaShape.Column.VectorKind.Vector, + resultDic[_options.ConfidenceUpperBoundColumn] = new SchemaShape.Column( + _options.ConfidenceUpperBoundColumn, SchemaShape.Column.VectorKind.Vector, NumberDataViewType.Single, false); } diff --git a/src/Microsoft.ML.TimeSeries/SequentialForecastingTransformBase.cs b/src/Microsoft.ML.TimeSeries/SequentialForecastingTransformBase.cs index 4f1e96039c..5b7813bc11 100644 --- a/src/Microsoft.ML.TimeSeries/SequentialForecastingTransformBase.cs +++ b/src/Microsoft.ML.TimeSeries/SequentialForecastingTransformBase.cs @@ -28,11 +28,11 @@ internal abstract class ForecastingArgumentsBase [Argument(ArgumentType.Required, HelpText = "The name of the confidence interval lower bound column.", ShortName = "cnfminname", SortOrder = 2)] - public string LowerBoundConfidenceColumn; + public string ConfidenceLowerBoundColumn; [Argument(ArgumentType.Required, HelpText = "The name of the confidence interval upper bound column.", ShortName = "cnfmaxnname", SortOrder = 2)] - public string UpperBoundConfidenceColumn; + public string ConfidenceUpperBoundColumn; [Argument(ArgumentType.AtMostOnce, HelpText = "The length of series from the begining used for training.", ShortName = "wnd", SortOrder = 3)] @@ -57,18 +57,18 @@ internal abstract class SequentialForecastingTransformBase : Seq private readonly int _outputLength; private protected SequentialForecastingTransformBase(int windowSize, int initialWindowSize, - string inputColumnName, string outputColumnName, string forecastingConfidenceIntervalMinOutputColumnName, - string forecastingConfidenceIntervalMaxOutputColumnName, string name, int outputLength, IHostEnvironment env) + string inputColumnName, string outputColumnName, string confidenceLowerBoundColumn, + string confidenceUpperBoundColumn, string name, int outputLength, IHostEnvironment env) : base(Contracts.CheckRef(env, nameof(env)).Register(name), windowSize, initialWindowSize, - outputColumnName, forecastingConfidenceIntervalMinOutputColumnName, - forecastingConfidenceIntervalMaxOutputColumnName, inputColumnName, new VectorDataViewType(NumberDataViewType.Single, outputLength)) + outputColumnName, confidenceLowerBoundColumn, + confidenceUpperBoundColumn, inputColumnName, new VectorDataViewType(NumberDataViewType.Single, outputLength)) { _outputLength = outputLength; } private protected SequentialForecastingTransformBase(ForecastingArgumentsBase args, string name, int outputLength, IHostEnvironment env) - : this(args.TrainSize, args.SeriesLength, args.Source, args.LowerBoundConfidenceColumn, - args.UpperBoundConfidenceColumn, args.Name, name, outputLength, env) + : this(args.TrainSize, args.SeriesLength, args.Source, args.ConfidenceLowerBoundColumn, + args.ConfidenceUpperBoundColumn, args.Name, name, outputLength, env) { } @@ -127,12 +127,12 @@ public DataViewSchema.DetachedColumn[] GetOutputColumns() { DetachedColumn[] info; - if (!string.IsNullOrEmpty(_parent.ForecastingConfidenceIntervalMaxOutputColumnName)) + if (!string.IsNullOrEmpty(_parent.ConfidenceUpperBoundColumn)) { info = new DetachedColumn[3]; info[0] = new DetachedColumn(_parent.OutputColumnName, new VectorDataViewType(NumberDataViewType.Single, _parent._outputLength)); - info[1] = new DetachedColumn(_parent.ForecastingConfidenceIntervalMinOutputColumnName, new VectorDataViewType(NumberDataViewType.Single, _parent._outputLength)); - info[2] = new DetachedColumn(_parent.ForecastingConfidenceIntervalMaxOutputColumnName, new VectorDataViewType(NumberDataViewType.Single, _parent._outputLength)); + info[1] = new DetachedColumn(_parent.ConfidenceLowerBoundColumn, new VectorDataViewType(NumberDataViewType.Single, _parent._outputLength)); + info[2] = new DetachedColumn(_parent.ConfidenceUpperBoundColumn, new VectorDataViewType(NumberDataViewType.Single, _parent._outputLength)); } else { @@ -156,7 +156,7 @@ public Func GetDependencies(Func activeOutput) public Delegate[] CreateGetters(DataViewRow input, Func activeOutput, out Action disposer) { disposer = null; - var getters = string.IsNullOrEmpty(_parent.ForecastingConfidenceIntervalMaxOutputColumnName) ? new Delegate[1] : new Delegate[3]; + var getters = string.IsNullOrEmpty(_parent.ConfidenceUpperBoundColumn) ? new Delegate[1] : new Delegate[3]; if (activeOutput(0)) { @@ -168,7 +168,7 @@ public Delegate[] CreateGetters(DataViewRow input, Func activeOutput, getters[0] = valueGetter; } - if (!string.IsNullOrEmpty(_parent.ForecastingConfidenceIntervalMaxOutputColumnName)) + if (!string.IsNullOrEmpty(_parent.ConfidenceUpperBoundColumn)) { if (activeOutput(1)) { diff --git a/src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs b/src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs index af6017a6ca..4ffe27b31f 100644 --- a/src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs +++ b/src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs @@ -335,8 +335,8 @@ private protected virtual void CloneCore(TState state) internal readonly string InputColumnName; internal readonly string OutputColumnName; - internal readonly string ForecastingConfidenceIntervalMinOutputColumnName; - internal readonly string ForecastingConfidenceIntervalMaxOutputColumnName; + internal readonly string ConfidenceLowerBoundColumn; + internal readonly string ConfidenceUpperBoundColumn; private protected DataViewType OutputColumnType; bool ITransformer.IsRowToRowMapper => false; @@ -372,12 +372,12 @@ private protected SequentialTransformerBase(IHost host, int windowSize, int init } private protected SequentialTransformerBase(IHost host, int windowSize, int initialWindowSize, - string outputColumnName, string forecastingConfidenceIntervalMinOutputColumnName, - string forecastingConfidenceIntervalMaxOutputColumnName, string inputColumnName, DataViewType outputColType) : + string outputColumnName, string confidenceLowerBoundColumn, + string confidenceUpperBoundColumn, string inputColumnName, DataViewType outputColType) : this(host, windowSize, initialWindowSize, outputColumnName, inputColumnName, outputColType) { - ForecastingConfidenceIntervalMinOutputColumnName = forecastingConfidenceIntervalMinOutputColumnName; - ForecastingConfidenceIntervalMaxOutputColumnName = forecastingConfidenceIntervalMaxOutputColumnName; + ConfidenceLowerBoundColumn = confidenceLowerBoundColumn; + ConfidenceUpperBoundColumn = confidenceUpperBoundColumn; } private protected SequentialTransformerBase(IHost host, ModelLoadContext ctx) @@ -403,8 +403,8 @@ private protected SequentialTransformerBase(IHost host, ModelLoadContext ctx) InputColumnName = inputColumnName; OutputColumnName = outputColumnName; - ForecastingConfidenceIntervalMinOutputColumnName = ctx.Reader.ReadString(); - ForecastingConfidenceIntervalMaxOutputColumnName = ctx.Reader.ReadString(); + ConfidenceLowerBoundColumn = ctx.Reader.ReadString(); + ConfidenceUpperBoundColumn = ctx.Reader.ReadString(); InitialWindowSize = initialWindowSize; WindowSize = windowSize; @@ -431,8 +431,8 @@ private protected virtual void SaveModel(ModelSaveContext ctx) ctx.Writer.Write(InitialWindowSize); ctx.SaveNonEmptyString(InputColumnName); ctx.SaveNonEmptyString(OutputColumnName); - ctx.Writer.Write(ForecastingConfidenceIntervalMinOutputColumnName ?? string.Empty); - ctx.Writer.Write(ForecastingConfidenceIntervalMaxOutputColumnName ?? string.Empty); + ctx.Writer.Write(ConfidenceLowerBoundColumn ?? string.Empty); + ctx.Writer.Write(ConfidenceUpperBoundColumn ?? string.Empty); var bs = new BinarySaver(Host, new BinarySaver.Arguments()); bs.TryWriteTypeDescription(ctx.Writer.BaseStream, OutputColumnType, out int byteWritten); } @@ -480,8 +480,8 @@ public SequentialDataTransform(IHost host, SequentialTransformerBase 0, _parent.OutputColumnType); + _parent.OutputColumnName, _parent.ConfidenceLowerBoundColumn, + _parent.ConfidenceUpperBoundColumn, InitFunction, _parent.WindowSize > 0, _parent.OutputColumnType); _mapper = mapper; _bindings = new ColumnBindings(input.Schema, _mapper.GetOutputColumns()); diff --git a/src/Microsoft.ML.TimeSeries/SsaForecastingBase.cs b/src/Microsoft.ML.TimeSeries/SsaForecastingBase.cs index f7911e1047..1eb942c775 100644 --- a/src/Microsoft.ML.TimeSeries/SsaForecastingBase.cs +++ b/src/Microsoft.ML.TimeSeries/SsaForecastingBase.cs @@ -127,8 +127,8 @@ internal sealed class SsaForecastingBase : SequentialForecastingTransformBase Model; public SsaForecastingBase(SsaForecastingOptions options, string name, IHostEnvironment env, SsaForecastingBaseWrapper parent) - : base(options.TrainSize, 0, options.Source, options.Name, options.LowerBoundConfidenceColumn, - options.UpperBoundConfidenceColumn, name, options.VariableHorizon ? 0: options.Horizon, env) + : base(options.TrainSize, 0, options.Source, options.Name, options.ConfidenceLowerBoundColumn, + options.ConfidenceUpperBoundColumn, name, options.VariableHorizon ? 0: options.Horizon, env) { Host.CheckUserArg(0 <= options.DiscountFactor && options.DiscountFactor <= 1, nameof(options.DiscountFactor), "Must be in the range [0, 1]."); IsAdaptive = options.IsAdaptive; @@ -136,7 +136,7 @@ public SsaForecastingBase(SsaForecastingOptions options, string name, IHostEnvir ConfidenceLevel = options.ConfidenceLevel; // Creating the master SSA model Model = new AdaptiveSingularSpectrumSequenceModelerInternal(Host, options.TrainSize, options.SeriesLength, options.WindowSize, - options.DiscountFactor, options.RankSelectionMethod, options.Rank, options.MaxRank, !string.IsNullOrEmpty(options.LowerBoundConfidenceColumn), + options.DiscountFactor, options.RankSelectionMethod, options.Rank, options.MaxRank, !string.IsNullOrEmpty(options.ConfidenceLowerBoundColumn), options.ShouldStablize, options.ShouldMaintainInfo, options.MaxGrowth); StateRef = new State(); diff --git a/test/BaselineOutput/Common/EntryPoints/core_manifest.json b/test/BaselineOutput/Common/EntryPoints/core_manifest.json index 166e75173b..6d9e968d58 100644 --- a/test/BaselineOutput/Common/EntryPoints/core_manifest.json +++ b/test/BaselineOutput/Common/EntryPoints/core_manifest.json @@ -4095,7 +4095,7 @@ "Default": false }, { - "Name": "LowerBoundConfidenceColumn", + "Name": "ConfidenceLowerBoundColumn", "Type": "String", "Desc": "The name of the confidence interval lower bound column.", "Aliases": [ @@ -4107,7 +4107,7 @@ "Default": null }, { - "Name": "UpperBoundConfidenceColumn", + "Name": "ConfidenceUpperBoundColumn", "Type": "String", "Desc": "The name of the confidence interval upper bound column.", "Aliases": [ diff --git a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesDirectApi.cs b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesDirectApi.cs index 00b8ec6613..85bac94fff 100644 --- a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesDirectApi.cs +++ b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesDirectApi.cs @@ -338,8 +338,8 @@ public void SsaForecast() ConfidenceLevel = 0.95f, Source = "Value", Name = "Forecast", - LowerBoundConfidenceColumn = "MinCnf", - UpperBoundConfidenceColumn = "MaxCnf", + ConfidenceLowerBoundColumn = "MinCnf", + ConfidenceUpperBoundColumn = "MaxCnf", WindowSize = 10, SeriesLength = 11, TrainSize = 22, @@ -397,8 +397,8 @@ public void SsaForecastPredictionEngine() SeriesLength = 11, TrainSize = 22, Horizon = 4, - LowerBoundConfidenceColumn = "ConfidenceLowerBound", - UpperBoundConfidenceColumn = "ConfidenceUpperBound", + ConfidenceLowerBoundColumn = "ConfidenceLowerBound", + ConfidenceUpperBoundColumn = "ConfidenceUpperBound", VariableHorizon = true }; @@ -413,8 +413,8 @@ public void SsaForecastPredictionEngine() var model = ml.Transforms.Text.FeaturizeText("Text_Featurized", "Text") .Append(ml.Transforms.Conversion.ConvertType("Value", "Value", DataKind.Single)) .Append(ml.Forecasting.ForecastBySsa("Forecast", "Value", 10, 11, 22, 4, - lowerBoundConfidenceColumn: "ConfidenceLowerBound", - upperBoundConfidenceColumn: "ConfidenceUpperBound", variableHorizon: true)) + confidenceLowerBoundColumn: "ConfidenceLowerBound", + confidenceUpperBoundColumn: "ConfidenceUpperBound", variableHorizon: true)) .Append(ml.Transforms.Concatenate("Forecast", "Forecast", "ConfidenceLowerBound", "ConfidenceUpperBound")) .Fit(dataView); diff --git a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesEstimatorTests.cs b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesEstimatorTests.cs index ee1b40156e..d9fe04bccd 100644 --- a/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesEstimatorTests.cs +++ b/test/Microsoft.ML.TimeSeries.Tests/TimeSeriesEstimatorTests.cs @@ -95,8 +95,8 @@ void TestSsaForecastingEstimator() // Train var pipe = new SsaForecastingEstimator(Env, "Forecast", "Value", 10, 11, 22, 4, - lowerBoundConfidenceColumn: "ConfidenceLowerBound", - upperBoundConfidenceColumn: "ConfidenceUpperBound"); + confidenceLowerBoundColumn: "ConfidenceLowerBound", + confidenceUpperBoundColumn: "ConfidenceUpperBound"); var xyData = new List { new TestDataXY() { A = new float[inputSize] } }; var stringData = new List { new TestDataDifferntType() { data_0 = new string[inputSize] } };