예제 #1
0
def test_score_correlation_coefficient():
    cc = 1
    expected_cc = 1
    sigma_cc = 0.1
    score_cc = ScoreCorrelationCoefficient(cc, sigma_cc, expected_cc)
    assert score_cc.p_s_given_cc == pytest.approx(0.9492499653267421)

    cc = 0.5
    score_cc = ScoreCorrelationCoefficient(cc, sigma_cc, expected_cc)
    assert score_cc.p_s_given_cc == pytest.approx(0.19697339347266518)

    cc = 0.5
    expected_cc = 0.6
    sigma_cc = 0.2
    score_cc = ScoreCorrelationCoefficient(cc, sigma_cc, expected_cc)
    assert score_cc.p_s_given_cc == pytest.approx(0.6178439917879021)

    if 0:
        import numpy as np
        from matplotlib import pyplot as plt

        x = np.linspace(-1, 1)
        values = [(0.1, 1), (0.1, 0.8), (0.2, 1), (0.2, 0.8)]
        fig, axes = plt.subplots(nrows=2, ncols=2)
        for ax, (sigma_cc, expected_cc) in zip(axes.flatten(), values):
            ax.set_title("E(CC) = %.1f, sigma(cc) = %.1f" %
                         (expected_cc, sigma_cc))
            p_cc_given_s = []
            p_cc_given_not_s = []
            p_s_given_cc = []
            for _ in x:
                score_cc = ScoreCorrelationCoefficient(_, sigma_cc,
                                                       expected_cc)
                p_cc_given_s.append(score_cc.p_cc_given_s)
                p_cc_given_not_s.append(score_cc.p_cc_given_not_s)
                p_s_given_cc.append(score_cc.p_s_given_cc)
            ax.plot(x, p_cc_given_s, label="p(CC;S)")
            ax.plot(x, p_cc_given_not_s, label="p(CC;!S)")
            ax.plot(x, p_s_given_cc, label="p(S;CC)")
        ylim = max(ax.get_ylim()[1] for ax in axes.flatten())
        for ax in axes.flatten():
            ax.legend()
            ax.set_ylim(ax.get_ylim()[0], ylim)
        plt.show()
예제 #2
0
    def __init__(self, cc, sigma_cc, cc_true):
        """Initialise a ScoreSymmetryElement object.

        Args:
          cc (float): the correlation coefficient for this symmetry element
          sigma_cc (float): the estimated error in the correlation coefficient
          cc_true (float): the expected value of CC if the symmetry element is present,
            E(CC; S)
        """

        self.cc = cc
        self.sigma_cc = sigma_cc
        self.z_cc = self.cc / self.sigma_cc
        score_cc = ScoreCorrelationCoefficient(self.cc, self.sigma_cc, cc_true)
        self.p_cc_given_s = score_cc.p_cc_given_s
        self.p_cc_given_not_s = score_cc.p_cc_given_not_s
        self.likelihood = score_cc.p_s_given_cc