Ниже приведен пример использования операции SetMs для изменения параметров уравнения. В запросе передаются: экземпляр открытого контейнера моделирования, параметры выполнения операции, настройки уравнения для метода «Нелинейная регрессия» и шаблон получения измененных данных. В результате выполнения операция возвращает модель, содержащую измененное уравнение.
Для выполнения примера уравнение должно содержать входную и выходную переменные.
{ "SetMs" : { "tMs" : { "id" : "KBKDOJOCAFNBFOAELHBGKDPMBJEKBCBENLOGCJBPHJJCNGNA!M!S!CFJCKJKOCAFNBFOAELBHKDONIACJNPIIEFLMPEGJAMDLKGLLF" }, "tArg" : { "pattern" : { "obInst" : "true", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Change" } } } }, "meta" : { "item" : { "k" : "89669", "type" : "Problem", "problemMd" : { "metamodel" : { "calculationChain" : { "its" : { "Item" : { "k" : "4", "type" : "Model", "model" : { "transform" : { "formulas" : { "its" : { "it" : [ { "k" : "0", "kind" : "NonLinearRegression", "method" : { "nonLinearRegression" : { "missingData" : { "method" : "LinTrend" }, "confidenceLevel" : "0.9", "useDerivatives" : "true", "initialApproximation" : { "d" : [ "0.15", "0.09" ] }, "maxIterations" : "500", "maxStep" : "0.4", "dampingFactorTolerance" : "0.6", "expression" : "@_2:0[] * a + b", "operands" : { "its" : { "Item" : { "slice" : { "k" : "0", "id" : "MyInputVavable|A", "n" : "MyInputVavable|A", "vis" : "true", "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" } } } }, "coefficients" : { "it" : [ "a", "b" ] } } } } ] } } }, "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2006-01-01", "forecastStartDate" : "2006-01-02", "forecastEndDate" : "2010-01-01", "autoPeriod" : "0" } } } } } } } } }, "metaGet" : { "obInst" : "true", "scenarios" : "Get", "period" : "true", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Get", "calcChainPattern" : { "modelPattern" : { "transform" : { "formulaCount" : "true", "formulas" : { "method" : "" }, "equationsFormula" : { "method" : "" }, "kind" : "true" } } }, "visualControllerPattern" : { "variableRubricatorKey" : "true", "useSourceName" : "false", "freeVariables" : "true", "levelFormat" : "Short" } }, "scenarios" : "Get", "details" : "true", "useSavedCoefficients" : "true" } } } } } }
{ "SetMsResult" : { "id" : { "id" : "KBKDOJOCAFNBFOAELHBGKDPMBJEKBCBENLOGCJBPHJJCNGNA!M!S!CFJCKJKOCAFNBFOAELBHKDONIACJNPIIEFLMPEGJAMDLKGLLF" }, "meta" : { "obInst" : { "obDesc" : { "@fullUrl" : "http:\/\/v-shp-development.dev.fs.fsight.world\/", "@isShortcut" : "0", "@isLink" : "0", "@ver" : "4", "@hf" : "0", "i" : "MODELSPACE", "n" : "Контейнер моделирования", "k" : "1581", "c" : "5121", "p" : "1580", "h" : "0", "hasPrv" : "0", "ic" : "0", "isPermanent" : "1", "isTemp" : "0" } }, "dirty" : "0", "period" : { "start" : "1970-01-01", "end" : "2020-12-31" }, "scenarios" : { "nodes" : { "it" : [ { "@isFolder" : "0", "k" : "1628", "id" : "OBJ1628", "n" : "Базовый", "vis" : "1", "scenDesc" : { "@fullUrl" : "http:\/\/v-shp-development.dev.fs.fsight.world\/", "@isShortcut" : "0", "@isLink" : "0", "@ver" : "0", "@hf" : "0", "i" : "OBJ1628", "n" : "Базовый", "k" : "1628", "c" : "5124", "p" : "1627", "h" : "0", "hasPrv" : "0", "ic" : "0" }, "internalKey" : "1629" }, { "@isFolder" : "0", "k" : "5371", "id" : "OBJ5371", "n" : "Базовый (копия1)", "vis" : "1", "scenDesc" : { "@fullUrl" : "http:\/\/v-shp-development.dev.fs.fsight.world\/", "@isShortcut" : "0", "@isLink" : "0", "@ver" : "0", "@hf" : "0", "i" : "OBJ5371", "n" : "Базовый (копия1)", "k" : "5371", "c" : "5124", "p" : "1627", "h" : "0", "hasPrv" : "0", "ic" : "0" }, "internalKey" : "5372" } ] } }, "item" : { "k" : "89669", "id" : "MODEL_NEW", "n" : "MODEL_NEW", "vis" : "1", "type" : "Problem", "problemMd" : { "metamodel" : { "k" : "89670", "calculationChain" : { "its" : { "Item" : [ { "k" : "1", "n" : "MyInputVavable", "vis" : "1", "type" : "Variable", "excluded" : "0", "graphMeta" : "{"Geometry":{"x":20,"y":10,"width":150,"height":50},"ChartOptions":{"chart":{"defaultSeriesType":"line","mixed":true,"backgroundColor":"rgba(0, 0, 0, 0.000000)"},"plotOptions":{"series":{"dataLabels":{"formatter":"%Autovalue","dataFormat":"#,##0.00"}}},"tooltip":{"formatter":"Значение: %Autovalue\nДата: %PointName","enabled":true,"backgroundType":"none","style":{"fontFamily":"Arial","fontSize":"12px","color":"#000000"}},"yAxis":[{"labels":{"enabled":true,"dataFormat":"#,##0.00"},"title":{"text":""}}],"xAxis":{"tickInterval":2,"labels":{},"title":{}},"series":[{"entryKey":1,"scenarioKey":4294967295,"serieType":"fact","showInLegend":true,"type":"line","color":"rgba(129, 129, 129, 1)","borderColor":"rgba(129, 129, 129, 1)","borderWidth":0,"lineColor":"rgba(129, 129, 129, 1)","zIndex":1,"legendIndex":0,"visible":true,"background":{"color":"rgba(129, 129, 129, 1)","type":"color"},"marker":{"enabled":false,"symbol":"circle","fillColor":"#FFFFFF","lineWidth":1.5,"lineColor":null},"dataLabels":{"formatter":"%Autovalue"},"trendLine":{}}]}}", "chainVariable" : { "slice" : { "k" : "0", "id" : "MyInputVavable|A", "n" : "MyInputVavable|A", "vis" : "1", "variableKey" : "1", "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" }, "fullName" : "MyInputVavable|A", "originalName" : "MyInputVavable", "originalShortName" : "MyInputVavable", "useCustomName" : "0" } }, { "k" : "2", "n" : "MyOutputVavable", "vis" : "1", "type" : "Variable", "excluded" : "0", "graphMeta" : "{"Geometry":{"x":30,"y":140,"width":150,"height":50}}", "chainVariable" : { "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "2", "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" }, "fullName" : "MyOutputVavable|A", "originalName" : "MyOutputVavable", "originalShortName" : "MyOutputVavable", "useCustomName" : "0" } }, { "k" : "4", "id" : "OBJ4", "n" : "MyOutputVavable|A[t] = MyInputVavable|A[t] * a + b, 1990A1-(От родителя)", "vis" : "1", "type" : "Model", "excluded" : "0", "graphMeta" : "", "model" : { "transform" : { "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" ] }, "optimizationMethod" : "LevenbergMarquardt", "tolerance" : "0.0001", "useDefaultInitValues" : "0" }, "inversionInfo" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "doUseR" : "0", "supportsR" : "1" }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ] } }, "kind" : "Simple" }, "warnings" : "", "readOnly" : "0" } } ] } }, "visualController" : { "variableRubricatorKey" : "89671", "freeVariables" : { "its" : "" }, "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "scenarios" : { "its" : "" }, "details" : { "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2018-04-24", "forecastStartDate" : "2018-04-25", "forecastEndDate" : "2020-01-01", "identificationStartDateParamID" : "", "identificationEndDateParamID" : "", "forecastStartDateParamID" : "", "forecastEndDateParamID" : "", "autoPeriod" : "0", "identificationStartOffset" : "0", "identificationEndOffset" : "0", "forecastEndOffset" : "0", "isIdentStartCorrect" : "1", "isIdentEndCorrect" : "1", "isForecastEndCorrect" : "1" }, "currentPoint" : "2018-04-25" }, "useSavedCoefficients" : "0", "useScenarios" : "0", "readOnly" : "0" } } } } }
Функция SetMsNonLinearRegr изменяет метод расчёта уравнения. Входные параметры:
ms. Экземпляр открытого контейнера моделирования;
modelKey. Ключ модели, содержащей уравнение;
eqKey. Ключ уравнения;
eq. Экземпляр открытого уравнения. Для выполнения примера уравнение должно содержать входную и выходную переменные.
В результате выполнения функция возвращает модель, содержащую уравнение.
public static MsItem SetMsNonLinearRegr(MsId ms, ulong modelKey, ulong eqKey, MsModel eq) { // Получаем входную переменую MsFormulaTransformVariable inp = eq.transform.inputs.its.GetValue(0) as MsFormulaTransformVariable; // Задаем параметры выполнения операции var setMsOp = new SetMs(); setMsOp.tMs = ms; setMsOp.tArg = new SetMsArg() { // Задаем шаблон изменения данных pattern = new MsMdPattern() { item = new MsItemPattern() { // Указываем ключ модели key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Change } } } }, // Задаем данные, которые необходимо изменить meta = new MsMd() { item = new MsItem() { // Указываем ключ модели k = modelKey, type = MsItemType.Problem, problemMd = new MsProblem() { metamodel = new MsMetaModel() { calculationChain = new MsCalculationChainEntries() { its = new MsCalculationChainEntry[] { new MsCalculationChainEntry() { k = eqKey, type = MsCalculationChainType.Model, model = new MsModel() { // Задаём периоды расчёта period = new MsModelPeriod() { autoPeriod = 0, identificationStartDate = DateTime.Parse("01.01.1990"), identificationEndDate = DateTime.Parse("01.01.2006"), forecastStartDate = DateTime.Parse("02.01.2006"), forecastEndDate = DateTime.Parse("01.01.2010") }, transform = new MsFormulaTransform() { formulas = new TsFormulas() { its = new TsFormula[] { new TsFormula() { kind = TsFormulaKind.NonLinearRegression, method = new TsMethod() { // Задаём параметры расчёта метода nonLinearRegression = new TsNonLinearRegressionMethod() { // Задаём метод обработки пропусков missingData = new StatMissingData(){method = StatMissingDataMethod.LinTrend}, //Задаём значимость доверительных границ confidenceLevel = 0.90, // Используем производные для повышения точности расчёта useDerivatives = true, // Задаём максимальное число итераций для расчёта метода maxIterations = 500, // Задаём точность определения параметра регуляризации dampingFactorTolerance = 0.6, // Задаём переменные, учавствующие в расчёте operands = new MsFormulaTerms() { its = new MsFormulaTerm[] { new MsFormulaTerm() {slice = inp.slices.its.GetValue(0) as MsFormulaTransformSlice} } }, // Задаём формулу для расчёта expression = "@_" + inp.k + ":0[] * a + b", // Задаём коэффициенты coefficients = new string[] {"a", "b"}, // Задаём начальные приближения коэффициентов initialApproximation = new double[] {0.15, 0.09}, // Задаём максимальное расстояние между приближениями maxStep = 0.4 } } } } } } } } } } } } } }, // Задаём шаблон извлечения измененных данных metaGet = new MsMdPattern() { scenarios = ListOperation.Get, period = true, item = new MsItemPattern() { key = modelKey, problem = new MsProblemPattern() { details = true, scenarios = ListOperation.Get, useSavedCoefficients = true, metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { modelPattern = new MsModelPattern() { transform = new MsFormulaTransformPattern() { kind = true, formulaCount = true, formulas = new TsFormulaPattern() { method = new TsMethodPattern() { } }, equationsFormula = new TsFormulaPattern() { method = new TsMethodPattern() { } } } } }, visualControllerPattern = new MsMetaModelVisualControllerPattern() { variableRubricatorKey = true, levelFormat = MsLevelFormat.Short, useSourceName = false, freeVariables = true } } } } } }; // Создаем прокси-объект для выполнения операции var somClient = new SomPortTypeClient(); // Задаем параметры выполнения операции var result = somClient.SetMs(setMsOp); return result.meta.item; }
См. также:
SetMs: Операция | Метод «Нелинейная регрессия»