/** Method: Load data for calculation * data - data from time series * n - number (real) of convolutions */ void IConvolution.LoadData(List <double> data, double n) { if (data.Count == 0) { throw new Exception("Error. No data"); } double res = n - (int)n; this.n = n; convData.Clear(); hist.Clear(); de = new KernelDensity(1, 100, 100); int [] indexes = new int[(int)n + 1]; int indexRes = -1; double sum; for (int i = 0; i < maxIt / 2; i++) { sum = 0; for (int j = 1; j <= n; j++) { indexes[j - 1] = rg.NextInt(0, data.Count - 1); sum += data[indexes[j - 1]]; } if (res > 0) { indexRes = rg.NextInt(0, data.Count - 1); sum = sum + data[indexRes] * res; } convData.Add(sum); sum = 0; for (int j = 1; j <= n; j++) { sum += data[data.Count - 1 - indexes[j - 1]]; } if (res > 0) { sum = sum + data[data.Count - 1 - indexRes] * res; } convData.Add(sum); } hist.LoadData(convData); de.LoadHist(hist); de.SetMaxInt(); }
private void LoadMontConvolution() { List <double> convData = new List <double>(); Histogram convHist = new Histogram(); double sum; for (int i = 0; i < maxIt; i++) { sum = 0; foreach (Distribution dist in distributions) { dist.RawData = dist.Histogram.GetRawData(); } foreach (Distribution dist in distributions) { int nLeadTimesInt = (int)dist.NLeadTimes; double nLeadTimesRes = dist.NLeadTimes - nLeadTimesInt; int[] indexes = new int[(int)dist.NLeadTimes + 1]; int indexRes = -1; for (int j = 1; j <= nLeadTimesInt; j++) { indexes[j - 1] = rg.NextInt(0, dist.RawData.Count - 1); sum += dist.RawData[indexes[j - 1]]; } if (nLeadTimesRes > 0) { indexRes = rg.NextInt(0, dist.RawData.Count - 1); sum = sum + dist.RawData[indexRes] * nLeadTimesRes; } convData.Add(sum * dist.Factor); } } convHist.LoadData(convData); de = new KernelDensity(1, 100, 100); de.LoadHist(convHist); de.SetMaxInt(); }