public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { var confusionMatrix = ConfusionMatrixCalculator.Calculate(originalValues, estimatedValues, out errorState); if (!errorState.Equals(OnlineCalculatorError.None)) { return double.NaN; } return CalculateMCC(confusionMatrix); }
public static double Calculate(IEnumerable <double> originalValues, IEnumerable <double> estimatedValues, out OnlineCalculatorError errorState) { var confusionMatrix = ConfusionMatrixCalculator.Calculate(originalValues, estimatedValues, out errorState); if (!errorState.Equals(OnlineCalculatorError.None)) { return(double.NaN); } return(CalculateMCC(confusionMatrix)); }
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); }
public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { if (originalValues.Distinct().Skip(2).Any()) { // TODO: we could use ClassificationPerformanceMeasuresCalculator instead of the ConfusionMatrixCalculator below to handle multi-class problems throw new ArgumentException("F1 score can only be calculated for binary classification."); } var confusionMatrix = ConfusionMatrixCalculator.Calculate(originalValues, estimatedValues, out errorState); if (!errorState.Equals(OnlineCalculatorError.None)) { return double.NaN; } return CalculateFOne(confusionMatrix); }
public static double Calculate(IEnumerable <double> originalValues, IEnumerable <double> estimatedValues, out OnlineCalculatorError errorState) { if (originalValues.Distinct().Skip(2).Any()) { // TODO: we could use ClassificationPerformanceMeasuresCalculator instead of the ConfusionMatrixCalculator below to handle multi-class problems throw new ArgumentException("F1 score can only be calculated for binary classification."); } var confusionMatrix = ConfusionMatrixCalculator.Calculate(originalValues, estimatedValues, out errorState); if (!errorState.Equals(OnlineCalculatorError.None)) { return(double.NaN); } return(CalculateFOne(confusionMatrix)); }
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); }
private void BwCalculateTimeframeCorrelation(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; string variable = bwInfo.Variable; int frames = bwInfo.Frames; double[,] alreadyCalculated = bwInfo.AlreadyCalculated; IList <string> doubleVariableNames = dataset.DoubleVariables.ToList(); OnlineCalculatorError error = OnlineCalculatorError.None; 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); } 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> var1 = problemData.Dataset.GetDoubleValues(variable, indices); IEnumerable <double> var2 = problemData.Dataset.GetDoubleValues(doubleVariableNames[i], indices); var valuesInFrame = var1.Take(j); var help = var1.Skip(j).ToList(); help.AddRange(valuesInFrame); var1 = help; elements[i, j] = calc.Calculate(var1, var2, 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); }