Skip to content

Commit

Permalink
Add tests for characteristics of dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
ChainsManipulator committed Nov 30, 2024
1 parent 6476e0c commit 4b5bc84
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 11 deletions.
9 changes: 4 additions & 5 deletions Libiada.Core.Tests/Core/ChainsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static class ChainsStorage

// 0 A A B A _ A _ _ B A
new Chain(
[1, 1, 2, 1, 0, 1, 0, 0, 2],
[1, 1, 2, 1, 0, 1, 0, 0, 2, 1],
[NullValue.Instance(), Elements["A"], Elements["B"]]),

// ----------- sequences from Morozenko's paper -----------
Expand Down Expand Up @@ -367,13 +367,12 @@ public static class ChainsStorage
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],
[NullValue.Instance(), Elements["A"], Elements["B"]]),

// 7 A _ _ _ _ _ _ _ _ _ B _ B B A _ _ A A A _ _ A _ _ _ _ _ B
// 7 A _ _ _ _ _ _ _ B _ B B A _ _ A A A _ _ A _ _ _ _ _ B
new Chain(
[1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 2, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 2],
[NullValue.Instance(), Elements["A"], Elements["B"]]),

// 8
// 7 A _ _ A _ _ B _ _ _ _ _ A A _ A _ A _ _ _ B _ A B
// 8 A _ _ A _ _ B _ _ _ _ _ A A _ A _ A _ _ _ B _ A B
new Chain(
[1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 2, 0, 1, 2],
[NullValue.Instance(), Elements["A"], Elements["B"]]),
Expand All @@ -388,7 +387,7 @@ public static class ChainsStorage
[1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0],
[NullValue.Instance(), Elements["A"], Elements["B"]]),

// 11 A _ B _ _ _ _ _ _ A _ B _ _ _ _ A _ _ B _ _ _ _ A B _ 0
// 11 A _ B _ _ _ _ _ _ A _ B _ _ _ _ A _ _ B _ _ _ _ A B _ _
new Chain(
[1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 1, 2, 0, 0],
[NullValue.Instance(), Elements["A"], Elements["B"]]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ protected void CalculationTest(int index, double firstValue, double secondValue)
CongenericChain secondChain = binaryChains[index].CongenericChain(elements["B"]);
double result1 = calculator.Calculate(firstChain, secondChain, Link.End);
double result2 = calculator.Calculate(secondChain, firstChain, Link.End);
Assert.That(result1, Is.EqualTo(firstValue).Within(0.0001d));
Assert.That(result2, Is.EqualTo(secondValue).Within(0.0001d));
Assert.Multiple(() =>
{
Assert.That(result1, Is.EqualTo(firstValue).Within(0.0001d));
Assert.That(result2, Is.EqualTo(secondValue).Within(0.0001d));
});
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ protected void CalculationTest(int index, double firstValue, double secondValue)
{
double result1 = Calculator.Calculate(Chains[index].GetRelationIntervalsManager(elements["A"], elements["B"]), Link.End);
double result2 = Calculator.Calculate(Chains[index].GetRelationIntervalsManager(elements["B"], elements["A"]), Link.End);
Assert.That(result1, Is.EqualTo(firstValue).Within(0.0001));
Assert.That(result2, Is.EqualTo(secondValue).Within(0.0001));
Assert.Multiple(() =>
{
Assert.That(result1, Is.EqualTo(firstValue).Within(0.0001));
Assert.That(result2, Is.EqualTo(secondValue).Within(0.0001));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ public class GeometricMeanTests : BinaryCalculatorsTests<GeometricMean>
/// The second value.
/// </param>
[TestCase(0, 1.7321, 1)]
[TestCase(1, 1, 0)]
[TestCase(2, 3, 0)]
[TestCase(3, 4.527019056, 2.080083823)]
[TestCase(4, 1, 0)]
[TestCase(5, 1, 0)]
[TestCase(6, 12, 0)]
[TestCase(7, 6.92820323, 1)]
[TestCase(8, 2.289428485, 3.464101615)]
[TestCase(9, 5.360108411, 1)]
[TestCase(10, 2, 2.5198421)]
[TestCase(11, 1.861209718, 5.59344471)]
[TestCase(12, 4, 4)]
[TestCase(13, 3, 2.466212074)]
[TestCase(14, 1, 3.556893304)]
[TestCase(15, 1, 1)]
[TestCase(16, 4.30886938, 3)]
[TestCase(17, 3.036588972, 4)]
[TestCase(19, 1, 5.646216173)]
public void SpatialDependenceTest(int index, double firstValue, double secondValue)
{
CalculationTest(index, firstValue, secondValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class InvolvedPartialDependenceCoefficientTests : BinaryCalculatorsTests<
/// <param name="secondValue">
/// The second value.
/// </param>
[TestCase(0, 0.285714286, 0.338143834)]
[TestCase(1, 0, 0)]
[TestCase(2, 0, 0)]
[TestCase(3, 0, 0.5461)]
Expand All @@ -38,6 +39,7 @@ public class InvolvedPartialDependenceCoefficientTests : BinaryCalculatorsTests<
[TestCase(15, 0.3429, 0.35)]
[TestCase(16, 0.3745, 0.3965)]
[TestCase(17, 0.6072, 0.3757)]
[TestCase(19, 0.759718859, -0.162330299)]
public void K2Test(int index, double firstValue, double secondValue)
{
CalculationTest(index, firstValue, secondValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MutualDependenceCoefficientTests : BinaryCalculatorsTests<MutualDep
/// <param name="value">
/// The value.
/// </param>
[TestCase(0, 0.310825552)]
[TestCase(1, 0)]
[TestCase(2, 0)]
[TestCase(3, 0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class NormalizedPartialDependenceCoefficientTests : BinaryCalculatorsTest
/// <param name="secondValue">
/// The second value.
/// </param>
[TestCase(0, 0.2, 0.094680274)]
[TestCase(1, 0, 0)]
[TestCase(2, 0, 0)]
[TestCase(3, 0, 0.1214)]
Expand All @@ -38,6 +39,7 @@ public class NormalizedPartialDependenceCoefficientTests : BinaryCalculatorsTest
[TestCase(15, 0.0357, 0.1458)]
[TestCase(16, 0.0904, 0.0478)]
[TestCase(17, 0.1401, 0.0578)]
[TestCase(19, 0.264250038, -0.042347035)]
public void NormalizedK1Test(int index, double firstValue, double secondValue)
{
CalculationTest(index, firstValue, secondValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PartialDependenceCoefficientTests : BinaryCalculatorsTests<PartialD
/// <param name="secondValue">
/// The second value.
/// </param>
[TestCase(0, 0.5, 0.236700684)]
[TestCase(1, 0, 0)]
[TestCase(2, 0, 0)]
[TestCase(3, 0, 0.5461)]
Expand All @@ -38,6 +39,7 @@ public class PartialDependenceCoefficientTests : BinaryCalculatorsTests<PartialD
[TestCase(15, 0.2143, 0.875)]
[TestCase(16, 0.4369, 0.3469)]
[TestCase(17, 0.6072, 0.3757)]
[TestCase(19, 0.759718859, -0.162330299)]
public void K1Test(int index, double firstValue, double secondValue)
{
CalculationTest(index, firstValue, secondValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class RedundancyTests : BinaryCalculatorsTests<Redundancy>
/// <param name="secondValue">
/// The second value.
/// </param>
[TestCase(0, 0.5, 0.59175171)]
[TestCase(1, 0, 0)]
[TestCase(2, 0, 0)]
[TestCase(3, 0, 0.7282)]
Expand All @@ -37,6 +38,7 @@ public class RedundancyTests : BinaryCalculatorsTests<Redundancy>
[TestCase(15, 0.8571, 0.875)]
[TestCase(16, 0.4369, 0.6938)]
[TestCase(17, 0.6072, 0.5636)]
[TestCase(19, 0.759718859, -0.216440399)]
public void ChainCalculationTest(int index, double firstValue, double secondValue)
{
CalculationTest(index, firstValue, secondValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public override double Calculate(BinaryIntervalsManager manager, Link link)

double result = intervals.Where(t => t > 0).Sum(t => Math.Log(t, 2));

return Math.Pow(2, intervals.Length == 0 ? 0 : result / intervals.Length);
return intervals.Length == 0 ? 0 : Math.Pow(2, result / intervals.Length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public override double Calculate(BinaryIntervalsManager manager, Link link)
GeometricMean geometricMeanCalculator = new();

double binaryGeometricMean = geometricMeanCalculator.Calculate(manager, link);
return 1 - (binaryGeometricMean / Math.Pow(2, avG));
return manager.PairsCount == 0 ? 0 : 1 - (binaryGeometricMean / Math.Pow(2, avG));
}
}

0 comments on commit 4b5bc84

Please sign in to comment.