Пример #1
0
 def compute_Sbar(b1, b2, b3, b4, b5, b6):
     model = MosaicityParameterisation((b1, b2, b3, b4, b5, b6))
     sigma = model.sigma()
     sigmap = R * sigma * R.transpose()
     sigma11 = matrix.sqr((sigmap[0], sigmap[1], sigmap[3], sigmap[4]))
     sigma12 = matrix.col((sigmap[2], sigmap[5]))
     sigma21 = matrix.col((sigmap[6], sigmap[7])).transpose()
     sigma22 = sigmap[8]
     return sigma11 - sigma12 * (1 / sigma22) * sigma21
Пример #2
0
    def callback(self, x):
        """
        Handle and update in parameter values

        """
        parameterisation = MosaicityParameterisation(x)
        sigma = parameterisation.sigma()
        lnL = self.log_likelihood(x)
        format_string = (
            "( %.3g, %.3g, %.3g, %.3g, %.3g, %.3g, %.3g, %.3g, %.3g ): L = %f")
        print(format_string % (tuple(sigma) + (lnL, )))
        self.history.append(x)
Пример #3
0
    def generate_predictions(self, experiment, reflections, parameters):

        # Create the mosaicity model
        parameterisation = MosaicityParameterisation(parameters)

        # The crystal A and beam s0
        A = matrix.sqr(experiment.crystal.get_A())
        s0 = matrix.col(experiment.beam.get_s0())
        s0_length = s0.length()

        # Compute all the vectors
        s1_cal = flex.vec3_double()
        s2_cal = flex.vec3_double()
        for i in range(len(reflections)):

            # Compute the reciprocal lattice vector
            h = matrix.col(reflections[i]["miller_index"])
            r = A * h
            s2 = s0 + r

            # Rotate the covariance matrix
            R = compute_change_of_basis_operation(s0, s2)
            S = R * parameterisation.sigma() * R.transpose()
            mu = R * s2
            assert abs(1 - mu.normalize().dot(matrix.col((0, 0, 1)))) < 1e-7

            # Partition the mean vector
            mu1 = matrix.col((mu[0], mu[1]))
            mu2 = mu[2]

            # Partition the covariance matrix
            S11 = matrix.sqr((S[0], S[1], S[3], S[4]))
            S12 = matrix.col((S[2], S[5]))
            S21 = matrix.col((S[6], S[7])).transpose()
            S22 = S[8]

            # Compute the conditional mean
            mubar = mu1 + S12 * (1 / S22) * (s0_length - mu2)

            # Compute the vector and rotate
            v = matrix.col(
                (mubar[0], mubar[1], s0_length)).normalize() * s0_length
            s1 = R.transpose() * v

            # Append the 2 vectors
            s1_cal.append(s1)
            s2_cal.append(s2)

        # Return the predicted vectors
        return s1_cal, s2_cal
Пример #4
0
    def compute_L(b1, b2, b3, b4, b5, b6):
        model = MosaicityParameterisation((b1, b2, b3, b4, b5, b6))
        sigma = model.sigma()
        sigmap = R * sigma * R.transpose()
        sigma11 = matrix.sqr((sigmap[0], sigmap[1], sigmap[3], sigmap[4]))
        sigma12 = matrix.col((sigmap[2], sigmap[5]))
        sigma21 = matrix.col((sigmap[6], sigmap[7])).transpose()
        sigma22 = sigmap[8]

        sigma_bar = sigma11 - sigma12 * (1 / sigma22) * sigma21

        d = r - mu2
        A = log(sigma22)
        B = (1 / sigma22) * d**2
        C = log(sigma_bar.determinant()) * ctot
        D = (sigma_bar.inverse() * Sobs).trace()
        return -0.5 * (A + B + C + D)
Пример #5
0
 def compute_sigma22(b1, b2, b3, b4, b5, b6):
     model = MosaicityParameterisation((b1, b2, b3, b4, b5, b6))
     sigma = model.sigma()
     sigmap = R * sigma * R.transpose()
     sigma22 = sigmap[8]
     return sigma22