示例#1
0
文件: cmt3d.py 项目: rmodrak/pycmt3d
    def invert_bootstrap(self):
        """
        It is used to evaluate the mean, standard deviation, and variance
        of new parameters

        :return:
        """
        A_bootstrap = []
        b_bootstrap = []
        n_subset = int(const.BOOTSTRAP_SUBSET_RATIO * self.nwins)
        for i in range(self.config.bootstrap_repeat):
            random_array = util.gen_random_array(
                self.nwins, sample_number=n_subset)
            A = util.sum_matrix(random_array * self.weight_array, self.A1_all)
            b = util.sum_matrix(random_array * self.weight_array, self.b1_all)
            A_bootstrap.append(A)
            b_bootstrap.append(b)

        # inversion of each subset
        new_par_array = np.zeros((self.config.bootstrap_repeat, const.NPARMAX))
        for i in range(self.config.bootstrap_repeat):
            new_par = self.invert_solver(A_bootstrap[i], b_bootstrap[i])
            new_par_array[i, :] = new_par

        # statistical analysis
        self.par_mean = np.mean(new_par_array, axis=0)
        self.par_std = np.std(new_par_array, axis=0)
        self.par_var = np.var(new_par_array, axis=0)
        for _ii in range(self.par_mean.shape[0]):
            if self.par_mean[_ii] != 0:
                # in case of 0 value
                self.std_over_mean[_ii] = \
                        np.abs(self.par_std[_ii] / self.par_mean[_ii])
            else:
                self.std_over_mean[_ii] = 0.
示例#2
0
文件: cmt3d.py 项目: rmodrak/pycmt3d
    def invert_cmt(self):
        """
        ensemble all measurements together to form Matrix A and vector
        b to solve the A * (dm) = b
        A is the Hessian Matrix and b is the misfit

        :return:
        """
        logger.info("*"*15)
        logger.info("CMT Inversion")
        logger.info("*"*15)
        # ensemble A and b
        A = util.sum_matrix(self.weight_array, self.A1_all)
        b = util.sum_matrix(self.weight_array, self.b1_all)
        logger.info("Inversion Matrix A is as follows:")
        logger.info("\n%s" % ('\n'.join(map(self._float_array_to_str, A))))
        logger.info("Condition number of A: %10.2f" % (np.linalg.cond(A)))
        logger.info("RHS vector b is as follows:")
        logger.info("[%s]" % (self._float_array_to_str(b)))

        # source inversion
        self.new_cmt_par = self.invert_solver(A, b, print_mode=True)
        self.convert_new_cmt_par()