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 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)