Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.ML.TimeSeries/ExtensionsCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public static SrCnnAnomalyEstimator DetectAnomalyBySrCnn(this TransformsCatalog
/// <param name="shouldStabilize">The flag determining whether the model should be stabilized.</param>
/// <param name="shouldMaintainInfo">The flag determining whether the meta information for the model needs to be maintained.</param>
/// <param name="maxGrowth">The maximum growth on the exponential trend.</param>
/// <param name="lowerBoundConfidenceColumn">The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="upperBoundConfidenceColumn">The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="confidenceLowerBoundColumn">The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="confidenceUpperBoundColumn">The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="confidenceLevel">The confidence level for forecasting.</param>
/// <param name="variableHorizon">Set this to true if horizon will change after training(at prediction time).</param>
/// <example>
Expand All @@ -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);
}
}
30 changes: 15 additions & 15 deletions src/Microsoft.ML.TimeSeries/SSaForecasting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -258,8 +258,8 @@ public sealed class SsaForecastingEstimator : IEstimator<SsaForecastingTransform
/// <param name="shouldStabilize">The flag determining whether the model should be stabilized.</param>
/// <param name="shouldMaintainInfo">The flag determining whether the meta information for the model needs to be maintained.</param>
/// <param name="maxGrowth">The maximum growth on the exponential trend.</param>
/// <param name="lowerBoundConfidenceColumn">The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="upperBoundConfidenceColumn">The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="confidenceLowerBoundColumn">The name of the confidence interval lower bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="confidenceUpperBoundColumn">The name of the confidence interval upper bound column. If not specified then confidence intervals will not be calculated.</param>
/// <param name="confidenceLevel">The confidence level for forecasting.</param>
/// <param name="variableHorizon">Set this to true if horizon will change after training.</param>
internal SsaForecastingEstimator(IHostEnvironment env,
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down
26 changes: 13 additions & 13 deletions src/Microsoft.ML.TimeSeries/SequentialForecastingTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -57,18 +57,18 @@ internal abstract class SequentialForecastingTransformBase<TInput, TState> : 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)
{
}

Expand Down Expand Up @@ -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
{
Expand All @@ -156,7 +156,7 @@ public Func<int, bool> GetDependencies(Func<int, bool> activeOutput)
public Delegate[] CreateGetters(DataViewRow input, Func<int, bool> 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))
{
Expand All @@ -168,7 +168,7 @@ public Delegate[] CreateGetters(DataViewRow input, Func<int, bool> activeOutput,
getters[0] = valueGetter;
}

if (!string.IsNullOrEmpty(_parent.ForecastingConfidenceIntervalMaxOutputColumnName))
if (!string.IsNullOrEmpty(_parent.ConfidenceUpperBoundColumn))
{
if (activeOutput(1))
{
Expand Down
24 changes: 12 additions & 12 deletions src/Microsoft.ML.TimeSeries/SequentialTransformerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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);
}
Expand Down Expand Up @@ -480,8 +480,8 @@ public SequentialDataTransform(IHost host, SequentialTransformerBase<TInput, TOu
Metadata = new MetadataDispatcher(3);
_parent = parent;
_transform = CreateLambdaTransform(_parent.Host, input, _parent.InputColumnName,
_parent.OutputColumnName, _parent.ForecastingConfidenceIntervalMinOutputColumnName,
_parent.ForecastingConfidenceIntervalMaxOutputColumnName, InitFunction, _parent.WindowSize > 0, _parent.OutputColumnType);
_parent.OutputColumnName, _parent.ConfidenceLowerBoundColumn,
_parent.ConfidenceUpperBoundColumn, InitFunction, _parent.WindowSize > 0, _parent.OutputColumnType);

_mapper = mapper;
_bindings = new ColumnBindings(input.Schema, _mapper.GetOutputColumns());
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.TimeSeries/SsaForecastingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ internal sealed class SsaForecastingBase : SequentialForecastingTransformBase<fl
internal SequenceModelerBase<Single, Single> 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;
Horizon = options.Horizon;
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();
Expand Down
Loading