Files
jube-fork/Accord.Statistics/Testing/Contingency/McNemarTest.cs
richard-churchman cc0a2bee21 Extensive modifications to the serialisation of Neural Network models to support Newtonsoft Json.net rather than Binary Serializer.
Included open-source Accord.net library code natively to the solution given the deprecated state of that project.  Accord.net will be supported inside Jube for own needs (such as upgrading to .Net 7+).

Accord.net libraries modified to compile to .Net 6.

Modified Accord.net libraries to better support Newtonsoft Json.net serialisation.

Included annotations in the Accord.net libraries to house important dependency statistics. Serialised json can be used independently of Jube to recall a Neural Network.

Removal of Binary Serializer totally as a precursor to the projects support of .Net 7+.

Extensive bug fixing in crucial functions of Neural Network training and recall.  While this part of the system remains in Alpha, it is substantially more fit for purpose.
2023-12-24 10:22:22 +01:00

87 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Accord Statistics Library
// The Accord.NET Framework
// http://accord-framework.net
//
// Copyright © César Souza, 2009-2017
// cesarsouza at gmail.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
namespace Accord.Statistics.Testing
{
using System;
using Accord.Statistics.Analysis;
using Accord.Compat;
/// <summary>
/// McNemar test of homogeneity for <c>2 x 2</c> contingency tables.
/// </summary>
///
/// <remarks>
/// <para>
/// McNemar's test is a non-parametric method used on nominal data. It is applied to
/// 2 × 2 contingency tables with a dichotomous trait, with matched pairs of subjects,
/// to determine whether the row and column marginal frequencies are equal, i.e. if
/// the contingency table presents marginal homogeneity.</para>
///
/// <para>
/// This is a <see cref="ChiSquareTest">Chi-square kind of test</see>.</para>
///
/// <para>
/// References:
/// <list type="bullet">
/// <item><description>
/// Wikipedia contributors, "McNemar's test," Wikipedia, The Free Encyclopedia,
/// Available on: http://http://en.wikipedia.org/wiki/McNemar's_test. </description></item>
/// </list></para>
/// </remarks>
///
/// <seealso cref="ChiSquareTest"/>
///
[Serializable]
public class McNemarTest : ChiSquareTest
{
/// <summary>
/// Creates a new McNemar test.
/// </summary>
///
/// <param name="matrix">The contingency table to test.</param>
/// <param name="yatesCorrection">True to use Yate's correction of
/// continuity, falser otherwise. Default is false.</param>
///
public McNemarTest(ConfusionMatrix matrix, bool yatesCorrection = false)
{
//int a = matrix.TruePositives;
int b = matrix.FalseNegatives;
int c = matrix.FalsePositives;
//int d = matrix.TrueNegatives;
double u = b - c;
if (yatesCorrection)
u = Math.Abs(u) - 0.5;
double chiSquare = (u * u) / (b + c);
int df = 1;
Compute(chiSquare, df);
}
}
}