Aggregator: BasicAggregatorOperation;
The Aggregator property determines how the aggregation is applied to elements of the slice on calculating the model.
Sub Main;
Var
MB: IMetabase;
CrInf: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Model: IMsModel;
Trans: IMsFormulaTransform;
VarTrans: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
NonLinear: IMsNonLinearRegressionTransform;
Varr: IMsVariable;
TransVar: IMsFormulaTransformVariable;
TermX1: IMsFormulaTerm;
SelectionFact: IDimSelectionSetFactory;
Selection: IDimSelectionSet;
s: String;
i: Integer;
Begin
MB := MetabaseClass.Active;
//create a model
CrInf := Mb.CreateCreateInfo;
CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;
CrInf.Id := "New_NonLinReg";
CrInf.Name := "New_NonLinReg";
CrInf.Parent := Mb.ItemById("KONT_MODEL");
CrInf.Permanent := False;
MObj := Mb.CreateObject(CrInf).Edit;
Model := MObj As IMsModel;
Trans := Model.Transform;
// add output variable
Varr := MB.ItemByIdNamespace("Var_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Output.Add(Varr);
VarTrans := Trans.Outputs.Item(0);
Tree := VarTrans.SlicesTree(VarTrans);
Slice := Tree.CreateSlice(1);
Selector := Model.Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.NonLinearRegression;
NonLinear := Formula.Method As IMsNonLinearRegressionTransform;
//adding a factor
Varr := MB.ItemByIdNamespace("Var_Factor", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Input.Add(Varr);
SelectionFact := New DimSelectionSetFactory.Create;
Selection := SelectionFact.CreateDimSelectionSet;
//additional dimensions selection modifying
For i := 0 To Varr.Dimensions.Count - 1 Do
Selection.Add((Varr.Dimensions.Item(i).Model As IMetabaseObject).Open(Null) As IDimInstance);
Selection.Item(i).DeselectAll;
Selection.Item(i).SelectElement(3, False);
End For;
TransVar := Model.Transform.Inputs.Item(0);
Slice := TransVar.Slices.Add(Selection);
Slice.Aggregator := BasicAggregatorOperation.Max;
TermX1 := NonLinear.Operands.Add(Slice);
//creation of the equation
s := "A0+" + TermX1.TermToInnerText + "/10";
NonLinear.Expression.AsString := s;
MObj.Save;
End Sub Main;
After executing the example a model is created in the modeling container. An output variable is added to the model; element with the index 3 is selected in all additional dimensions of this variable. Specification of calculation is adjusted for the received slice. The method of non-linear regression is used for calculation. A variable is added to the input variables list, fixation by additional dimensions and data aggregation mode are modified for it. Then terms are obtained, and the equation is composed.
See also: