public void ChiSquare04() { FourFoldContingencyTable table = new FourFoldContingencyTable(103, 0, 5, 6074); Assert.AreEqual(0.0D, table.ChiSquareValue(), "FFTQ038"); //TODO BUG (chyba hlasena Karbymu) //Assert.IsTrue(CloseEnough(6, table.ChiSquareValue(), 0.0550538165123782D)); }
public void ChiSquare01() { FourFoldContingencyTable table = new FourFoldContingencyTable(21, 1, 71, 141); Assert.IsTrue(table.ChiSquareValidity(0.05D), "FFTQ032"); //Assert.AreEqual(1.48276669831304e-08D, table.ChiSquareValue()); Assert.IsTrue(table.ChiSquareValue() < 1e-07D, "FFTQ033"); // correct value should be 1.48276595040141e-08 }
public void ContingecyTable01() { FourFoldContingencyTable table = new FourFoldContingencyTable(103, 0, 5, 6074); Assert.AreEqual(table.K, 108, "FFTQ007"); Assert.AreEqual(table.L, 6074, "FFTQ008"); Assert.AreEqual(table.R, 103, "FFTQ009"); Assert.AreEqual(table.S, 6079, "FFTQ010"); Assert.AreEqual(table.N, 6182, "FFTQ011"); Assert.AreEqual(table.A, 103, "FFTQ012"); Assert.AreEqual(table.B, 0, "FFTQ013"); Assert.AreEqual(table.C, 5, "FFTQ014"); Assert.AreEqual(table.D, 6074, "FFTQ015"); }
public void ContingecyTable02() { FourFoldContingencyTable table = new FourFoldContingencyTable(103, 0, 5, 6074, 2); Assert.AreEqual(table.K, (double)108 / 2, "FFTQ016"); Assert.AreEqual(table.L, (double)6074 / 2, "FFTQ017"); Assert.AreEqual(table.R, (double)103 / 2, "FFTQ018"); Assert.AreEqual(table.S, (double)6079 / 2, "FFTQ019"); Assert.AreEqual(table.N, (double)6182 / 2, "FFTQ020"); Assert.AreEqual(table.A, (double)103 / 2, "FFTQ021"); Assert.AreEqual(table.B, (double)0 / 2, "FFTQ022"); Assert.AreEqual(table.C, (double)5 / 2, "FFTQ023"); Assert.AreEqual(table.D, (double)6074 / 2, "FFTQ024"); }
public void CreateFourFoldTable04() { int[][] arrayTable = new int[3][] { new int[2] { 0, 5 }, new int[2] { 23, 45 }, new int[2] { 23, 45 } }; FourFoldContingencyTable table = new FourFoldContingencyTable(arrayTable); Assert.IsNull(table, "FFTQ005: FFTable was created with bad shape of table (not int[2,2])!"); }
public void SetUp() { this.table = new FourFoldContingencyTable(30, 1, 23, 45); }
/// <summary> /// Returns the <c>a</c> frequency from 4ft-table. /// Gets the <c>a</c> frequency of the 4f-table (four fold table). (divided by the /// <see cref="F:Ferda.Modules.Quantifiers.ContingencyTable.denominator"/>) /// </summary> /// <result>The <c>a</c> frequency of the 4f-table (four fold table).</result> public static double BaseCeilValue(FourFoldContingencyTable table) { return table.A; }
/// <summary> /// Computes the statistical strength value at the specified significance (alpha). /// </summary> /// <returns>Statistical strength value at the specified significance (alpha).</returns> /// <remarks> /// <para>Computes the numerical solution of the following equation (for variable p):</para> /// <para><c>Sum[i = 0..a] x! / (i! * (x - i)!) * p^i * (1.0 - p)^(x - i) - alpha = 0.0</c>, /// where <c>x = (a + b + c)</c>.</para> /// <para>The solution must be between 0.0 and 1.0 (inclusive).</para> /// </remarks> public override double Value(AbstractQuantifierSetting setting, Ice.Current __current) { FourFoldContingencyTable table = new FourFoldContingencyTable(setting.firstContingencyTableRows); return table.DoubleCriticalImplicationValue(Alpha); }
/// <summary> /// Returns XML string with all occurences of Active element "4FT hypothesis". /// </summary> /// <param name="index">index of data source in FEplugin data sources table</param> /// <returns>XML string</returns> public static string getList(int index) { string resultString = ""; // result XML string // loading DTD to resultString try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { #if (LADENI) MessageBox.Show("error while loading DTD: " + e.Message); #endif return resultString; } // root element resultString += "<active_list>"; string PropName = "Hypotheses"; // name of Property, which contain list of hypotheses // searching all boxes with type "4FT-task" IBoxModule[] FFTTaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.FFTTask"); // loop over all boxes - getting all hypotheses string ErrStr = ""; // error report string matrix_name = "unknown"; // analyzed data matrix name string db_name="unknown"; // analyzed database name string task_name = "unknown"; // task name - given with user name of box FFTTast #region Loop - processing of each 4ft-Task from array FFTTaskBoxes foreach (IBoxModule box in FFTTaskBoxes) { try { // searching data source name (database) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // searched more than one data source or neither one throw new System.Exception("found " + db_names.GetLength(0).ToString() + " databases"); db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // searching data matrix name IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // searched more than one data source or neither one throw new System.Exception("found " + matrix_names.GetLength(0).ToString() + " data matrixes"); matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // searching task name task_name = box.UserName; // searching the list of all hypotheses in this task HypothesesT HypT = box.GetPropertyOther(PropName) as HypothesesT; HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[]; // records for storing the results Rec_hyp_4ft rHyp = new Rec_hyp_4ft(); // hypothesis Rec_ti_cedent rAnt = new Rec_ti_cedent(); // antecedent Rec_ti_cedent rSuc = new Rec_ti_cedent(); // succedent Rec_ti_cedent rCon = new Rec_ti_cedent(); // condition #region Loop - processing of each hypotez jedne krabicky FFTTask // Loop over all hypotheses for (int i = 0; i < HypList.GetLength(0); i++) { #region element hyp_4ft rHyp.id = "hyp4ft" + box.ProjectIdentifier.ToString() + "_" + i.ToString(); rHyp.db_name = db_name; rHyp.matrix_name = matrix_name; rHyp.task_name = task_name; rHyp.antecedent = "ant" + rHyp.id; rHyp.succedent = "suc" + rHyp.id; rHyp.condition = "con" + rHyp.id; FourFoldContingencyTable FFT = new FourFoldContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows); rHyp.a = FFT.A.ToString(); rHyp.b = FFT.B.ToString(); rHyp.c = FFT.C.ToString(); rHyp.d = FFT.D.ToString(); // values of quantifiers rHyp.conf = FourFoldContingencyTable.FoundedImplicationValue(FFT).ToString(); // Founded implication (a/a+b) rHyp.d_conf = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT).ToString(); // Double Founded implication (a/a+b+c) rHyp.e_conf = FourFoldContingencyTable.FoundedEquivalenceValue(FFT).ToString(); // Founded Equivalence (a+d)/(a+b+c+d) ??? BUG ve Ferdovi rHyp.support = FourFoldContingencyTable.BaseCeilValue(FFT).ToString(); //??? Support (a/a+b+c+d) // helping variable double avg_diff = FourFoldContingencyTable.AboveAverageImplicationValue(FFT) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1) rHyp.avg_diff = avg_diff.ToString(); rHyp.fisher = FFT.FisherValue().ToString(); rHyp.chi_sq = FFT.ChiSquareValue().ToString(); #endregion #region element ti_cedent (Antecedent) rAnt.id = "ant" + rHyp.id; rAnt.type = "Antecedent"; // literals int litCounter = 0; // counter of literals of this hypotheses List<Rec_ti_literal> Lit_a = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Antecedent) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_a.Add(l); } } #endregion #region element ti_cedent (Succedent) rSuc.id = "suc" + rHyp.id; rSuc.type = "Succedent"; // literals List<Rec_ti_literal> Lit_s = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Succedent) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_s.Add(l); } } #endregion #region element ti_cedent (Condition) rCon.id = "con" + rHyp.id; rCon.type = "Condition"; // literals List<Rec_ti_literal> Lit_c = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Condition) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_c.Add(l); } } #endregion #region Generating of one hypotheses to XML string string oneHypString = ""; // generating hypotheses to XML oneHypString += rHyp.ToXML(); // generating Antecedent to XML oneHypString += rAnt.ToXML(Lit_a); // generating Succedent to XML oneHypString += rSuc.ToXML(Lit_s); // generating Condition to XML oneHypString += rCon.ToXML(Lit_c); resultString += oneHypString; #endregion } #endregion } catch (System.Exception e) { ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n"; } } #endregion // root element resultString += "</active_list>"; #if (LADENI) // generating of error message: if (!String.IsNullOrEmpty(ErrStr)) MessageBox.Show("Pri nacitani hypotez doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error); // Kody - storing output to file "XML4fthypExample.xml" in directory XMLHelper.saveXMLexample(resultString, "../XML/XML4fthypExample.xml"); #endif return resultString; }
/// <summary> /// The 4ft-quantifier chi-square is valid, if the null hypothesis of independence between antecedent and succedent is rejected, /// thus we say that antecedent and succedent are not independent. /// </summary> /// <returns><c>true</c> if the null hypothesis of independence is rejected.</returns> public override bool Validity(AbstractQuantifierSetting setting, Ice.Current __current) { FourFoldContingencyTable table = new FourFoldContingencyTable(setting.firstContingencyTableRows); return table.ChiSquareValidity(Alpha); }
/// <summary> /// Computes the <c>strength</c>. /// </summary> /// <returns>The strength defined as <c>a / (a + b + c)</c>.</returns> /// <remarks> /// <para>If (a + b + c) = 0, returns 0.</para> /// </remarks> public static double DoubleFoundedImplicationValue(FourFoldContingencyTable table) { double a = table.A; double sum = a + table.B + table.C; return (sum > 0) ? (a / sum) : 0.0D; }
public void CreateFourFoldTable02() { int[][] arrayTable = new int[2][] { new int[2] { -30, 1 }, new int[2] { 23, 45 } }; FourFoldContingencyTable table = new FourFoldContingencyTable(arrayTable); Assert.IsNull(table, "FFTQ003: FFTable was created with frequency less than 0!"); }
public void ChiSquare02() { FourFoldContingencyTable table = new FourFoldContingencyTable(12, 14, 11, 13); Assert.IsFalse(table.ChiSquareValidity(0.05D), "FFTQ034"); Assert.IsTrue(closeEnough(6, table.ChiSquareValue(), 0.981874933633231), "FFTQ035"); }
// ==================== 4ft-hypoteza ================================ public static string fFE4fthyp(int index) { string resultString = ""; // vysledny XML string // nacteni DTD do resultStringu try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { MessageBox.Show("Chyba pri nacitani DTD: " + e.Message); return resultString; } // korenovy element resultString += "<active_list>"; string PropName = "Hypotheses"; // nazev Property, ktera obsahuje seznam hypotez // nalezeni vsech krabicek 4FT-uloh IBoxModule[] FFTTaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.FFTTask"); // zpracovani kazde krabicky - ziskani z ni vsechny 4ft-hypotezy string ErrStr = ""; // zaznam o chybach string matrix_name = ""; // jmeno analyzovane matice string db_name = ""; // jmeno analyzovane databaze string task_name = ""; // jmeno ulohy - dano uzivatelskym nazvem krabicky FFTTast #region Cyklus - zpracovani vsech 4ft-Tasku z pole FFTTaskBoxes foreach (IBoxModule box in FFTTaskBoxes) { try { // nalezeni jmena datoveho zdroje (databaze) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // byl nalezen pocet datovych zdroju ruzny od jedne throw new System.Exception("bylo nalezeno " + db_names.GetLength(0).ToString() + " databazi"); db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // nalezeni jmena datove matice IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // byl nalezen pocet datovych matic ruzny od jedne throw new System.Exception("bylo nalezeno " + matrix_names.GetLength(0).ToString() + " datovych matic"); matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // nalezeni jmena ulohy task_name = box.UserName; // nalezeni seznamu vsech hypotez v tomto Tasku HypothesesT HypT = box.GetPropertyOther(PropName) as HypothesesT; HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[]; // recordy pro ukladani vysledku Rec_hyp_4ft rHyp = new Rec_hyp_4ft(); // hypoteza Rec_ti_cedent rAnt = new Rec_ti_cedent(); // antecedent Rec_ti_cedent rSuc = new Rec_ti_cedent(); // succedent Rec_ti_cedent rCon = new Rec_ti_cedent(); // condition #region Cyklus - zpracovani vsech hypotez jedne krabicky FFTTask // cyklus pres vsechny hypotezy for (int i = 0; i < HypList.GetLength(0); i++) { #region element hyp_4ft rHyp.id = "hyp4ft" + box.ProjectIdentifier.ToString() + "_" + i.ToString(); rHyp.db_name = db_name; rHyp.matrix_name = matrix_name; rHyp.task_name = task_name; rHyp.antecedent = "ant" + rHyp.id; rHyp.succedent = "suc" + rHyp.id; rHyp.condition = "con" + rHyp.id; FourFoldContingencyTable FFT = new FourFoldContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows); rHyp.a = FFT.A; rHyp.b = FFT.B; rHyp.c = FFT.C; rHyp.d = FFT.D; // hodnoty kvantifikatoru rHyp.conf = FourFoldContingencyTable.FoundedImplicationValue(FFT); // Founded implication (a/a+b) rHyp.d_conf = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT); // Double Founded implication (a/a+b+c) rHyp.e_conf = FourFoldContingencyTable.FoundedEquivalenceValue(FFT); // Founded Equivalence (a+d)/(a+b+c+d) ??? BUG ve Ferdovi rHyp.support = FourFoldContingencyTable.BaseCeilValue(FFT); //??? Support (a/a+b+c+d) rHyp.avg_diff = FourFoldContingencyTable.AboveAverageImplicationValue(FFT) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1) // tyto hodnoty se vypocitavaji (mozna zbytecne?) rHyp.fisher = FFT.FisherValue(); rHyp.chi_sq = FFT.ChiSquareValue(); #endregion // TODO - dodelat vypocty, ostatni ciselne polozky (hodnoty nekterych kvantifikatoru atd.) #region element ti_cedent (Antecedent) rAnt.id = "ant" + rHyp.id; rAnt.type = "Antecedent"; // literaly int litCounter = 0; // pocitadlo literalu teto hypotezy ArrayList ARLit_a = new ArrayList(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Antecedent) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if(lit.negation) l.quant = "¬"; l.quant = lit.literalName; foreach (string s in lit.categoriesNames) l.value += s; ARLit_a.Add(l); } } Rec_ti_literal[] ALit_a = (Rec_ti_literal[])ARLit_a.ToArray(typeof(Rec_ti_literal)); // pole literalu daneho cedentu #endregion #region element ti_cedent (Succedent) rSuc.id = "suc" + rHyp.id; rSuc.type = "Succedent"; // literaly ArrayList ARLit_s = new ArrayList(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Succedent) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant = lit.literalName; foreach (string s in lit.categoriesNames) l.value += s; ARLit_s.Add(l); } } Rec_ti_literal[] ALit_s = (Rec_ti_literal[])ARLit_s.ToArray(typeof(Rec_ti_literal)); // pole literalu daneho cedentu #endregion #region element ti_cedent (Condition) rCon.id = "con" + rHyp.id; rCon.type = "Condition"; // literaly ArrayList ARLit_c = new ArrayList(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Condition) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant = lit.literalName; foreach (string s in lit.categoriesNames) l.value += s; ARLit_s.Add(l); } } Rec_ti_literal[] ALit_c = (Rec_ti_literal[])ARLit_c.ToArray(typeof(Rec_ti_literal)); // pole literalu daneho cedentu #endregion #region Vypsani jedne hypotezy do XML stringu string oneHypString = ""; // vypsani hypotezy do XML oneHypString += rHyp.ToXML(); // vypsani Antecedentu do XML oneHypString += rAnt.ToXML(ALit_a); // vypsani Succedentu do XML oneHypString += rSuc.ToXML(ALit_s); // vypsani Condition do XML oneHypString += rCon.ToXML(ALit_c); resultString += oneHypString; #endregion } #endregion } catch (System.Exception e) { ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n"; } } #endregion // vypsani pripadne chybove hlasky: if (!String.IsNullOrEmpty(ErrStr)) MessageBox.Show("Pri nacitani hypotez doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error); // korenovy element resultString += "</active_list>"; // Kody - ulozeni vystupu do souboru "XML4fthypExample.xml" v adresari XMLHelper.saveXMLexample(resultString, "../XML/XML4fthypExample.xml"); return resultString; }
/// <summary> /// Returns <c>true</c> if the simple deviation strength is greater than or equal to the strength parameter. /// </summary> /// <returns><c>true</c> iff <c>(a * d) >= 2^k * (b * c)</c>.</returns> /// <remarks> /// <para>There are special cases defined explicitly:</para> /// <para>If both <c>(a * d) = 0</c> and <c>(b * c) = 0</c>, return true if <c>k <= 0</c>.</para> /// <para>If only <c>(a * d) = 0</c>, return <c>false</c>.</para> /// <para>If only <c>(b * c) = 0</c>, return <c>true</c>.</para> /// </remarks> public override bool Validity(AbstractQuantifierSetting setting, Ice.Current __current) { FourFoldContingencyTable table = new FourFoldContingencyTable(setting.firstContingencyTableRows); return table.SimpleDeviationValidity(K); }
/// <summary> /// Returns XML string with all occurences of Active element "SD-4FFT hypothesis". /// </summary> /// <param name="index">index of data source in FEplugin data sources table</param> /// <returns>XML string</returns> public static string getList(int index) { string resultString = ""; // result XML string // loading DTD to resultString try { resultString = XMLHelper.loadDTD(); } catch (Exception e) { #if (LADENI) MessageBox.Show("error while loading DTD: " + e.Message); #endif return resultString; } // root element resultString += "<active_list>"; string PropName = "Hypotheses"; // name of property which contain a list of hypotheses // searching all boxes SD-4FT-uloh IBoxModule[] TaskBoxes = BoxesHelper.ListBoxesWithID(CFEsourcesTab.Sources[index] as CFEsource, "LISpMinerTasks.SDFFTTask"); // processing of each box - searching all 4ft-hypotheses string ErrStr = ""; // error report string matrix_name = "unknown"; // analyzed data matrix name string db_name="unknown"; // analyzed database name string task_name = "unknown"; // task name - given with user name of box FFTTast // creating delegate of quantifier function - "sum of value" ContingencyTable.QuantifierValue<FourFoldContingencyTable> sum_delegat = new ContingencyTable.QuantifierValue<FourFoldContingencyTable>(FourFoldContingencyTable.GetSumOfValues); #region Loop - processing of each SD-4ft-Task from array TaskBoxes foreach (IBoxModule box in TaskBoxes) { try { // searching data source name (database) IBoxModule[] db_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.Database"); if (db_names.GetLength(0) != 1) // searched more than one data source or neither one throw new System.Exception("found " + db_names.GetLength(0).ToString() + " databases"); db_name = (db_names[0].GetPropertyOther("DatabaseName") as StringT).stringValue; // searching data matrix name IBoxModule[] matrix_names = BoxesHelper.ListAncestBoxesWithID(box, "DataMiningCommon.DataMatrix"); if (matrix_names.GetLength(0) != 1) // searched more than one data source or neither one throw new System.Exception("found " + matrix_names.GetLength(0).ToString() + " data matrixes"); matrix_name = (matrix_names[0].GetPropertyOther("Name") as StringT).stringValue; // searching task name task_name = box.UserName; // searching the list of all hypotheses in this task HypothesesT HypT = box.GetPropertyOther(PropName) as HypothesesT; HypothesisStruct[] HypList = HypT.hypothesesValue.Clone() as HypothesisStruct[]; // records for storing the results Rec_hyp_sd4ft rHyp = new Rec_hyp_sd4ft(); // hypothesis Rec_ti_cedent rAnt = new Rec_ti_cedent(); // antecedent Rec_ti_cedent rSuc = new Rec_ti_cedent(); // succedent Rec_ti_cedent rCon = new Rec_ti_cedent(); // condition Rec_ti_cedent rSet1 = new Rec_ti_cedent(); // set 1 Rec_ti_cedent rSet2 = new Rec_ti_cedent(); // set 2 #region Loop - processing of each hypotheses of one SDFFTTask box // Loop over all hypotheses for (int i = 0; i < HypList.GetLength(0); i++) { #region element hyp_sd4ft rHyp.id = "hypsd4ft" + box.ProjectIdentifier.ToString() + "_" + i.ToString(); rHyp.db_name = db_name; rHyp.matrix_name = matrix_name; rHyp.task_name = task_name; rHyp.antecedent = "ant" + rHyp.id; rHyp.succedent = "suc" + rHyp.id; rHyp.condition = "con" + rHyp.id; rHyp.set1 = "set1" + rHyp.id; rHyp.set2 = "set2" + rHyp.id; FourFoldContingencyTable FFT1 = new FourFoldContingencyTable(HypList[i].quantifierSetting.firstContingencyTableRows); FourFoldContingencyTable FFT2 = new FourFoldContingencyTable(HypList[i].quantifierSetting.secondContingencyTableRows); rHyp.a = FFT1.A.ToString(); rHyp.b = FFT1.B.ToString(); rHyp.c = FFT1.C.ToString(); rHyp.d = FFT1.D.ToString(); rHyp.e = FFT2.A.ToString(); rHyp.f = FFT2.B.ToString(); rHyp.g = FFT2.C.ToString(); rHyp.h = FFT2.D.ToString(); // values of quantifiers - first set double conf1 = FourFoldContingencyTable.FoundedImplicationValue(FFT1); // Founded implication (a/a+b) rHyp.conf1 = conf1.ToString(); double d_conf1 = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT1); // Double Founded implication (a/a+b+c) rHyp.d_conf1 = d_conf1.ToString(); double e_conf1 = FourFoldContingencyTable.FoundedEquivalenceValue(FFT1); // Founded Equivalence (a+d)/(a+b+c+d) ??? BUG ve Ferdovi rHyp.e_conf1 = e_conf1.ToString(); rHyp.support1 = FourFoldContingencyTable.BaseCeilValue(FFT1).ToString(); //??? Support (a/a+b+c+d) // helping variable double avg_diff1 = FourFoldContingencyTable.AboveAverageImplicationValue(FFT1) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1) rHyp.avg_diff1 = avg_diff1.ToString(); rHyp.fisher1 = FFT1.FisherValue().ToString(); rHyp.chi_sq1 = FFT1.ChiSquareValue().ToString(); // values of quantifiers - second set double conf2 = FourFoldContingencyTable.FoundedImplicationValue(FFT2); // Founded implication (a/a+b) rHyp.conf2 = conf2.ToString(); double d_conf2 = FourFoldContingencyTable.DoubleFoundedImplicationValue(FFT2); // Double Founded implication (a/a+b+c) rHyp.d_conf2 = d_conf2.ToString(); double e_conf2 = FourFoldContingencyTable.FoundedEquivalenceValue(FFT2); // Founded Equivalence (a+d)/(a+b+c+d) ??? BUG ve Ferdovi rHyp.e_conf2 = e_conf2.ToString(); rHyp.support2 = FourFoldContingencyTable.BaseCeilValue(FFT2).ToString(); //??? Support (a/a+b+c+d) // helping variable double avg_diff2 = FourFoldContingencyTable.AboveAverageImplicationValue(FFT2) - 1; // Averafe difference ((a*(a+b+c+d))/((a+b)*(a+c)) -1) rHyp.avg_diff2 = avg_diff2.ToString(); rHyp.fisher2 = FFT2.FisherValue().ToString(); rHyp.chi_sq2 = FFT2.ChiSquareValue().ToString(); // values of quantifiers - diffrent of first and second set rHyp.dr_sum = FourFoldContingencyTable.Value<FourFoldContingencyTable>(sum_delegat, FFT1, FFT2, OperationModeEnum.DifferencesOfRelativeFrequencies).ToString(); double df_conf = FourFoldContingencyTable.Combine(conf1, conf2, OperationModeEnum.DifferenceOfQuantifierValues); rHyp.df_conf = df_conf.ToString(); double df_dfui = FourFoldContingencyTable.Combine(d_conf1, d_conf2, OperationModeEnum.DifferenceOfQuantifierValues); rHyp.df_dfui = df_dfui.ToString(); double df_fue = FourFoldContingencyTable.Combine(e_conf1, e_conf2, OperationModeEnum.DifferenceOfQuantifierValues); rHyp.df_fue = df_fue.ToString(); double df_avg = FourFoldContingencyTable.Combine(avg_diff1, avg_diff2, OperationModeEnum.DifferenceOfQuantifierValues); rHyp.df_avg = df_avg.ToString(); #endregion #region element ti_cedent (Antecedent) rAnt.id = rHyp.antecedent; rAnt.type = "Antecedent"; // literals int litCounter = 0; // counter of literals of this hypotheses List<Rec_ti_literal> Lit_a = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Antecedent) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_a.Add(l); } } #endregion #region element ti_cedent (Succedent) rSuc.id = rHyp.succedent; rSuc.type = "Succedent"; // literals List<Rec_ti_literal> Lit_s = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Succedent) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_s.Add(l); } } #endregion #region element ti_cedent (Condition) rCon.id = rHyp.condition; rCon.type = "Condition"; // literals List<Rec_ti_literal> Lit_c = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.Condition) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_c.Add(l); } } #endregion #region element ti_cedent (First Set) rSet1.id = rHyp.set1; rSet1.type = "First Set"; // literals List<Rec_ti_literal> Lit_s1 = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.FirstSet) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_s1.Add(l); } } #endregion #region element ti_cedent (Second Set) rSet2.id = rHyp.set2; rSet2.type = "Second Set"; // literals List<Rec_ti_literal> Lit_s2 = new List<Rec_ti_literal>(); foreach (BooleanLiteralStruct lit in HypList[i].booleanLiterals) { if (lit.cedentType == CedentEnum.SecondSet) { Rec_ti_literal l = new Rec_ti_literal(); l.id = "tiLit" + rHyp.id + "_" + litCounter.ToString(); litCounter++; if (lit.negation) l.quant = "¬"; l.quant += lit.literalName; int counter = 0; foreach (string s in lit.categoriesNames) { if (counter > 0) l.value += ","; l.value += s; counter++; } Lit_s2.Add(l); } } #endregion #region Generating of one hypotheses to XML string string oneHypString = ""; // generating hypotheses to XML oneHypString += rHyp.ToXML(); // generating Antecedent to XML oneHypString += rAnt.ToXML(Lit_a); // generating Succedent to XML oneHypString += rSuc.ToXML(Lit_s); // generating Condition to XML oneHypString += rCon.ToXML(Lit_c); // generating First Set to XML oneHypString += rSet1.ToXML(Lit_s1); // generating Second Set to XML oneHypString += rSet2.ToXML(Lit_s2); resultString += oneHypString; #endregion } #endregion } catch (System.Exception e) { ErrStr += "Box ProjectIdentifier=" + box.ProjectIdentifier.ToString() + ": " + e.Message + "\n"; } } #endregion // root element resultString += "</active_list>"; #if (LADENI) // generating of error message: if (!String.IsNullOrEmpty(ErrStr)) // LADICI MessageBox.Show("Pri nacitani SD4FT hypotheses doslo k chybam:\n" + ErrStr, "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error); // LADICI - Kody - storing output to file "XMLsd4fthypExample.xml" in directory XMLHelper.saveXMLexample(resultString, "../XML/XMLsd4fthypExample.xml"); #endif return resultString; }
/// <summary> /// Computes the <c>confidence</c>. /// </summary> /// <returns>The confidence defined as <c>a / (a + b)</c>.</returns> /// <remarks> /// <para>If (a + b) = 0, returns 0.</para> /// </remarks> public static double FoundedImplicationValue(FourFoldContingencyTable table) { double r = table.R; return (r > 0) ? (table.A) / r : 0.0D; }
/// <summary> /// Computes the <c>strength</c> of founded equivalence. /// </summary> /// <returns>The strength defined as <c>(a + d) / (a + b + c + d)</c>.</returns> /// <remarks> /// <para>If (a + b + c + d) = 0, returns 0.</para> /// </remarks> public static double FoundedEquivalenceValue(FourFoldContingencyTable table) { double n = table.N; return (n > 0) ? (table.A) / n : 0.0D; }
public void ChiSquare03() { FourFoldContingencyTable table = new FourFoldContingencyTable(252, 143, 847, 602); Assert.IsFalse(table.ChiSquareValidity(0.05D), "FFTQ036"); Assert.IsTrue(closeEnough(6, table.ChiSquareValue(), 0.0550538165123782D), "FFTQ037"); }
public void CreateFourFoldTable05() { long[,] arrayTable = new long[2, 2] { { 30, 1 }, { 23, 45 } }; FourFoldContingencyTable table = new FourFoldContingencyTable(arrayTable); Assert.IsNotNull(table, "FFTQ006: FFTable wasn`t created!"); }
public void E01() { FourFoldContingencyTable table = new FourFoldContingencyTable(103, 0, 5, 6074); Assert.AreEqual(0.999191200258816D, table.EValue(), "FFTQ041"); Assert.IsTrue(table.EValidity(0.5D), "FFTQ042"); Assert.IsFalse(table.EValidity(0.999999D), "FFTQ043"); }
public void Fischer01() { FourFoldContingencyTable table = new FourFoldContingencyTable(103, 0, 5, 6074); Assert.AreEqual(0.0f, (float)table.FisherValue(), "FFTQ039"); Assert.AreEqual(8.46676800899516e-219D, table.FisherValue(), "FFTQ040"); }
public void CreateFourFoldTable00() { int[][] arrayTable = new int[2][] { new int[2] { 30, 1 }, new int[2] { 23, 45 } }; FourFoldContingencyTable table = new FourFoldContingencyTable(arrayTable); Assert.IsNotNull(table, "FFTQ001: FFTable wasn`t created!"); }
public void FoundedImplication02() { FourFoldContingencyTable table = new FourFoldContingencyTable(103, 0, 5, 6074); Assert.AreEqual(1.0D, FourFoldContingencyTable.FoundedImplicationValue(table), "FFTQ026"); }
/// <summary> /// Returns value of expression (<c>a</c> + <c>d</c>) / (<c>a</c> + <c>b</c> + <c>c</c> + <c>d</c>) from 4ft-table. /// </summary> /// <returns>The value of expression (<c>a</c> + <c>d</c>) / (<c>a</c> + <c>b</c> + <c>c</c> + <c>d</c>) 4ft-table.</returns> public override double Value(AbstractQuantifierSetting setting, Ice.Current __current) { FourFoldContingencyTable table = new FourFoldContingencyTable(setting.firstContingencyTableRows); return table.EValue(); }
public void LowerCriticalImplication01() { FourFoldContingencyTable table = new FourFoldContingencyTable(10, 2, 0, 0); //FourFTQuantifiers.LowerCriticalImplication quantifier = new RelMiner.FourFTQuantifiers.LowerCriticalImplication(0.8f, 0.05f); Assert.IsFalse(table.CriticalImplicationValidity(0.8D, 0.05D, CoreRelationEnum.LessThanOrEqualCore), "FFTQ028"); Assert.AreEqual(0.561894564884689D, table.CriticalImplicationValue(0.05D), "FFTQ029"); //TODO I`m not sure }
/// <summary> /// Returns <c>true</c> if the statistical strength value is greater than or equal to the p parameter with the specified statistical significance (alpha). /// </summary> /// <returns><c>true</c> if if the statistical strength value is greater than or equal to the p parameter with the specified statistical significance (alpha).</returns> /// <remarks> /// <para>It computes the following condition:</para> /// <para>Sum[i = 0..a] x! / (i! * (x - i)!) * p^i * (1 - p)^(x - i) is in <c>relation</c> to alpha, /// where x = (a + b + c).</para> /// </remarks> public override bool Validity(AbstractQuantifierSetting setting, Ice.Current __current) { FourFoldContingencyTable table = new FourFoldContingencyTable(setting.firstContingencyTableRows); return table.DoubleCriticalImplicationValidity(P, Alpha, Relation); }
public void LowerCriticalImplication02() { FourFoldContingencyTable table = new FourFoldContingencyTable(100, 1, 0, 0); Assert.IsTrue(table.CriticalImplicationValidity(0.8D, 0.05D, CoreRelationEnum.LessThanOrEqualCore), "FFTQ030"); Assert.AreEqual(0.953892650075111D, table.CriticalImplicationValue(0.05D), "FFTQ031"); //TODO I`m not sure }
/// <summary> /// Computes the above average strength value. /// </summary> /// <returns>Above average strength value defined as <c>(a / (a + b)) * ((a + b + c + d) / (a + c))</c> if <c>a > 0</c>; otherwise it returns zero.</returns> /// <remarks> /// <para>If a = 0, returns 0.</para> /// </remarks> public override double Value(AbstractQuantifierSetting setting, Ice.Current __current) { FourFoldContingencyTable table = new FourFoldContingencyTable(setting.firstContingencyTableRows); return FourFoldContingencyTable.AboveAverageImplicationValue(table); }
/// <summary> /// Computes the above average strength result. /// </summary> /// <returns>Above average strength result defined as <c>(a / (a + b)) * ((a + b + c + d) / (a + c))</c> if <c>a > 0</c>; otherwise it returns zero.</returns> /// <remarks> /// <para>If a = 0, returns 0.</para> /// </remarks> public static double AboveAverageImplicationValue(FourFoldContingencyTable table) { return (table.A > 0) ? ((table.A * table.N) / (table.R * table.K)) : 0.0D; }