easyvvuq.sampling.dataframe_sampler
1""" 2""" 3 4from .base import BaseSamplingElement 5import csv 6 7__license__ = "LGPL" 8 9 10class DataFrameSampler(BaseSamplingElement, sampler_name="csv_sampler"): 11 12 def __init__(self, df, counter=0): 13 """Takes a DataFrame and outputs it row by row. 14 """ 15 self.data = df.to_dict(orient='records') 16 self.counter = counter 17 18 def is_finite(self): 19 return True 20 21 def n_samples(self): 22 """Returns the number of samples in this sampler. 23 Returns 24 ------- 25 if the user specifies maximum number of samples than return that, otherwise - error 26 """ 27 return len(self.data) 28 29 def __next__(self): 30 try: 31 return self.data[self.counter] 32 finally: 33 if self.counter < self.n_samples(): 34 self.counter += 1 35 else: 36 raise StopIteration
11class DataFrameSampler(BaseSamplingElement, sampler_name="csv_sampler"): 12 13 def __init__(self, df, counter=0): 14 """Takes a DataFrame and outputs it row by row. 15 """ 16 self.data = df.to_dict(orient='records') 17 self.counter = counter 18 19 def is_finite(self): 20 return True 21 22 def n_samples(self): 23 """Returns the number of samples in this sampler. 24 Returns 25 ------- 26 if the user specifies maximum number of samples than return that, otherwise - error 27 """ 28 return len(self.data) 29 30 def __next__(self): 31 try: 32 return self.data[self.counter] 33 finally: 34 if self.counter < self.n_samples(): 35 self.counter += 1 36 else: 37 raise StopIteration
Baseclass for all EasyVVUQ sampling elements.
Attributes
- sampler_name (str): Name of the particular sampler.
DataFrameSampler(df, counter=0)
13 def __init__(self, df, counter=0): 14 """Takes a DataFrame and outputs it row by row. 15 """ 16 self.data = df.to_dict(orient='records') 17 self.counter = counter
Takes a DataFrame and outputs it row by row.
def
n_samples(self):
22 def n_samples(self): 23 """Returns the number of samples in this sampler. 24 Returns 25 ------- 26 if the user specifies maximum number of samples than return that, otherwise - error 27 """ 28 return len(self.data)
Returns the number of samples in this sampler.
Returns
- if the user specifies maximum number of samples than return that, otherwise - error