Exemplo n.º 1
0
        protected override void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     worker = (BackgroundWorker)sender;
            BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;

            var dataset = bwInfo.Dataset;
            var indices = bwInfo.Indices.ToArray();
            IDependencyCalculator calc = bwInfo.Calculator;

            IList <string> doubleVariableNames = dataset.DoubleVariables.ToList();

            int length = doubleVariableNames.Count;

            double[,] elements = new double[length, length];

            worker.ReportProgress(0);

            for (int counter = 0; counter < length; counter++)
            {
                if (worker.CancellationPending)
                {
                    worker.ReportProgress(100);
                    e.Cancel = true;
                    return;
                }

                var i = counter;
                Parallel.ForEach(Enumerable.Range(i, length - i), j => {
                    var var1 = dataset.GetDoubleValues(doubleVariableNames[i], indices);
                    var var2 = dataset.GetDoubleValues(doubleVariableNames[j], indices);

                    OnlineCalculatorError error = OnlineCalculatorError.None;
                    if (bwInfo.IgnoreMissingValues)
                    {
                        var filtered   = FilterNaNValues(var1, var2);
                        elements[i, j] = calc.Calculate(filtered, out error);
                    }
                    else
                    {
                        elements[i, j] = calc.Calculate(var1, var2, out error);
                    }

                    if (!error.Equals(OnlineCalculatorError.None))
                    {
                        elements[i, j] = double.NaN;
                    }
                    elements[j, i] = elements[i, j];
                });
                worker.ReportProgress((int)(((double)counter) / length * 100));
            }

            e.Result = elements;
            worker.ReportProgress(100);
        }
Exemplo n.º 2
0
        protected override void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker     worker = (BackgroundWorker)sender;
            BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;

            var dataset = bwInfo.Dataset;
            var indices = bwInfo.Indices.ToArray();
            IDependencyCalculator calc = bwInfo.Calculator;
            string variable            = bwInfo.Variable;
            int    frames = bwInfo.Frames;

            double[,] alreadyCalculated = bwInfo.AlreadyCalculated;

            IList <string> doubleVariableNames = dataset.DoubleVariables.ToList();
            int            length = doubleVariableNames.Count;

            double[,] elements = new double[length, frames + 1];
            double calculations = (frames + 1) * length;

            worker.ReportProgress(0);

            int start = 0;

            if (alreadyCalculated != null)
            {
                for (int i = 0; i < alreadyCalculated.GetLength(0); i++)
                {
                    Array.Copy(alreadyCalculated, i * alreadyCalculated.GetLength(1), elements, i * elements.GetLength(1), alreadyCalculated.GetLength(1));
                }
                start = alreadyCalculated.GetLength(1);
            }

            var var1 = dataset.GetDoubleValues(variable, indices).ToArray();

            for (int i = 0; i < length; i++)
            {
                for (int j = start; j <= frames; j++)
                {
                    if (worker.CancellationPending)
                    {
                        worker.ReportProgress(100);
                        e.Cancel = true;
                        return;
                    }

                    IEnumerable <double> var2 = dataset.GetDoubleValues(doubleVariableNames[i], indices);

                    var error = OnlineCalculatorError.None;
                    elements[i, j] = calc.Calculate(var1.Skip(j), var2.Take(var1.Length - j), out error);

                    if (!error.Equals(OnlineCalculatorError.None))
                    {
                        elements[i, j] = double.NaN;
                    }
                    worker.ReportProgress((int)((100.0 / calculations) * (i * (frames + 1) + j + 1)));
                }
            }
            e.Result = elements;
            worker.ReportProgress(100);
        }
Exemplo n.º 3
0
        private void BwCalculateCorrelation(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;
            var dataset = bwInfo.Dataset;
            IEnumerable <int>     indices = bwInfo.Indices;
            IDependencyCalculator calc    = bwInfo.Calculator;

            IList <string>        doubleVariableNames = dataset.DoubleVariables.ToList();
            OnlineCalculatorError error = OnlineCalculatorError.None;
            int length = doubleVariableNames.Count;

            double[,] elements = new double[length, length];
            double calculations = (Math.Pow(length, 2) + length) / 2;

            worker.ReportProgress(0);

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < i + 1; j++)
                {
                    if (worker.CancellationPending)
                    {
                        worker.ReportProgress(100);
                        e.Cancel = true;
                        return;
                    }
                    IEnumerable <double> var1 = problemData.Dataset.GetDoubleValues(doubleVariableNames[i], indices);
                    IEnumerable <double> var2 = problemData.Dataset.GetDoubleValues(doubleVariableNames[j], indices);

                    elements[i, j] = calc.Calculate(var1, var2, out error);

                    if (!error.Equals(OnlineCalculatorError.None))
                    {
                        elements[i, j] = double.NaN;
                    }
                    elements[j, i] = elements[i, j];
                    worker.ReportProgress((int)Math.Round((((Math.Pow(i, 2) + i) / 2 + j + 1.0) / calculations) * 100));
                }
            }
            e.Result = elements;
            worker.ReportProgress(100);
        }