def test_histograms_to_pandas_dataframe(self): data = [1.0, 1.1, 1.2, 1.3, 2.0, 1.4, 2.3, 2.5, 3.1, 3.5] # This length needs to be larger than 10 to see a difference between # str ordering and int ordering hists = [Histogram(n_bins=5) for i in range(11)] for hist in hists: _ = hist.histogram(data) df = histograms_to_pandas_dataframe(hists) # sort like is done in analysis df = df.sort_index(axis=1) # This breaks if the sorting is done based on strings as that will # return [0, 1, 10 ...] instead of [0, 1, 2, ...] for i, c in enumerate(df.columns): assert str(c) == str(i)
def total_crossing_probability(self, steps=None, method="wham", force=False): """Return the total crossing probability using `method` Parameters ---------- steps : iterable of :class:`.MCStep` cycles to be analyzed method : "wham" (later: or "mbar" or "tram") approach to use to combine the histograms force : bool (False) if true, cached results are overwritten """ if method == "wham": run_ensembles = False for ens in self.ensembles: try: hist = self.histograms['max_lambda'][ens] except KeyError: run_ensembles = True if run_ensembles or force: if steps is None: raise RuntimeError( "Unable to build histograms without steps source") self.all_statistics(steps, force=True) df = histograms_to_pandas_dataframe( self.histograms['max_lambda'].values(), fcn="reverse_cumulative").sort_index(axis=1) # if lambdas not set, returns None and WHAM uses fallback lambdas = self.interfaces.lambdas wham = WHAM(interfaces=lambdas) # wham.load_from_dataframe(df) # wham.clean_leading_ones() tcp = wham.wham_bam_histogram(df).to_dict() elif method == "mbar": pass else: raise ValueError( "Only supported methods are 'wham' and 'mbar'. " + "Whereas 'mbar' is not yet implemented!") self.tcp = LookupFunction(tcp.keys(), tcp.values()) return self.tcp
def total_crossing_probability(self, steps=None, method="wham", force=False): """Return the total crossing probability using `method` Parameters ---------- steps : iterable of :class:`.MCStep` cycles to be analyzed method : "wham" (later: or "mbar" or "tram") approach to use to combine the histograms force : bool (False) if true, cached results are overwritten """ if method == "wham": run_ensembles = False for ens in self.ensembles: try: hist = self.histograms['max_lambda'][ens] except KeyError: run_ensembles = True if run_ensembles or force: if steps is None: raise RuntimeError("Unable to build histograms without steps source") self.all_statistics(steps, force=True) df = histograms_to_pandas_dataframe( self.histograms['max_lambda'].values(), fcn="reverse_cumulative" ).sort_index(axis=1) # if lambdas not set, returns None and WHAM uses fallback lambdas = self.interfaces.lambdas wham = WHAM(interfaces=lambdas) # wham.load_from_dataframe(df) # wham.clean_leading_ones() tcp = wham.wham_bam_histogram(df).to_dict() elif method == "mbar": pass else: raise ValueError("Only supported methods are 'wham' and 'mbar'. " + "Whereas 'mbar' is not yet implemented!") self.tcp = LookupFunction(tcp.keys(), tcp.values()) return self.tcp