Show contents 

Ms > Examples > Calculating a Model

Calculating a Model

Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier. The MODEL_1 model is contained in the container, it is set up to calculation that uses the universal trend method.

Add links to the Metabase, Ms, Stat system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Model: IMsModel;
    Trans: IMsFormulaTransform;
    TransVar: IMsFormulaTransformVariable;
    Tree: IMsFormulaTransformSlicesTree;
    Selector: IMsFormulaTransformSelector;
    CurveEst: IMsCurveEstimationTransform;
    Coo: IMsFormulaTransformCoord;
    Calc: IMsMethodCalculation;
    Period: IMsModelPeriod;
    Result: IMsModelCalculationResult;
    SmCurve: ISmCurveEstimation;
    Ar: Array Of double;
    i: Integer;
Begin
    MB := MetabaseClass.Active;
    //Calculated model
    Model := MB.ItemByIdNamespace("MODEL_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsModel;
    Trans := Model.Transform;
    TransVar := Trans.Outputs.Item(0);
    Tree := TransVar.SlicesTree(TransVar);
    Selector := Trans.CreateSelector;
    Selector.Slice := Tree.CreateSlice(1);
    CurveEst := Trans.Transform(Selector).Method As IMsCurveEstimationTransform;
    //Coordinate, by which calculation is executed
    Coo := Trans.CreateCoord(TransVar);
    Calc := Trans.CreateCalculation;
    //Set sample and forecasting periods
    Period := Calc.Period;
    Period.IdentificationStartDate := Trans.Period.IdentificationStartDate;
    Period.IdentificationEndDate := Trans.Period.IdentificationEndDate;
    Period.ForecastStartDate := Trans.Period.ForecastStartDate;
    Period.ForecastEndDate := Trans.Period.ForecastEndDate;
    //Calculate model with the use of the best dependency form
    Result := CurveEst.Execute(Calc, Coo);
    SmCurve := Result.StatMethod As ISmCurveEstimation;
    Debug.WriteLine("Smoothed series");
    Ar := SmCurve.DependenceForms.Item(0).Fitted;
    For i := 0 To Ar.Length - 1 Do
        Debug.WriteLine(Ar[i]);
    End For;
    Debug.WriteLine(Forecast);
    Ar := SmCurve.DependenceForms.Item(0).Forecast.Value;
    For i := 0 To Ar.Length - 1 Do
        Debug.WriteLine(Ar[i]);
    End For
End Sub UserProc;

After executing the example the model is calculated. The smoothed series and forecasting values obtained as a calculation result are displayed in the development environment console.

See also:

Examples