Ниже приведен пример использования операции GetMs для расчёта уравнения. В запросе передаются: экземпляр открытого контейнера моделирования, шаблон расчёта уравнения и параметры выполнения операции. В ответе приходит экземпляр модели, содержащей уравнение с результатами расчёта.
Для выполнения примера уравнение должно рассчитываться методом «Нелинейная регрессия».
{
"Envelope" :
{
"Body" :
{
"GetMs" :
{
"tMs" :
{
"id" : "S82!M!S!C1"
},
"tArg" :
{
"pattern" :
{
"obInst" : "false",
"all" : "false",
"item" :
{
"key" : "3674",
"model" :
{
"transform" :
{
"formulas" :
{
"method" : ""
}
}
}
}
},
"execParams" :
{
"k" : "0",
"scenarioKeys" : "",
"execMethod" : "true",
"execCoefficients" : "true",
"execEvaluateSeries" : "true",
"execIsCoefficientsSaved" : "true",
"execStatCoefficients" : "true"
}
}
}
}
}
}
{
"Envelope" :
{
"Body" :
{
"GetMsResult" :
{
"id" :
{
"id" : "S82!M!S!C1"
},
"meta" :
{
"item" :
{
"k" : "3674",
"id" : "OBJ3674",
"n" : "MyOutputVavable[t] = MyInputVavable[t] * a + b",
"vis" : "1",
"type" : "Model",
"modelMd" :
{
"transform" :
{
"formulas" :
{
"its" :
{
"it" :
[
{
"k" : "0",
"kind" : "NonLinearRegression",
"method" :
{
"nonLinearRegression" :
{
"missingData" :
{
"specifiedVector" : "",
"method" : "LinTrend",
"methodParameter" : "5",
"specifiedValue" : "0"
},
"confidenceLevel" : "0.900000",
"useDerivatives" : "1",
"initialApproximation" :
{
"d" :
[
"0.150000",
"0.090000"
]
},
"maxIterations" : "500",
"maxStep" : "0.400000",
"dampingFactorTolerance" : "0.600000",
"expression" : "@_3675:0[] * a + b",
"result" :
{
"slice" :
{
"k" : "0",
"id" : "262",
"n" : "MyOutputVavable",
"vis" : "1",
"variableKey" : "3676",
"stubKey" : "2805",
"selections" :
{
"its" :
{
"Item" :
{
"id" :
{
"id" : "2818"
},
"variant" : "262"
}
}
},
"aggregator" : "None",
"parametrizedDimensions" :
{
"its" :
{
"Item" :
{
"dimension" : "0",
"parameter" : "0"
}
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
},
"level" : "None"
},
"lag" : "",
"key" : "0",
"termToText" : "{MyOutputVavable[t]}",
"termToInnerText" : "@_3676:0[]",
"termInfo" :
{
"k" : "4294967295",
"lag" : "0",
"inversion" :
{
"type" : "None",
"lag" : "PrecidingValue",
"previousLag" : "-1",
"seasonality" : "None",
"dependence" : "Linear",
"K" : "3"
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
}
},
"operands" :
{
"its" :
{
"Item" :
{
"k" : "0",
"slice" :
{
"k" : "0",
"id" : "261",
"n" : "MyInputVavable",
"vis" : "1",
"variableKey" : "3675",
"stubKey" : "2805",
"selections" :
{
"its" :
{
"Item" :
{
"id" :
{
"id" : "2818"
},
"variant" : "261"
}
}
},
"aggregator" : "None",
"parametrizedDimensions" :
{
"its" :
{
"Item" :
{
"dimension" : "0",
"parameter" : "0"
}
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
},
"level" : "None"
},
"lag" : "",
"key" : "1",
"termToText" : "{MyInputVavable[t]}",
"termToInnerText" : "@_3675:0[]",
"termInfo" :
{
"k" : "4294967295",
"lag" : "0",
"inversion" :
{
"type" : "None",
"lag" : "PrecidingValue",
"previousLag" : "-1",
"seasonality" : "None",
"dependence" : "Linear",
"K" : "3"
}
},
"unitInfo" :
{
"unit" : "4294967295",
"measure" : "4294967295",
"baseUnit" : "4294967295",
"unitsDimensionKey" : "0"
}
}
}
},
"coefficients" :
{
"it" :
[
"a",
"b"
]
},
"coefficientsData" :
{
"d" :
[
"0.124864",
"2.163685"
]
},
"isCoefficientsSaved" : "0",
"statCoefficients" :
{
"its" :
{
"Item" :
[
{
"estimate" : "0.124864",
"standardError" : "0.218206",
"tStatistic" : "0.572231",
"probability" : "0.575642"
},
{
"estimate" : "2.163685",
"standardError" : "0.952901",
"tStatistic" : "2.270629",
"probability" : "0.038336"
}
]
}
}
},
"name" : "Y = X1 * 0.1249 + 2.1637",
"evaluateSeries" :
{
"its" :
{
"Item" :
{
"scenarioKey" : "4294967295",
"fact" :
{
"d" :
[
"4.000000",
"1.200000",
"3.000000",
"2.000000",
"3.800000",
"1.200000",
"2.800000",
"2.000000",
"1.100000",
"5.400000",
"1.000000",
"-1.700000",
"7.200000",
"-1.000000",
"5.000000",
"0.200000",
"6.600000"
]
},
"modelling" :
{
"d" :
[
"2.288549",
"1.951416",
"3.062706",
"2.038821",
"2.788005",
"2.188658",
"2.987787",
"2.101253",
"2.563250",
"2.413413",
"2.538277",
"2.937842",
"3.050219",
"2.887896",
"2.513304",
"2.625682",
"2.862923"
]
},
"forecast" :
{
"d" :
[
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"2.563250",
"2.613195",
"3.162597",
"3.037733"
]
},
"residuals" :
{
"d" :
[
"1.711451",
"-0.751416",
"-0.062706",
"-0.038821",
"1.011995",
"-0.988658",
"-0.187787",
"-0.101253",
"-1.463250",
"2.986587",
"-1.538277",
"-4.637842",
"4.149781",
"-3.887896",
"2.486696",
"-2.425682",
"3.737077"
]
},
"upperConfidenceLevel" :
{
"d" :
[
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"6.529654",
"6.579599",
"7.129001",
"7.004137"
]
},
"lowerConfidenceLevel" :
{
"d" :
[
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"NaN",
"-1.403154",
"-1.353209",
"-0.803807",
"-0.928671"
]
},
"dUpperConfidenceLevel" : "",
"dLowerConfidenceLevel" : ""
}
},
"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"
}
},
"calendarLevel" : "Year",
"outputSliceKey" : "0"
}
]
}
}
},
"warnings" : ""
}
}
}
}
}
}
}
Функция GetMsNonLinearRegr рассчитывает указанное уравнение. Входные параметры: экземпляр контейнера моделирования; ключ рассчитываемого уравнения. В результате выполнения функция возвращает модель, содержащую рассчитанное уравнение. Результаты расчёта выводятся в окно консоли. Для вывода результатов используются вспомогательные процедуры: PrintArray, PrintSeries, описанные в разделе «Расчёт уравнения».
public static MsItem GetMsNonLinearRegr(MsId ms, ulong eqKey)
{
var getMsOp = new GetMs();
// Задаём параметры выполнения операции
getMsOp.tMs = ms;
getMsOp.tArg = new GetMsArg()
{ // Задаём шаблон извлечения данных
pattern = new MsMdPattern()
{
obInst = false,
all = false,
item = new MsItemPattern()
{ // Указываем ключ рассчитываемого уравнения
key = eqKey,
model = new MsModelPattern()
{
transform = new MsFormulaTransformPattern()
{
formulas = new TsFormulaPattern()
{
method = new TsMethodPattern(){}
}
}
}
}
}, // Задаём параметры расчёта уравнения
execParams = new MsMdExecParams()
{
k = 0,
execMethod = true,
execEvaluateSeries = true,
scenarioKeys = new long[] { },
execStatCoefficients = true, execCoefficients = true, execIsCoefficientsSaved = true } }; // Создаем прокси-объект для выполнения операции var somClient = new SomPortTypeClient(); GetMsResult getMsResult = somClient.GetMs(getMsOp); MsItem model = getMsResult.meta.item; // Выводим ошибки и предупреждения
MsModel eq = model.modelMd;
if (eq.warnings != null)
{
Console.WriteLine("-- Предупреждения --");
Console.WriteLine("".PadRight(3) + printArray(eq.warnings));
}
if (eq.error == null) //Проверяем, возникли ли ошибки при расчёте уравнения
{ // Уравнение рассчитано без ошибок, получаем результаты расчёта
TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula;
TsNonLinearRegressionMethod nonLinR = formula.method.nonLinearRegression;
Console.WriteLine("-- Коэффициенты --");
Console.WriteLine("".PadRight(3) + printArray(nonLinR.coefficients));
Console.WriteLine("".PadRight(3) + "- сохранены: " + nonLinR.isCoefficientsSaved);
Console.WriteLine("-- Значения коэффициентов --");
Console.WriteLine("".PadRight(3) + printArray(nonLinR.coefficientsData));
// Получаем значения коэффициентов уравнения и выводим в окно консоли
Console.WriteLine("-- Подробное описание коэффициентов --");
StatConstCoefficientsArr cArr = nonLinR.statCoefficients;
Console.WriteLine("".PadRight(3) + "- точность вычислений: " + cArr.precision);
int i = 0;
foreach (StatConstCoefficients n in cArr.its)
{
Console.WriteLine("".PadRight(3) + "Коэффициент '" + nonLinR.coefficients.GetValue(i) + "'");
Console.WriteLine("".PadRight(6) + " - значение: " + n.estimate);
Console.WriteLine("".PadRight(6) + " - стандартная ошибка: " + n.standardError);
Console.WriteLine("".PadRight(6) + " - t-статистика: " + n.tStatistic);
Console.WriteLine("".PadRight(6) + " - вероятность: " + n.probability);
i++;
}
// Получаем рассчитанные значения и выводим в окно консоли
MsEvaluateSeriesResult seriesRes = formula.method.evaluateSeries;
printSeries(seriesRes);
}
else // При расчёте уравнения возникли ошибки
{
Console.WriteLine("-- Ошибки --");
Console.WriteLine(eq.error);
}
// Возвращаем модель, содержащую уравнение
return model;
}
См. также:
GetMs: Операция | Метод «Нелинейная регрессия»
SOAP