Esempio n. 1
0
    def get_all_results_by_param(self, mlmc_est, param_name):
        """
        Get all result values by given param name, e.g. param_name = "temp" - return all temperatures...
        :param mlmc_est: Estimate instance
        :param param_name: Sample result param name
        :return: moments means, moments vars -> two numpy arrays
        """
        n_moments = 3
        mlmc_est.mlmc.clean_select()
        mlmc_est.mlmc.select_values({param_name: (0, ">=")})
        domain = Estimate.estimate_domain(mlmc_est.mlmc)
        moments_fn = Monomial(n_moments, domain, False, ref_domain=domain)
        means, vars = mlmc_est.estimate_moments(moments_fn)

        return means, vars
Esempio n. 2
0
    def process(self):
        """
        Use collected data
        :return: None
        """
        assert os.path.isdir(self.work_dir)
        mlmc_est_list = []

        for nl in [1]:  # high resolution fields
            mlmc = self.setup_config(nl, clean=False)
            # Use wrapper object for working with collected data
            mlmc_est = Estimate(mlmc)
            mlmc_est_list.append(mlmc_est)

        #self.plot_density(mlmc)

        self.plot_temp_power(mlmc_est)
Esempio n. 3
0
    def process(self):
        """
        Use collected data
        :return: None
        """
        assert os.path.isdir(self.work_dir)
        mlmc_est_list = []
        # for nl in [ 1,3,5,7,9]:

        import time
        for nl in [5]:  # high resolution fields
            start = time.time()
            mlmc = self.setup_config(nl, clean=False)
            print("celkový čas ", time.time() - start)
            # Use wrapper object for working with collected data
            mlmc_est = Estimate(mlmc)
            mlmc_est_list.append(mlmc_est)
Esempio n. 4
0
    def plot_param(self, mlmc_est, ax, X, col, param_name, legend):
        """
        Get all result values by given param name, e.g. param_name = "temp" - return all temperatures...
        :param mlmc_est: Estimate instance
        :param param_name: Sample result param name
        :return: moments means, moments vars -> two numpy arrays
        """

        n_moments = 3
        mlmc_est.mlmc.clean_select()
        mlmc_est.mlmc.select_values(None, selected_param=param_name)
        print("plot param:", param_name)
        samples = mlmc_est.mlmc.levels[0].sample_values[:,0,:]
        print("    shape: ", samples.shape)
        #print(np.any(np.isnan(samples), axis=1))
        domain = Estimate.estimate_domain(mlmc_est.mlmc)
        domain_diff = domain[1] - domain[0]
        print("    domain: ", domain)
        moments_fn = Monomial(n_moments, domain, False, ref_domain=domain)
        N = mlmc_est.mlmc.n_samples[0]
        mom_means, mom_vars = mlmc_est.estimate_moments(moments_fn)

        mom_means, mom_vars = mom_means[1:, :], mom_vars[1:, :] # omit time=0
        q_mean = mom_means[:, 1]
        q_mean_err = np.sqrt(mom_vars[:, 1])
        q_var = (mom_means[:, 2] - q_mean ** 2) * N / (N-1)
        # print("    means: ", mom_means[-1, :])
        # print("    vars: ", mom_vars[-1, :])
        # print("    alt var: ", mom_vars[-1, 1]*N)
        # print("    qvar : ", q_var[-1])
        # print("    qvar_err : ", q_var[-1])
        #q_var = q_mean_err * N
        q_std = np.sqrt(q_var)
        q_std_err = np.sqrt(q_var + np.sqrt(mom_vars[:, 2] * N / (N-1)))

        ax.fill_between(X, q_mean - q_mean_err, q_mean + q_mean_err,
                         color=col, alpha=1, label=legend + " - mean")
        ax.fill_between(X, q_mean - q_std, q_mean + q_std,
                         color=col, alpha=0.2, label=legend + " - std")
        ax.fill_between(X, q_mean - q_std_err, q_mean - q_std,
                         color=col, alpha=0.4, label = None)
        ax.fill_between(X, q_mean + q_std, q_mean + q_std_err,
                         color=col, alpha=0.4, label = None)
Esempio n. 5
0
    def process(self):
        """
        Use collected data
        :return: None
        """
        assert os.path.isdir(self.work_dir)
        mlmc_est_list = []

        for nl in [1]:  # high resolution fields
            mlmc = self.setup_config(nl, clean=False)
            # Use wrapper object for working with collected data
            mlmc_est = Estimate(mlmc)
            mlmc_est_list.append(mlmc_est)

        # self.result_text(mlmc)
        # self.plot_density(mlmc)

        mlmc_est.mlmc.clean_select()

        th_02_model_params = ["power", "temp", "temp_min", "temp_max"]
        th_03_model_params = [n + "_ref" for n in th_02_model_params]
        print("02_th - stimulated EGS")
        good_mask = self.select_samples_with_good_values(mlmc_est, th_02_model_params)
        print("03_th - reference EGS")
        good_mask = self.select_samples_with_good_values(mlmc_est, th_03_model_params, good_mask=good_mask)
        #good_mask[np.random.choice(len(good_mask), int(len(good_mask)*0.93))] = False
        #print("N Random choice: ", sum(good_mask))
        mlmc_est.mlmc.subsample_by_indices(good_mask)

        # self.plot_temp_power(mlmc_est, th_02_model_params)
        # self.plot_temp_power(mlmc_est, th_03_model_params)

        #self.plot_histogram_const(mlmc_est, 'fr_cs_med', "fr_cs_median", "Median of $\delta_f$ [mm]", bins=30, scale=1000)
        #self.plot_histogram_const(mlmc_est, 'fr_cond_med', "fr_cond_median", "Median of $k_f$ [m.s$^{-1}$]", bins=30, scale=1)
        #self.plot_histogram_flux(mlmc_est, 'bc_flux', "total_flux_histogram", bins=30)

        self.plot_histogram(mlmc_est, 'temp', "temp_histogram", "Temperature [$^\circ$C]", bins=30)
        self.plot_histogram(mlmc_est, 'power', "power_histogram", "Power [MW]", bins=30)

        self.plot_temp_ref_comparison(mlmc_est)
        self.plot_power_ref_comparison(mlmc_est)

        # n_samples = int(mlmc_est.mlmc.n_samples)
        # print("N samples: ", n_samples)
        # temp_v_ele = np.zeros((2 * n_samples, 2 * n_samples), dtype=int)
        # print("good temperature interval: <{},{}>".format(MIN_T, MAX_T))
        # bad_temp_flag = np.zeros((len(n_bad_els),))
        # bad_ele_flag = np.zeros((len(n_bad_els),))
        # for i in range(0, n_samples):
        #     bad_temp_flag[i] = min(temp_min[i][0]) < MIN_T or max(temp_max[i][0]) > MAX_T
        #     bad_ele_flag[i] = n_bad_els[i][0][0] > 0
        #     ty = i if bad_temp_flag[i] else n_samples + i
        #     tx = i if bad_ele_flag[i] else n_samples + i
        #     temp_v_ele[ty, tx] = 1
        #     [np.sum(temp_v_ele[:n_samples, :n_samples]),
        #      np.sum(temp_v_ele[:n_samples, n_samples:2 * n_samples])],
        #     [np.sum(temp_v_ele[n_samples:2 * n_samples, :n_samples]),
        #      np.sum(temp_v_ele[n_samples:2 * n_samples, n_samples:2 * n_samples])]]
        #
        # print("temp[BAD, GOOD]' x mesh[BAD, GOOD]]\n{}\n{}".format(temp_v_ele_sum[0], temp_v_ele_sum[1]))
        #
        # # print(n_bad_els.shape)
        # n_bad_elements = np.zeros((len(n_bad_els),))
        # for i in range(len(n_bad_els)):
        #     n_bad_elements[i] = n_bad_els[i][0][0]
        #
        # print("min n_bad_element = ", min(n_bad_elements))
        # print("max n_bad_element = ", max(n_bad_elements))
        #
        # # compute EX and varX
        # bad_temp_ele_avg = 0    # EX of bad elements for bad temperature
        # good_temp_ele_avg = 0   # EX of bad elements for good temperature
        # for i in range(len(n_bad_els)):
        #     if bad_temp_flag[i]:
        #         bad_temp_ele_avg += n_bad_elements[i]
        #     else:
        #         good_temp_ele_avg += n_bad_elements[i]
        # if temp_v_ele_sum[0][0] != 0:
        #     bad_temp_ele_avg /= temp_v_ele_sum[0][0]
        # if temp_v_ele_sum[1][0] != 0:
        #     good_temp_ele_avg /= temp_v_ele_sum[1][0]
        # print("bad_temp EX: ", bad_temp_ele_avg)
        # print("good_temp EX: ", good_temp_ele_avg)
        #
        # bad_temp_ele_var = 0    # varX of bad elements for bad temperature
        # good_temp_ele_var = 0   # varX of bad elements for good temperature
        # for i in range(len(n_bad_els)):
        #     if bad_temp_flag[i]:
        #         bad_temp_ele_var += (n_bad_elements[i]-bad_temp_ele_avg)**2
        #     else:
        #         good_temp_ele_var += (n_bad_elements[i]-good_temp_ele_avg)**2
        # if temp_v_ele_sum[0][0] != 0:
        #     bad_temp_ele_var /= temp_v_ele_sum[0][0]
        # if temp_v_ele_sum[1][0] != 0:
        #     good_temp_ele_var /= temp_v_ele_sum[1][0]
        # print("bad_temp varX: ", bad_temp_ele_var)
        # print("good_temp varX: ", good_temp_ele_var)
        # print("bad_temp s: ", np.sqrt(bad_temp_ele_var))
        # print("good_temp s: ", np.sqrt(good_temp_ele_var))
        #
        # # print("temp_v_ele:\n", temp_v_ele)
        # temp_v_ele_sum = [
        #     [np.sum(temp_v_ele[:n_samples, :n_samples]),
        #      np.sum(temp_v_ele[:n_samples, n_samples:2 * n_samples])],
        #     [np.sum(temp_v_ele[n_samples:2 * n_samples, :n_samples]),
        #      np.sum(temp_v_ele[n_samples:2 * n_samples, n_samples:2 * n_samples])]]
        #
        # print("temp[BAD, GOOD]' x mesh[BAD, GOOD]]\n{}\n{}".format(temp_v_ele_sum[0], temp_v_ele_sum[1]))
        #
        # # print(n_bad_els.shape)
        # n_bad_elements = np.zeros((len(n_bad_els),))
        # for i in range(len(n_bad_els)):
        #     n_bad_elements[i] = n_bad_els[i][0][0]
        #
        # print("min n_bad_element = ", min(n_bad_elements))
        # print("max n_bad_element = ", max(n_bad_elements))
        #
        # # compute EX and varX
        # bad_temp_ele_avg = 0    # EX of bad elements for bad temperature
        # good_temp_ele_avg = 0   # EX of bad elements for good temperature
        # for i in range(len(n_bad_els)):
        #     if bad_temp_flag[i]:
        #         bad_temp_ele_avg += n_bad_elements[i]
        #     else:
        #         good_temp_ele_avg += n_bad_elements[i]
        # bad_temp_ele_avg /= temp_v_ele_sum[0][0]
        # good_temp_ele_avg /= temp_v_ele_sum[1][0]
        # print("bad_temp EX: ", bad_temp_ele_avg)
        # print("good_temp EX: ", good_temp_ele_avg)
        #
        # bad_temp_ele_var = 0    # varX of bad elements for bad temperature
        # good_temp_ele_var = 0   # varX of bad elements for good temperature
        # for i in range(len(n_bad_els)):
        #     if bad_temp_flag[i]:
        #         bad_temp_ele_var += (n_bad_elements[i]-bad_temp_ele_avg)**2
        #     else:
        #         good_temp_ele_var += (n_bad_elements[i]-good_temp_ele_avg)**2
        # bad_temp_ele_var /= temp_v_ele_sum[0][0]
        # good_temp_ele_var /= temp_v_ele_sum[1][0]
        # print("bad_temp varX: ", bad_temp_ele_var)
        # print("good_temp varX: ", good_temp_ele_var)
        # print("bad_temp s: ", np.sqrt(bad_temp_ele_var))
        # print("good_temp s: ", np.sqrt(good_temp_ele_var))
        #
        # # print("n_bad_els:\n", n_bad_els)
        #
        # # print("TEMP_MIN: ", temp_min)
        # # print("TEMP_MAX: ", temp_max)
        # #
        # # print("TEMP_MIN: ", min(temp_min[0][0]))
        # # print("TEMP_MAX: ", max(temp_max[1][0]))

        print("PROCESS FINISHED :)")