/// <summary> /// 保存してあるタイムマシンデータからInfectDataを作成する /// </summary> public void MakeTimeMachineInfectData() { if (TimeMachineData._notEmpty()) { _timeMachineInfectData = null; _timeMachineInfectData = NthInfectData(-1).CreateData(TimeMachineData); RenewDecaySubParams(); } }
/// <summary> /// ソースデータからテスト用InfectDataを作成して、整形されたデータを保存する /// </summary> /// <param name="srcIdx"></param> /// <returns></returns> public void UseTimeMachineInfectData(string tmData) { logger.Info($"{GetTitle()}: {tmData}"); _timeMachineInfectData = null; var trimData = tmData._strip()._orElse("0"); _timeMachineInfectData = NthInfectData(-1).CreateData(trimData); RenewDecaySubParams(); TimeMachineData = trimData; TimeMachineMode = true; }
public InfectData ShiftStartDate(DateTime startDt) { InfectData data = Clone(); int idx = Dates._findIndex(startDt); if (idx > 0) { data.Dates = Dates.Skip(idx).ToArray(); data.Newly = Newly.Skip(idx).ToArray(); data.DistNewly = DistNewly.Skip(idx).ToArray(); data.Average = Average.Skip(idx).ToArray(); data.PosiRates = PosiRates.Skip(idx).ToArray(); data.Rt = Rt.Skip(idx).ToArray(); data.Serious = Serious.Skip(idx).ToArray(); data.SeriousEx = SeriousEx.Skip(idx).ToArray(); } return(data); }
/// <summary>各種推計値の計算</summary> /// <param name="infData"></param> /// <param name="rtDecayParam">not null で、書き換えられてもよいデータである必要がある</param> /// <param name="skipDays">実データの初めから表示開始日までの日数</param> /// <param name="numFullDays">全表示候補日の数(1年間とか)</param> /// <param name="extensionDays"></param> /// <param name="predStartDt"></param> /// <returns></returns> public UserPredictData predictValuesEx(InfectData infData, RtDecayParam rtDecayParam, int skipDays, int numFullDays, int extensionDays, DateTime?predStartDt) { //logger.Trace("ENTER"); var firstRealDate = infData.Dates.First(); DateTime realEndDate = predStartDt?.AddDays(-1) ?? DateTime.MaxValue; DateTime infEndDate = infData.Dates.Last(); if (realEndDate > infEndDate) { realEndDate = infEndDate; } int realDays = (realEndDate - firstRealDate).Days + 1; int totalDays = skipDays + numFullDays; if (rtDecayParam.StartDate > realEndDate) { rtDecayParam.StartDate = realEndDate; } if (rtDecayParam.StartDateFourstep > realEndDate) { rtDecayParam.StartDateFourstep = realEndDate; } //logger.Debug($"rtDecayParam.StartDate={rtDecayParam.StartDate.ToLongDateString()}, " + // $"StartDateFourstep={rtDecayParam.StartDateFourstep.ToLongDateString()}, " + // $"EffectiveStartDate={rtDecayParam.EffectiveStartDate.ToLongDateString()}"); const int ExtraDaysForAverage = Constants.EXTRA_DAYS_FOR_AVERAGE; // 逆算移動平均 double[] revAverage = new double[totalDays + ExtraDaysForAverage]; // 予想実効再生産数 double[] fullPredRt = new double[totalDays + ExtraDaysForAverage]; int predStartIdx = (rtDecayParam.EffectiveStartDate - firstRealDate).Days; if (predStartIdx < 0 || predStartIdx >= infData.Average.Length) { logger.Warn($"PredStartIdx({predStartIdx}) is out of range. " + $"rtDecayParam.EffectiveStartDate({rtDecayParam.EffectiveStartDate}) may not be valid. " + $"Use realEndDate={realEndDate} instead"); predStartIdx = (realEndDate - firstRealDate).Days; } Array.Copy(infData.Average, revAverage, predStartIdx); int predRtLen = rtDecayParam.CalcAndCopyPredictRt(infData.Rt, predStartIdx, fullPredRt, realDays, extensionDays + ExtraDaysForAverage); for (int i = 0; i < predRtLen; ++i) { int idx = predStartIdx + i; var rt = fullPredRt[idx]; if (idx >= 7 && idx < revAverage.Length && rt > 0) { revAverage[idx] = Math.Pow(rt, 7.0 / 5.0) * revAverage[idx - 7]; } } predRtLen -= ExtraDaysForAverage; double[] revAveAverage = new double[totalDays + ExtraDaysForAverage]; // 逆算移動平均の平均 for (int i = 3; i < predRtLen; ++i) { int idx = predStartIdx + i; int margin = i._highLimit(ExtraDaysForAverage - 1); int beg = idx - margin; int end = idx + margin + 1; if (beg >= 0 && end <= revAverage.Length) { revAveAverage[idx] = revAverage[beg..end].Sum() / (margin * 2 + 1);
/// <summary> /// 各種推計値の計算 /// </summary> /// <param name="rtDecayParam">書き換えられてもよいデータである必要がある</param> /// <param name="skipDays">実データの初めから表示開始日までの日数</param> /// <param name="numFullDays">全表示候補日の数(1年間とか)</param> /// <param name="predStartDt">予測開始日</param> /// <returns>(PredictInfectData, 表示開始から予測終了までの日数)</returns> public static UserPredictData PredictValuesEx(InfectData infData, RtDecayParam rtDecayParam, int skipDays, int numFullDays, int extensionDays, DateTime?predStartDt = null) { return(new UserPredictData().predictValuesEx(infData, rtDecayParam, skipDays, numFullDays, extensionDays, predStartDt)); }
public void ClearTimeMachineInfectData() { _timeMachineInfectData = null; TimeMachineMode = false; RenewDecaySubParams(); }