IModelling.MedianSmooth

Fore Syntax

MedianSmooth(Input: ITimeSeries;
            Period: IMsPeriod;
            [WindowSize: Integer = 5];

            [Casewise: MsCasewise = 0]): Variant;

Fore.NET Syntax

MedianSmooth(Input: Prognoz.Platform.Interop.Ms.ITimeSeries;
             Period: Prognoz.Platform.Interop.Ms.IMsPeriod;
             WindowSize: integer;

             Casewise: Prognoz.Platform.Interop.Ms.MsCasewise;
             Context: Prognoz.Platform.Interop.Fore.ForeRuntimeContext): object;

Parameters

Input. Output variable.

Period. Period, at which the method is calculated. If the parameter is set to Null, the method is calculated at the entire time period.

WindowSize. Window size.

Casewise. Missing data treatment method.

Context. Context. The parameter is used only in Fore.NET.

Description

The MedianSmooth method models the variable by using median smoothing.

Comments

The main advantage of median smoothing is its robustness to outliers.

Fore Example

Executing the example requires that the repository contains a modeling container with the MS identifier. A model with the MODEL_D identifier calculated by the method of determinate equation and containing at least one input variable must be available in this container.

Add links to the Metabase, Ms system assemblies.

Sub ProcMedianSmooth;
Var
    Mb: IMetabase;
    ModelSpace, ModelObj: IMetabaseObject;
    Transf: IMsFormulaTransform;
    Formula: IMsFormula;
    Model: IMsModel;
    Determ: IMsDeterministicTransform;
    TransVar: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
    TermInfo: IMsFormulaTermInfo;
    Expr: IExpression;
Begin
    Mb := MetabaseClass.Active;
    ModelSpace := Mb.ItemById(
"MS").Bind;
    ModelObj := Mb.ItemByIdNamespace(
"MODEL_D", ModelSpace.Key).Edit;
    Model := ModelObj 
As IMsModel;
    Transf := Model.Transform;
    Formula := Transf.FormulaItem(
0);
    Determ := Formula.Method 
As IMsDeterministicTransform;
    TransVar := Transf.Inputs.Item(
0);
    Slice := TransVar.Slices.Item(
0);
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;
    TermInfo.Type := MsFormulaTermType.Pointwise;
    Expr := Determ.Expression;
    Expr.References := 
"Ms";
    
Expr.AsString := "MedianSmooth(" + TermInfo.TermInnerText + ", SetPeriod(" +
        
"""" + "01.01.2000" + """" + "," + """" + "01.01.2015" + """" + "), 5, MsCasewise.Yes)";
    
If Expr.Valid
        
Then ModelObj.Save;
        
Else Debug.WriteLine("The model is not saved: error in formula");
    
End If;
End Sub ProcMedianSmooth;

After executing the example the model will transform the first input variable by the method of median smoothing at the period of 2000-2015. The calculation is executed by the Casewise missing data treatment method.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.ForeSystem;

Public Shared Sub Main(Params: StartParams);
Var
    Mb: IMetabase;
    ModelSpace, ModelObj: IMetabaseObject;
    Transf: IMsFormulaTransform;
    Formula: IMsFormula;
    Model: IMsModel;
    Determ: IMsDeterministicTransform;
    TransVar: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
    TermInfo: IMsFormulaTermInfo;
    Expr: IExpression;
Begin
    Mb := Params.Metabase;
    ModelSpace := Mb.ItemById["MS"].Bind();
    ModelObj := Mb.ItemByIdNamespace["MODEL_D", ModelSpace.Key].Edit();
    Model := ModelObj As IMsModel;
    Transf := Model.Transform;
    Formula := Transf.FormulaItem[0];
    Determ := Formula.Method As IMsDeterministicTransform;
    TransVar := Transf.Inputs.Item[0];
    Slice := TransVar.Slices.Item[0];
    TermInfo := Transf.CreateTermInfo();
    TermInfo.Slice := Slice;
    TermInfo.Type := MsFormulaTermType.mfttPointwise;
    Expr := Determ.Expression;
    Expr.References := "Ms";
    Expr.AsString := "MedianSmooth(" + TermInfo.TermInnerText + ", SetPeriod(" +
        """" + "01.01.2000" + """" + "," + """" + "01.01.2015" + """" + "), 5, MsCasewise.Yes)";
    If Expr.Valid
        Then ModelObj.Save();
        Else System.Diagnostics.Debug.WriteLine("Model is not saved: error in formulaquot;);
    End If;
End Sub;

Example of Use in Expressions

Expression 1:

MedianSmooth({Brazil|BCA}, SetPeriod("01.01.2000", "01.01.2015"), 5, MsCasewise.Yes)

Result: for the Brazil|BCA factor, the median smoothing (window size is five) is applied at the period of 2000-2015, the calculation is executed by the Casewise missing data treatment method.

Use: it can be used in formulas of calculated series of time series database and model formulas of modeling container that is a child of the time series database.

Expression 2:

MedianSmooth(X1, SetPeriod("01.01.2000", "01.01.2015"), 7, MsCasewise.Yes)

Result: for the X1 factor, the median smoothing is applied (window size is seven) at the period 2000-2015, the calculation is executed by the Casewise missing data treatment method.

Use: it can be used in model formulas of modeling container.

See also:

IModelling | The Calculation Method  Median Smoothing | Time Series Database: Calculator | Modeling Container: Editing Regressor or Formula