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 with the Extrapolate method.
The C# example uses the PrintStat, PrintCoef, PrintSeries auxiliary procedures to display results described in the Equation Calculation section.
{ "GetMs" : { "tMs" : { "id" : "JNLCLHMGDNMBFOAELPKIJBHANNONPCBEIJFLOLMEADGBMGDH!M!S!CEOONGIMGDNMBFOAELALNGGIOBDBEJFMELJOJAOPDLFDOADIF" }, "tArg" : { "pattern" : { "obInst" : "true", "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", "execSummaryStatistics" : "true", "execCoefficients" : "true", "execEvaluateSeries" : "true", "execStatCoefficients" : "true", "execGenerateName" : "true" } } } }
{ "GetMsResult" : { "id" : { "id" : "JNLCLHMGDNMBFOAELPKIJBHANNONPCBEIJFLOLMEADGBMGDH!M!S!CEOONGIMGDNMBFOAELALNGGIOBDBEJFMELJOJAOPDLFDOADIF" }, "meta" : { "obInst" : { "obDesc" : { "@fullUrl" : "http:\/\/v-shp-development.dev.fs.fsight.world\/", "@isShortcut" : "0", "@isLink" : "0", "@ver" : "4", "@hf" : "0", "i" : "MODELSPACE", "n" : Modeling container", "k" : "1581", "c" : "5121", "p" : "1580", "h" : "0", "hasPrv" : "0", "ic" : "0", "isPermanent" : "1", "isTemp" : "0" } }, "dirty" : "0", "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] = Trend(MyInputVavable[t]), (From parent)-(From parent)", "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" : "CurveEstimation", "method" : { "curveEstimation" : { "criterion" : "R2", "dependenceForm" : "Linear", "dependenceFormIncluded" : { "it" : [ "Linear", "Polynomial", "Logarithmic" ] }, "polynomOrder" : "4", "seasonalComponent" : { "mode" : "Additive", "cycle" : "4" }, "missingData" : { "specifiedVector" : "", "method" : "Casewise", "methodParameter" : "5", "specifiedValue" : "0", "specifiedTerm" : { "k" : "4294967295" } }, "confidenceLevel" : "0.96", "bestDependenceForm" : "Polynomial", "value" : "0", "explained" : { "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" }, "dependenceForms" : { "its" : { "Item" : [ { "dependenceForm" : "Linear", "expression" : "A1*t + A0", "statCoefficients" : { "intercept" : { "mode" : "AutoEstimate", "estimate" : "-0.4928571428571348", "standardError" : "0.2910409353847357", "tStatistic" : "-1.693428940522103", "probability" : "0.1018820994993999" }, "coefficients" : { "estimate" : { "d" : "1.598351648351648" }, "standardError" : { "d" : "0.01498937077595134" }, "tStatistic" : { "d" : "106.6323378240808" }, "probability" : { "d" : "0" } } }, "criterionValue" : "0.9981691131922996", "summaryStatistics" : { "stR2" : "0.9981691131922996", "stAdjR2" : "0.9980928262419788", "stR2_2" : "0.9981691131922996", "stAdjR2_2" : "0.9980928262419788", "stSE" : "0.5350176585813732", "stSSR" : "6.869853479853474", "stLogL" : "-19.59000298921173", "stDW" : "3.366608997117618", "stDWLowerBound" : "5.226173552036746e-05", "stDWUpperBound" : "6.112166540301281e-06", "stSD" : "12.25104077211402", "stAIC" : "1.660769460708595", "stSC" : "1.757546117479478", "stFstat_2" : "13084.40184060549", "stProbFstat_2" : "0", "stFstat" : "13084.40184060549", "stProbFstat" : "0", "stME" : "-3.552713678800501e-15", "stMAE" : "0.31025641025641", "stMSE" : "0.2642251338405183", "stMaxAE" : "1.933150183150188", "stSqMSE" : "0.5140283395305343", "stVE" : "0.2642251338405183", "stSEE" : "0.5140283395305344", "stMD" : "21.1", "stHQcriterion" : "1.688637636217742", "stAvgLogL" : "NaN", "stMcFaddenRsquared" : "NaN", "stRestrLogL" : "NaN", "stLRstatistic" : "NaN", "stLRprobability" : "NaN", "stIncludedObservations" : "26", "stJstat" : "NaN", "stProbJstat" : "NaN", "stNumOfIter" : "-1", "stJBStat" : "46.45284363973704", "stProbJBStat" : "8.182632349473806e-11" }, "errors" : "" }, { "dependenceForm" : "Polynomial", "expression" : "An*t^n + ... + A2*t^2 + A1*t + A0", "statCoefficients" : { "intercept" : { "mode" : "AutoEstimate", "estimate" : "-0.465181344869594", "standardError" : "0.7871206378330464", "tStatistic" : "-0.590991167694757", "probability" : "0.5594417347097805" }, "coefficients" : { "estimate" : { "d" : [ "1.582420928890241", "0.001388551345301276", "-4.994188660429374e-06", "-1.199216706196811e-06" ] }, "standardError" : { "d" : [ "0.392724727858397", "0.05749696262512111", "0.003169750766421726", "5.829715944935267e-05" ] }, "tStatistic" : { "d" : [ "4.029338660489969", "0.02414999474588944", "-0.001575577712082147", "-0.02057075709218157" ] }, "probability" : { "d" : [ "0.0007867132522725306", "0.9809986801874817", "0.9987602020207836", "0.9838143840419024" ] } } }, "criterionValue" : "0.9981742366165919", "summaryStatistics" : { "stR2" : "0.9981742366165919", "stAdjR2" : "0.9978264721626093", "stR2_2" : "0.9981742366165919", "stAdjR2_2" : "0.9978264721626093", "stSE" : "0.5711571115361268", "stSSR" : "6.850629367224124", "stLogL" : "-19.55357371328806", "stDW" : "3.374546243247101", "stDWLowerBound" : "0.000686446402999863", "stDWUpperBound" : "3.749894734120952e-09", "stSD" : "12.25104077211402", "stAIC" : "1.888736439483697", "stSC" : "2.130678081410905", "stFstat_2" : "2870.259525336149", "stProbFstat_2" : "0", "stFstat" : "2870.259525336149", "stProbFstat" : "0", "stME" : "-1.084602493287653e-15", "stMAE" : "0.3119376087872172", "stMSE" : "0.2634857448932355", "stMaxAE" : "1.920839385280324", "stSqMSE" : "0.5133086253836336", "stVE" : "0.2634857448932355", "stSEE" : "0.5133086253836336", "stMD" : "21.1", "stHQcriterion" : "1.958406878256565", "stAvgLogL" : "NaN", "stMcFaddenRsquared" : "NaN", "stRestrLogL" : "NaN", "stLRstatistic" : "NaN", "stLRprobability" : "NaN", "stIncludedObservations" : "26", "stJstat" : "NaN", "stProbJstat" : "NaN", "stNumOfIter" : "-1", "stJBStat" : "44.27599282059314", "stProbJBStat" : "2.429910717083317e-10" }, "errors" : "" }, { "dependenceForm" : "Logarithmic", "expression" : "A1*ln(t) + A0", "statCoefficients" : { "intercept" : { "mode" : "AutoEstimate", "estimate" : "-9.757959888305843", "standardError" : "3.272527297090876", "tStatistic" : "-2.981781052515655", "probability" : "0.006007865777448607" }, "coefficients" : { "estimate" : { "d" : "13.5959840407783" }, "standardError" : { "d" : "1.206750999298278" }, "tStatistic" : { "d" : "11.26660267833573" }, "probability" : { "d" : "1.035826979745025e-11" } } }, "criterionValue" : "0.8590172900274078", "summaryStatistics" : { "stR2" : "0.8590172900274078", "stAdjR2" : "0.8531430104452165", "stR2_2" : "0.8590172900274078", "stAdjR2_2" : "0.8531430104452165", "stSE" : "4.694834592219236", "stSSR" : "528.9953243591607", "stLogL" : "-76.05988158036546", "stDW" : "0.2565964910183629", "stDWLowerBound" : "1.273053136754938e-09", "stDWUpperBound" : "2.323162006230125e-11", "stSD" : "12.25104077211402", "stAIC" : "6.004606275412727", "stSC" : "6.10138293218361", "stFstat_2" : "146.2336407398165", "stProbFstat_2" : "1.065614263495718e-11", "stFstat" : "146.2336407398165", "stProbFstat" : "1.065614263495718e-11", "stME" : "-3.962642180200559e-15", "stMAE" : "3.81749483888947", "stMSE" : "20.34597401381387", "stMaxAE" : "10.75795988830584", "stSqMSE" : "4.510651174033953", "stVE" : "20.34597401381387", "stSEE" : "4.510651174033953", "stMD" : "21.1", "stHQcriterion" : "6.032474450921874", "stAvgLogL" : "NaN", "stMcFaddenRsquared" : "NaN", "stRestrLogL" : "NaN", "stLRstatistic" : "NaN", "stLRprobability" : "NaN", "stIncludedObservations" : "26", "stJstat" : "NaN", "stProbJstat" : "NaN", "stNumOfIter" : "-1", "stJBStat" : "1.964796154276888", "stProbJBStat" : "0.374412152187965" }, "errors" : "" } ] } } }, "summaryStatistics" : { "stR2" : "0.9981742366165919", "stAdjR2" : "0.9978264721626093", "stR2_2" : "0.9981742366165919", "stAdjR2_2" : "0.9978264721626093", "stSE" : "0.5711571115361268", "stSSR" : "6.850629367224124", "stLogL" : "-19.55357371328806", "stDW" : "3.374546243247101", "stDWLowerBound" : "0.000686446402999863", "stDWUpperBound" : "3.749894734120952e-09", "stSD" : "12.25104077211402", "stAIC" : "1.888736439483697", "stSC" : "2.130678081410905", "stFstat_2" : "2870.259525336149", "stProbFstat_2" : "0", "stFstat" : "2870.259525336149", "stProbFstat" : "0", "stME" : "-1.084602493287653e-15", "stMAE" : "0.3119376087872172", "stMSE" : "0.2634857448932355", "stMaxAE" : "1.920839385280324", "stSqMSE" : "0.5133086253836336", "stVE" : "0.2634857448932355", "stSEE" : "0.5133086253836336", "stMD" : "21.1", "stHQcriterion" : "1.958406878256565", "stAvgLogL" : "NaN", "stMcFaddenRsquared" : "NaN", "stRestrLogL" : "NaN", "stLRstatistic" : "NaN", "stLRprobability" : "NaN", "stIncludedObservations" : "26", "stJstat" : "NaN", "stProbJstat" : "NaN", "stNumOfIter" : "-1", "stJBStat" : "44.27599282059314", "stProbJBStat" : "2.429910717083317e-10" }, "name" : "An*t^n + ... + A2*t^2 + A1*t + A0", "series" : { "input" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "1", "n" : "MyInputVavable", "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" }, "addFactor" : { "k" : "4294967295" } }, "evaluateSeries" : { "its" : { "Item" : { "scenarioKey" : "4294967295", "fact" : { "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", "34.7", "36.3", "37.9", "39.5", "41.1", "NaN", "NaN", "NaN" ] }, "modelling" : { "d" : [ "1.118621941960582", "2.913186226971609", "3.920839385280324", "6.083655743685077", "7.480263299190218", "9.284729796956913", "10.30170480827827", "12.47314753514884", "13.87757084976917", "15.68892737249664", "16.71175154982057", "18.8878874589317", "20.2957328472268", "22.10912521025945", "23.13248386971516", "25.30753777798089", "26.71256955764962", "28.52130157947111", "29.53803804032711", "31.70439276780075", "33.09853325968123", "34.89406676191454", "35.89518234657857", "38.04337871645274", "39.4167082445224", "41.18866305192973", "NaN", "NaN", "NaN" ] }, "residuals" : { "d" : [ "-0.1186219419605818", "1.086813773028391", "-1.920839385280324", "0.9163442563149227", "0.01973670080978174", "-0.1847297969569137", "0.398295191721731", "-0.1731475351488356", "0.02242915023083114", "-0.1889273724966447", "0.3882484501794323", "-0.187887458931705", "0.004267152773199001", "-0.2091252102594545", "0.3675161302848373", "-0.2075377779808925", "-0.01256955764961987", "-0.2213015794711097", "0.3619619596728931", "-0.2043927678007549", "0.0014667403187687", "-0.1940667619145344", "0.404817653421425", "-0.1433787164527374", "0.08329175547759604", "-0.08866305192972845", "NaN", "NaN", "NaN" ] }, "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", "1.42857143", "1.28571429", "1.14285714", "1", "0.85714286", "0.71428571", "0.57142857", "NaN", "NaN", "NaN" ] }, "factors" : { "its" : "" } } }, "dates" : { "it" : [ "1990A1", "1991A1", "1992A1", "1993A1", "1994A1", "1995A1", "1996A1", "1997A1", "1998A1", "1999A1", "2000A1", "2001A1", "2002A1", "2003A1", "2004A1", "2005A1", "2006A1", "2007A1", "2008A1", "2009A1", "2010A1", "2011A1", "2012A1", "2013A1", "2014A1", "2015A1", "2016A1", "2017A1", "2018A1", "2019A1", "2020A1" ] } }, "inversionInfo" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "doUseR" : "0", "supportsR" : "0" }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ] } }, "displayId" : "0", "series" : { "its" : "" }, "kind" : "Simple", "displaySettings" : { "displayTermsAs" : "Derive" }, "additionalAttributes" : "", "calculationType" : "Serie", "calculationDirection" : "Forward" }, "stochastic" : "0", "calculationPeriod" : "Forecast", "useModelPeriod" : "1", "useExistingData" : "0", "treatNullsAsZeros" : "0", "autoName" : "1", "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2018-04-24", "forecastStartDate" : "2018-04-25", "forecastEndDate" : "2020-01-01", "identificationStartDateParamID" : "", "identificationEndDateParamID" : "", "forecastStartDateParamID" : "", "forecastEndDateParamID" : "", "autoPeriod" : "28672", "identificationStartOffset" : "0", "identificationEndOffset" : "0", "forecastEndOffset" : "0", "isIdentStartCorrect" : "1", "isIdentEndCorrect" : "1", "isForecastEndCorrect" : "1" }, "isExclusive" : "1", "useAutoPeriod" : "1", "generatedName" : "MyOutputVavable|A[t] = An*t^n + ... + A2*t^2 + A1*t + A0", "warnings" : "", "readOnly" : "0" } } } }, "visualController" : { "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "useScenarios" : "0", "readOnly" : "0" } } } } }
public static MsCalculationChainEntry GetMsCurveEstimation(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() { item = new MsItemPattern() { // Specify calculated equation key key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { 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, execGenerateName = true, execSummaryStatistics = true, execCoefficients = true, execStatCoefficients = true, scenarioKeys = new long[] { }, 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.Length != 0) { Console.WriteLine("-- Warnings --"); Console.WriteLine("".PadRight(3) + printArray(eq.warnings)); } if (eq.error == null) //Check if errors occurred on equation calculation { // Equation if calculated without errors // Get calculation results TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula; TsCurveEstimationMethod curve = formula.method.curveEstimation; // Display best dependency form Console.WriteLine("Best dependency form: "+curve.bestDependenceForm.Value); // Display data on dependency forms MsDependenceForms depForms = curve.dependenceForms; foreach (MsDependenceForm form in depForms.its) { Console.WriteLine("Analyzed dependency form: "+ form.dependenceForm.ToString()); if (form.errors == "") { Console.WriteLine("Criterion value: ".PadRight(3) + form.criterionValue); Console.WriteLine("Equation: ".PadRight(3) + form.expression); // Get summary statistics and display into console window StatSummaryStatistics stat = form.summaryStatistics; PrintStat(stat); // Get coefficient values and display into console window StatModelCoefficients coef = form.statCoefficients; PrintCoef(coef); } else // Display errors occurred on dependency autoselection { Console.WriteLine("".PadRight(3)+form.errors);}; }; // 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 | Setting Up Parameters of the Extrapolate Method