コード例 #1
0
        private void CalculateElements(IDataset dataset, IDependencyCalculator calc, string partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null)
        {
            var indices = GetRelevantIndices(problemData, partition);

            bwInfo = new BackgroundWorkerInfo {
                Dataset  = dataset, Calculator = calc, Partition = partition, Indices = indices,
                Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated
            };
            if (bw == null)
            {
                bw = new BackgroundWorker();
                bw.WorkerReportsProgress      = true;
                bw.WorkerSupportsCancellation = true;
                bw.DoWork             += new DoWorkEventHandler(BwDoWork);
                bw.ProgressChanged    += new ProgressChangedEventHandler(BwProgressChanged);
                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BwRunWorkerCompleted);
            }
            if (bw.IsBusy)
            {
                bw.CancelAsync();
            }
            else
            {
                bw.RunWorkerAsync(bwInfo);
            }
        }
コード例 #2
0
        protected override void CalculateCorrelation()
        {
            if (correlationCalcComboBox.SelectedItem == null)
            {
                return;
            }
            if (partitionComboBox.SelectedItem == null)
            {
                return;
            }

            IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
            string partition           = (string)partitionComboBox.SelectedValue;

            dataView.Enabled = false;
            double[,] corr   = correlationCache.GetCorrelation(calc, partition, ignoreMissingValuesCheckbox.Checked);
            if (corr == null)
            {
                CorrelationCalculator.CalculateElements(Content, calc, partition, ignoreMissingValuesCheckbox.Checked);
            }
            else
            {
                CorrelationCalculator.TryCancelCalculation();
                var correlation = new DoubleMatrix(corr, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
                UpdateDataView(correlation);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
 protected override void CalculateCorrelation()
 {
     if (correlationCalcComboBox.SelectedItem != null && partitionComboBox.SelectedItem != null &&
         variableSelectionComboBox.SelectedItem != null)
     {
         string variable            = (string)variableSelectionComboBox.SelectedItem;
         IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
         string partition           = (string)partitionComboBox.SelectedValue;
         int    frames;
         int.TryParse(timeframeTextbox.Text, out frames);
         dataView.Enabled = false;
         double[,] corr   = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable);
         if (corr == null)
         {
             fcc.CalculateTimeframeElements(calc, partition, variable, frames);
         }
         else if (corr.GetLength(1) <= frames)
         {
             fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr);
         }
         else
         {
             fcc.TryCancelCalculation();
             var columnNames = Enumerable.Range(0, corr.GetLength(1)).Select(x => x.ToString());
             var correlation = new DoubleMatrix(corr, columnNames, Content.Dataset.DoubleVariables);
             ((IStringConvertibleMatrix)correlation).Columns = frames + 1;
             UpdateDataView(correlation);
         }
     }
 }
コード例 #5
0
 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null)
 {
     this.Correlation = correlation;
     this.Calculcator = calculator;
     this.Partition   = partition;
     this.Variable    = variable;
 }
コード例 #6
0
            public double[,] GetCorrelation(IDependencyCalculator calc, string partition)
            {
                double[,] corr;
                var key = new Tuple <IDependencyCalculator, string>(calc, partition);

                correlationsCache.TryGetValue(key, out corr);
                return(corr);
            }
コード例 #7
0
            public double[,] GetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues)
            {
                double[,] corr;
                var key = Tuple.Create(calc, partition, ignoreMissingValues);

                correlationsCache.TryGetValue(key, out corr);
                return(corr);
            }
コード例 #8
0
    public void CalculateElements(IDataAnalysisProblemData problemData, IDependencyCalculator calc, string partition, bool ignoreMissingValues) {
      var indices = GetRelevantIndices(problemData, partition);
      var info = new BackgroundWorkerInfo {
        Dataset = problemData.Dataset, Calculator = calc, Partition = partition, Indices = indices, IgnoreMissingValues = ignoreMissingValues
      };

      StartCalculation(info);
    }
コード例 #9
0
            public double[,] GetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable)
            {
                double[,] corr;
                var key = new Tuple <IDependencyCalculator, string, string>(calc, partition, variable);

                timeFrameCorrelationsCache.TryGetValue(key, out corr);
                return(corr);
            }
コード例 #10
0
 // returns true if any calculation takes place
 public bool CalculateTimeframeElements(IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null) {
   if (correlation == null || correlation.GetLength(1) <= frames) {
     CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation);
     return true;
   } else {
     return false;
   }
 }
 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, bool ignoreMissingValues, string variable = null)
 {
     this.Correlation         = correlation;
     this.Calculcator         = calculator;
     this.Partition           = partition;
     this.IgnoreMissingValues = ignoreMissingValues;
     this.Variable            = variable;
 }
コード例 #12
0
        public void CalculateElements(IDataAnalysisProblemData problemData, IDependencyCalculator calc, string partition, bool ignoreMissingValues)
        {
            var indices = GetRelevantIndices(problemData, partition);
            var info    = new BackgroundWorkerInfo {
                Dataset = problemData.Dataset, Calculator = calc, Partition = partition, Indices = indices, IgnoreMissingValues = ignoreMissingValues
            };

            StartCalculation(info);
        }
コード例 #13
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);
        }
コード例 #14
0
    // returns true if any calculation takes place
    public bool CalculateTimeframeElements(IDataAnalysisProblemData problemData, IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null) {
      if (correlation != null && correlation.GetLength(1) > frames) return false;

      var indices = GetRelevantIndices(problemData, partition);
      var info = new BackgroundWorkerInfo {
        Dataset = problemData.Dataset, Calculator = calc, Partition = partition, Indices = indices, Variable = variable, Frames = frames, AlreadyCalculated = correlation
      };

      StartCalculation(info);
      return true;
    }
コード例 #15
0
 // returns true if any calculation takes place
 public bool CalculateTimeframeElements(IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null)
 {
     if (correlation == null || correlation.GetLength(1) <= frames)
     {
         CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation);
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #16
0
        protected void UpdateDataView(DoubleMatrix correlation)
        {
            IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;

            maximumLabel.Text = calc.Maximum.ToString();
            minimumLabel.Text = calc.Minimum.ToString();

            correlation.SortableView = true;
            dataView.Maximum         = calc.Maximum;
            dataView.Minimum         = calc.Minimum;

            dataView.Content = correlation;
            dataView.Enabled = true;
        }
コード例 #17
0
        // returns true if any calculation takes place
        public bool CalculateTimeframeElements(IDataAnalysisProblemData problemData, IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null)
        {
            if (correlation != null && correlation.GetLength(1) > frames)
            {
                return(false);
            }

            var indices = GetRelevantIndices(problemData, partition);
            var info    = new BackgroundWorkerInfo {
                Dataset = problemData.Dataset, Calculator = calc, Partition = partition, Indices = indices, Variable = variable, Frames = frames, AlreadyCalculated = correlation
            };

            StartCalculation(info);
            return(true);
        }
コード例 #18
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);
        }
コード例 #19
0
 private void CalculateElements(IDataset dataset, IDependencyCalculator calc, string partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {
   var indices = GetRelevantIndices(problemData, partition);
   bwInfo = new BackgroundWorkerInfo {
     Dataset = dataset, Calculator = calc, Partition = partition, Indices = indices,
     Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated
   };
   if (bw == null) {
     bw = new BackgroundWorker();
     bw.WorkerReportsProgress = true;
     bw.WorkerSupportsCancellation = true;
     bw.DoWork += new DoWorkEventHandler(BwDoWork);
     bw.ProgressChanged += new ProgressChangedEventHandler(BwProgressChanged);
     bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BwRunWorkerCompleted);
   }
   if (bw.IsBusy) {
     bw.CancelAsync();
   } else {
     bw.RunWorkerAsync(bwInfo);
   }
 }
        protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, bool ignoreMissingValues, string variable = null)
        {
            var handler = CorrelationCalculationFinished;

            if (handler != null)
            {
                handler(this, new CorrelationCalculationFinishedArgs(correlation, calculator, partition, ignoreMissingValues, variable));
            }
        }
コード例 #21
0
 public void CalculateElements(IDependencyCalculator calc, string partition) {
   CalculateElements(problemData.Dataset, calc, partition);
 }
コード例 #22
0
            public void SetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable, double[,] correlation)
            {
                var key = new Tuple <IDependencyCalculator, string, string>(calc, partition, variable);

                timeFrameCorrelationsCache[key] = correlation;
            }
コード例 #23
0
 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, bool ignoreMissingValues, string variable = null) {
   this.Correlation = correlation;
   this.Calculcator = calculator;
   this.Partition = partition;
   this.IgnoreMissingValues = ignoreMissingValues;
   this.Variable = variable;
 }
コード例 #24
0
            public void SetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues, double[,] correlation)
            {
                var key = Tuple.Create(calc, partition, ignoreMissingValues);

                correlationsCache[key] = correlation;
            }
コード例 #25
0
 public double[,] GetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues) {
   double[,] corr;
   var key = Tuple.Create(calc, partition, ignoreMissingValues);
   correlationsCache.TryGetValue(key, out corr);
   return corr;
 }
コード例 #26
0
 public void SetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues, double[,] correlation) {
   var key = Tuple.Create(calc, partition, ignoreMissingValues);
   correlationsCache[key] = correlation;
 }
コード例 #27
0
 public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
   double[,] corr;
   var key = new Tuple<IDependencyCalculator, string>(calc, partition);
   correlationsCache.TryGetValue(key, out corr);
   return corr;
 }
コード例 #28
0
 public void SetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable, double[,] correlation) {
   var key = new Tuple<IDependencyCalculator, string, string>(calc, partition, variable);
   timeFrameCorrelationsCache[key] = correlation;
 }
コード例 #29
0
 public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {
   this.Correlation = correlation;
   this.Calculcator = calculator;
   this.Partition = partition;
   this.Variable = variable;
 }
コード例 #30
0
 protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, bool ignoreMissingValues, string variable = null) {
   var handler = CorrelationCalculationFinished;
   if (handler != null)
     handler(this, new CorrelationCalculationFinishedArgs(correlation, calculator, partition, ignoreMissingValues, variable));
 }
コード例 #31
0
 public double[,] GetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable) {
   double[,] corr;
   var key = new Tuple<IDependencyCalculator, string, string>(calc, partition, variable);
   timeFrameCorrelationsCache.TryGetValue(key, out corr);
   return corr;
 }
コード例 #32
0
            public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation)
            {
                var key = new Tuple <IDependencyCalculator, string>(calc, partition);

                correlationsCache[key] = correlation;
            }
コード例 #33
0
 public void CalculateElements(IDependencyCalculator calc, string partition)
 {
     CalculateElements(problemData.Dataset, calc, partition);
 }
コード例 #34
0
 public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {
   var key = new Tuple<IDependencyCalculator, string>(calc, partition);
   correlationsCache[key] = correlation;
 }