Пример #1
0
 def run(self, beta_num, sim):
     RA = pickle.load(self.RA_file())
     beta = pickle.load(sim.beta_file(beta_num))
     beta = BlockDiag.from_big1darray(beta, RA.ranges())
     results = [beta.dot(RA.dot(beta))]
     print(results[-1])
     return results
Пример #2
0
 def run(self, beta_num, sim):
     RA = pickle.load(self.RA_file())
     beta = pickle.load(sim.beta_file(beta_num))
     beta = BlockDiag.from_big1darray(beta, RA.ranges())
     results = [beta.dot(RA.dot(beta))]
     print(results[-1])
     return results
Пример #3
0
    def run(self, beta_num, sim):
        if not hasattr(self, 'R'):
            print('loading matrices')
            self.init()
        self.beta = pickle.load(sim.beta_file(beta_num))

        print('computing bias')
        self.biases = self.compute_biases(sim.sample_size)
        print('biases are', self.biases)
        self.scalings = self.get_scalings()

        # compute the results
        results = []
        variances = []
        for alphahat in sim.sumstats_aligned_to_refpanel(
                beta_num, self.refpanel):
            alphahat = BlockDiag.from_big1darray(alphahat, self.R.ranges())
            results.append(self.compute_statistic(alphahat))
            variances.append(
                self.compute_variance(alphahat, results[-1], sim.sample_size))
            print(len(results), results[-1], variances[-1])

        print('empirical var of results:', np.var(results))

        return np.concatenate([np.array([results]).T,
                               np.array([variances]).T],
                              axis=1)
Пример #4
0
    def run(self, beta_num, sim):
        if not hasattr(self, 'R'):
            print('loading matrices')
            self.init()
        self.beta = pickle.load(sim.beta_file(beta_num))

        print('computing bias')
        self.biases = self.compute_biases(sim.sample_size)
        print('biases are', self.biases)
        self.scalings = self.get_scalings()

        # compute the results
        results = []
        variances = []
        for alphahat in sim.sumstats_aligned_to_refpanel(beta_num, self.refpanel):
            alphahat = BlockDiag.from_big1darray(alphahat, self.R.ranges())
            results.append(self.compute_statistic(
                alphahat))
            variances.append(self.compute_variance(
                alphahat, results[-1], sim.sample_size))
            print(len(results), results[-1], variances[-1])

        print('empirical var of results:', np.var(results))

        return np.concatenate([np.array([results]).T,
            np.array([variances]).T], axis=1)
Пример #5
0
    def run(self, beta_num, sim):
        R = pickle.load(self.R_file())
        RA = pickle.load(self.RA_file())

        # compute the results
        results = []
        for alphahat in sim.sumstats_aligned_to_refpanel(beta_num, self.refpanel):
            alphahat = BlockDiag.from_big1darray(alphahat, R.ranges())
            results.append(self.compute_statistic(alphahat, R, RA, sim.sample_size, self.refpanel.N, memoize=True))
            print(len(results), results[-1])

        return results
Пример #6
0
    def run(self, beta_num, sim):
        R = pickle.load(self.R_file())
        RA = pickle.load(self.RA_file())

        if self.params.prune_regions > 0:

            def var(L, LA, h2A, N):
                LinvLA = np.linalg.solve(L, LA)
                tr1 = np.einsum('ij,ji', LinvLA, LinvLA)
                tr2 = np.einsum('ij,ji', LA, LinvLA)
                return 2 * tr1 / float(N)**2 + 2 * tr2 * h2A / (float(N) *
                                                                float(750))

            print('computing variances')
            variances = {}
            for r in R.ranges():
                variances[r] = var(R.ranges_to_arrays[r],
                                   RA.ranges_to_arrays[r], 0.05,
                                   sim.sample_size)
            print('total variance:', sum(variances.values()))

            sortedrs = R.ranges()
            sortedrs.sort(key=lambda r: variances[r])
            worstrs = sortedrs[-self.params.prune_regions:]
            for r in worstrs:
                print('removing', r)
                del R.ranges_to_arrays[r]
                del RA.ranges_to_arrays[r]
            print('new variance:', sum([variances[r] for r in R.ranges()]))

        print(len(R.ranges()))
        print(len(RA.ranges()))
        # compute the results
        results = []
        for alphahat in sim.sumstats_aligned_to_refpanel(
                beta_num, self.refpanel):
            alphahat = BlockDiag.from_big1darray(alphahat, R.ranges())
            results.append(
                self.compute_statistic(alphahat,
                                       R,
                                       RA,
                                       sim.sample_size,
                                       self.refpanel.N,
                                       memoize=True))
            print(len(results), results[-1])

        return results
Пример #7
0
    def run(self, beta_num, sim):
        R = pickle.load(self.R_file())
        RA = pickle.load(self.RA_file())

        # compute the results
        results = []
        for alphahat in sim.sumstats_aligned_to_refpanel(
                beta_num, self.refpanel):
            alphahat = BlockDiag.from_big1darray(alphahat, R.ranges())
            results.append(
                self.compute_statistic(alphahat,
                                       R,
                                       RA,
                                       sim.sample_size,
                                       self.refpanel.N,
                                       memoize=True))
            print(len(results), results[-1])

        return results
Пример #8
0
    def run(self, beta_num, sim):
        R = pickle.load(self.R_file())
        RA = pickle.load(self.RA_file())

        if self.params.prune_regions > 0:

            def var(L, LA, h2A, N):
                LinvLA = np.linalg.solve(L, LA)
                tr1 = np.einsum("ij,ji", LinvLA, LinvLA)
                tr2 = np.einsum("ij,ji", LA, LinvLA)
                return 2 * tr1 / float(N) ** 2 + 2 * tr2 * h2A / (float(N) * float(750))

            print("computing variances")
            variances = {}
            for r in R.ranges():
                variances[r] = var(R.ranges_to_arrays[r], RA.ranges_to_arrays[r], 0.05, sim.sample_size)
            print("total variance:", sum(variances.values()))

            sortedrs = R.ranges()
            sortedrs.sort(key=lambda r: variances[r])
            worstrs = sortedrs[-self.params.prune_regions :]
            for r in worstrs:
                print("removing", r)
                del R.ranges_to_arrays[r]
                del RA.ranges_to_arrays[r]
            print("new variance:", sum([variances[r] for r in R.ranges()]))

        print(len(R.ranges()))
        print(len(RA.ranges()))
        # compute the results
        results = []
        for alphahat in sim.sumstats_aligned_to_refpanel(beta_num, self.refpanel):
            alphahat = BlockDiag.from_big1darray(alphahat, R.ranges())
            results.append(self.compute_statistic(alphahat, R, RA, sim.sample_size, self.refpanel.N, memoize=True))
            print(len(results), results[-1])

        return results