Below is the example of using the GetMs operation to calculate an equation. The request contains an instance of opened modeling container, equation calculation pattern, and parameters of operation execution. The response contains an instance of the model that contains an equation with calculation results.
To execute the example the equation must be calculated using the Non-Linear Regression method.
{ "GetMs" : { "tMs" : { "id" : "CGNGLNJJAFNBFOAEAMLDKJBMDFDMIKBECLCCPAGGMMNHDHAO!M!S!CCFELIOJJAFNBFOAEGCJLMLPJNCHIHJEEHKPLONIGDEKIBJDL" }, "tArg" : { "pattern" : { "obInst" : "false", "all" : "false", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Get", "calcChainPattern" : { "modelPattern" : { "transform" : { "outputs" : "Get", "formulaCount" : "true", "formulas" : { "method" : { "series" : "true" } }, "displayId" : "true", "equationsFormula" : { "method" : "" }, "series" : "Get", "kind" : "true", "displaySettings" : "true", "additionalAttributes" : "true", "calculationType" : "true", "calculationDirection" : "true", "transformVariable" : { "slices" : "Get", "transformSlice" : { "selection" : "Get" } } }, "stochastic" : "true", "calculationPeriod" : "true", "useModelPeriod" : "true", "useExistingData" : "true", "treatNullsAsZeros" : "true", "autoName" : "true", "generatedName" : "true", "period" : "true", "isExclusive" : "true", "useAutoPeriod" : "true" }, "entryKeys" : { "l" : "4" } } } } } }, "execParams" : { "k" : "0", "modelKeys" : { "l" : "4" }, "scenarioKeys" : "", "execMethod" : "true", "execEvaluateSeries" : "true", "execIsCoefficientsSaved" : "true", "execStatCoefficients" : "true" } } } }
{ "GetMsResult" : { "id" : { "id" : "CGNGLNJJAFNBFOAEAMLDKJBMDFDMIKBECLCCPAGGMMNHDHAO!M!S!CCFELIOJJAFNBFOAEGCJLMLPJNCHIHJEEHKPLONIGDEKIBJDL" }, "meta" : { "item" : { "k" : "89669", "id" : "MODEL_NEW", "n" : "MODEL_NEW", "vis" : "1", "type" : "Problem", "problemMd" : { "metamodel" : { "k" : "89670", "calculationChain" : { "its" : { "Item" : { "k" : "4", "id" : "OBJ4", "n" : "MyOutputVavable|A[t] = MyInputVavable|A[t] * a + b, 1990A1-2010A1", "vis" : "1", "type" : "Model", "excluded" : "0", "graphMeta" : "", "model" : { "transform" : { "outputs" : { "its" : { "Item" : { "k" : "1", "id" : "VARIABLES_89670", "n" : "Variables", "vis" : "1", "slices" : { "its" : { "Item" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" } } }, "variableStubKey" : "89671", "parameterID" : "", "kind" : "Stub", "attributeId" : "", "attributeType" : "Series" } } }, "formulaCount" : "1", "formulas" : { "its" : { "it" : [ { "k" : "0", "kind" : "NonLinearRegression", "method" : { "nonLinearRegression" : { "missingData" : { "specifiedVector" : "", "method" : "LinTrend", "methodParameter" : "5", "specifiedValue" : "0", "specifiedTerm" : { "k" : "4294967295" } }, "confidenceLevel" : "0.9", "useDerivatives" : "1", "initialApproximation" : { "d" : [ "0.15", "0.09" ] }, "maxIterations" : "500", "maxStep" : "0.4", "dampingFactorTolerance" : "0.6", "expression" : "@_2:0[] * a + b", "result" : { "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "lag" : "", "key" : "0", "termToText" : "{MyOutputVavable|A[t]}", "termToInnerText" : "@_1:0[]", "termInfo" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "0" }, "operands" : { "its" : { "Item" : [ { "k" : "0", "slice" : { "k" : "0", "id" : "MyInputVavable|A", "n" : "MyInputVavable|A", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "lag" : "1", "key" : "1", "termToText" : "{TS(MyInputVavable|A[t+1], Linear)}", "termToInnerText" : "@_2:0[1][9:0]", "termInfo" : { "k" : "4294967295", "lag" : "1", "inversion" : { "type" : "TS", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyInputVavable|A", "n" : "MyInputVavable|A", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "0" }, { "k" : "1", "slice" : { "k" : "0", "id" : "MyInputVavable|A", "n" : "MyInputVavable|A", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "lag" : "0", "key" : "2", "termToText" : "{MyInputVavable|A[t]}", "termToInnerText" : "@_2:0[]", "termInfo" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyInputVavable|A", "n" : "MyInputVavable|A", "vis" : "1", "variableKey" : "2", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "1" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "1" } ] } }, "coefficients" : { "it" : [ "a", "b" ] }, "isCoefficientsSaved" : "0", "statCoefficients" : { "its" : { "Item" : [ { "estimate" : "-0.07833068250940456", "standardError" : "0.04307364909196183", "tStatistic" : "-1.818529058036604", "probability" : "0.08900474700852867" }, { "estimate" : "4.374510772763077", "standardError" : "0.6880094965630595", "tStatistic" : "6.358212778480349", "probability" : "1.285011021923133e-05" } ] } }, "optimizationMethod" : "LevenbergMarquardt", "tolerance" : "0.0001", "useDefaultInitValues" : "0" }, "name" : "X2 * (-0.0783) + 4.3745", "series" : { "input" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "addFactor" : { "k" : "4294967295" } }, "evaluateSeries" : { "its" : { "Item" : { "scenarioKey" : "4294967295", "fact" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714" ] }, "modelling" : { "d" : [ "4.296180090253672", "4.061188042725458", "4.217849407744268", "3.826195995197245", "3.787030653942542", "3.661701561927495", "3.536372469912448", "3.4110433778974", "3.285714285882353", "3.160385193867306", "3.035056101852258", "2.909727009837211", "2.784397917822164", "2.659068825807117", "2.53373973379207", "2.408410641777022", "2.283081549761975" ] }, "residuals" : { "d" : [ "-1.296180090253672", "2.938811957274542", "-2.217849407744268", "2.173804004802755", "0.2129693460574575", "-2.661701561927495", "1.463627530087552", "0.01752805210259956", "4.117647112167333e-09", "-0.01752805386730616", "-0.03505610185225816", "-0.05258414983721105", "-0.07011220782216387", "-0.08764025580711676", "-0.1051683037920697", "-0.1226963517770217", "-0.1402244097619749" ] }, "input" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714", "2", "1.85714286", "1.71428571", "1.57142857" ] }, "factors" : { "its" : { "it" : [ { "termToText" : "{MyInputVavable|A[t]}", "serie" : { "d" : [ "1", "4", "2", "7", "7.5", "9.1", "10.7", "12.3", "13.9", "15.5", "17.1", "18.7", "20.3", "21.9", "23.5", "25.1", "26.7", "28.3", "29.9", "31.5", "33.1" ] }, "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "entryKey" : "1" } ] } } } }, "dates" : { "it" : [ "1990A1", "1991A1", "1992A1", "1993A1", "1994A1", "1995A1", "1996A1", "1997A1", "1998A1", "1999A1", "2000A1", "2001A1", "2002A1", "2003A1", "2004A1", "2005A1", "2006A1", "2007A1", "2008A1", "2009A1", "2010A1" ] } }, "inversionInfo" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "doUseR" : "0", "supportsR" : "1" }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ] } }, "displayId" : "0", "series" : { "its" : "" }, "kind" : "Simple", "displaySettings" : { "displayTermsAs" : "Derive" }, "additionalAttributes" : "", "calculationType" : "Serie", "calculationDirection" : "Forward" }, "stochastic" : "1", "calculationPeriod" : "Forecast", "useModelPeriod" : "1", "useExistingData" : "0", "treatNullsAsZeros" : "0", "autoName" : "1", "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2006-01-01", "forecastStartDate" : "2006-01-02", "forecastEndDate" : "2010-01-01", "identificationStartDateParamID" : "", "identificationEndDateParamID" : "", "forecastStartDateParamID" : "", "forecastEndDateParamID" : "", "autoPeriod" : "0", "identificationStartOffset" : "0", "identificationEndOffset" : "0", "forecastEndOffset" : "0", "isIdentStartCorrect" : "1", "isIdentEndCorrect" : "1", "isForecastEndCorrect" : "1" }, "isExclusive" : "1", "useAutoPeriod" : "0", "generatedName" : "MyOutputVavable|A[t] = MyInputVavable|A[t] * a + b", "warnings" : "", "readOnly" : "0" } } } }, "visualController" : { "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "useScenarios" : "0", "readOnly" : "0" } } } } }
The GetMsNonLinearRegr function calculates the specified equation. Input parameters:
ms. Opened modeling container instance.
modelKey. Key of the model that contains the equation.
eqKey. Equation key.
After executing the function returns a model that contains calculated equation. Calculation results are displayed in the console window. The following auxiliary procedures described in the Calculating Equation section are used to output the results: PrintArray and PrintSeries.
public static MsCalculationChainEntry GetMsNonLinearRegr(MsId ms, ulong modelKey, ulong eqKey) { var getMsOp = new GetMs(); // Set operation execution parameters getMsOp.tMs = ms; getMsOp.tArg = new GetMsArg() { // Set data getting pattern pattern = new MsMdPattern() { obInst = false, all = false, item = new MsItemPattern() { // Specify calculated model class key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { // Specify calculated equation key entryKeys = new long[] { (long)eqKey }, modelPattern = new MsModelPattern() { autoName = true, calculationPeriod = true, generatedName = true, isExclusive = true, period = true, stochastic = true, treatNullsAsZeros = true, useAutoPeriod = true, useExistingData = true, useModelPeriod = true, transform = new MsFormulaTransformPattern() { additionalAttributes = true, calculationDirection = true, calculationType = true, displayId = true, displaySettings = true, formulaCount = true, outputs = ListOperation.Get, series = ListOperation.Get, kind = true, formulas = new TsFormulaPattern() { method = new TsMethodPattern() { series = true } }, equationsFormula = new TsFormulaPattern() { method = new TsMethodPattern() { } }, transformVariable = new MsFormulaTransformVariablePattern() { slices = ListOperation.Get, transformSlice = new MsFormulaTransformSlicePattern() { selection = ListOperation.Get } } } } } } } } }, // Set equation calculation parameters execParams = new MsMdExecParams() { k = 0, execMethod = true, execEvaluateSeries = true, scenarioKeys = new long[] { }, execStatCoefficients = true, execIsCoefficientsSaved = true, modelKeys = new long[] { (long)eqKey } } }; // Create a proxy object for operation execution var somClient = new SomPortTypeClient(); GetMsResult getMsResult = somClient.GetMs(getMsOp); MsMetaModel meta = getMsResult.meta.item.problemMd.metamodel; MsCalculationChainEntry chainEntry = meta.calculationChain.its.GetValue(0) as MsCalculationChainEntry; // Display errors and warnings MsModel eq = chainEntry.model; if (eq.warnings != null) { Console.WriteLine("-- Warnings --"); Console.WriteLine("".PadRight(3) + printArray(eq.warnings)); } if (eq.error == null) //Check if errors occurred on equation calculation { // Equation is calculated without errors, get calculation results TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula; TsNonLinearRegressionMethod nonLinR = formula.method.nonLinearRegression; Console.WriteLine("-- Coefficients --"); Console.WriteLine("".PadRight(3) + printArray(nonLinR.coefficients)); Console.WriteLine("".PadRight(3) + "- saved: " + nonLinR.isCoefficientsSaved); Console.WriteLine("-- Coefficient values --"); Console.WriteLine("".PadRight(3) + printArray(nonLinR.coefficientsData)); // Get equation coefficient values and display into console window Console.WriteLine("-- Detailed description of coefficients --"); StatConstCoefficientsArr cArr = nonLinR.statCoefficients; Console.WriteLine("".PadRight(3) + "- accuracy of solution: " + cArr.precision); int i = 0; foreach (StatConstCoefficients n in cArr.its) { Console.WriteLine("".PadRight(3) + "Coefficient '" + nonLinR.coefficients.GetValue(i) + "'"); Console.WriteLine("".PadRight(6) + " - value: " + n.estimate); Console.WriteLine("".PadRight(6) + " - standard error: " + n.standardError); Console.WriteLine("".PadRight(6) + " - t-statistics: " + n.tStatistic); Console.WriteLine("".PadRight(6) + " - probability: " + n.probability); i++; } // Get calculated values and display into console window MsEvaluateSeriesResult seriesRes = formula.method.evaluateSeries; printSeries(seriesRes); } else // Errors occurred on equation calculation { Console.WriteLine("-- Errors --"); Console.WriteLine(eq.error); } // Return the model that contains equation return chainEntry; }
See also:
GetMs: Operation | The Non-Linear Regression Method