コード例 #1
0
    def __init__(self, csv_file_name, wtp_range,
                 csv_file_name_proj_thresholds='ProjectedOptimalThreshold.csv'):

        self.cols = io.read_csv_cols(
            file_name=csv_file_name, n_cols=3, if_ignore_first_row=True, if_convert_float=True)

        self.wtps = self.cols[0]
        self.OnTs = self.cols[1]
        self.OffTs = self.cols[2]
        self.RegToOn = Reg.ExpRegression(x=self.wtps,
                                         y=self.OnTs,
                                         if_c0_zero=True)
        print(self.RegToOn.get_coeffs())
        self.RegToOff = Reg.ExpRegression(x=self.wtps,
                                          y=self.OffTs,
                                          if_c0_zero=True)
        print(self.RegToOff.get_coeffs())

        wtps = np.linspace(wtp_range[0], wtp_range[1], 13)
        to_on_ts = self.RegToOn.get_predicted_y(wtps)
        to_off_ts = self.RegToOff.get_predicted_y(wtps)
        rows = []
        for i in range(len(wtps)):
            row = [wtps[i], to_on_ts[i], to_off_ts[i]]
            rows.append(row)
        io.write_csv(rows=rows, file_name=csv_file_name_proj_thresholds)
コード例 #2
0
    def __init__(self, csv_file_name):
        """ extracts seeds, mortality probabilities and the associated likelihood from
        the csv file where the calibration results are stored
        :param csv_file_name: name of the csv file where the calibrated results are stored
        :param drug_effectiveness_ratio: effectiveness of the drug
        """

        # read the columns of the csv files containing the calibration results
        cols = InOutSupport.read_csv_cols(file_name=csv_file_name,
                                          n_cols=3,
                                          if_ignore_first_row=True,
                                          if_convert_float=True)

        # store likelihood weights, cohort IDs and sampled mortality probabilities
        self.cohortIDs = cols[CalibrationColIndex.ID.value].astype(int)
        self.weights = cols[CalibrationColIndex.W.value]
        self.mortalityProbs = cols[CalibrationColIndex.MORT_PROB.value]
        self.multiCohorts = None  # multi-cohort
コード例 #3
0
import SimPy.InOutFunctions as IO
import SimPy.Plots.Histogram as Hist
import SimPy.Plots.ProbDist as Plot
import SimPy.RandomVariateGenerators as RVGs
import SimPy.Statistics as Stat

# read weekly number of drinks
cols = IO.read_csv_cols(file_name='dataNumOfDrinks.csv',
                        n_cols=1,
                        if_ignore_first_row=True,
                        if_convert_float=True)

# make a histogram
Hist.plot_histogram(data=cols[0], title='Weekly Number of Drinks', bin_width=1)

# mean and standard deviation
stat = Stat.SummaryStat(name='Weekly number of drinks', data=cols[0])
print('Mean = ', stat.get_mean())
print('StDev = ', stat.get_stdev())

# fit a Poisson distribution
fit_results = RVGs.Poisson.fit_ml(data=cols[0])
print('Fitting a Poisson distribution:', fit_results)

# plot the fitted Poisson distribution
Plot.plot_poisson_fit(data=cols[0],
                      fit_results=fit_results,
                      x_label='Weekly number of drinks',
                      x_range=(0, 40),
                      bin_width=1)
コード例 #4
0
from SimPy import InOutFunctions as InOutSupport

# test reading by rows
rows = InOutSupport.read_csv_rows('myCSV',
                                  if_del_first_row=True,
                                  if_convert_float=True)
print('Testing reading by rows:')
for row in rows:
    print(sum(row))

# test reading by columns
cols = InOutSupport.read_csv_cols('myCSV',
                                  n_cols=3,
                                  if_ignore_first_row=True,
                                  if_convert_float=True)
print('Testing reading by columns:')
for j in range(0, 3):
    print(sum(cols[j]))

# rest reading by columns into a dictionary
dict_cols = InOutSupport.read_csv_cols_to_dictionary('myCSV',
                                                     if_convert_float=True)
print('Testing reading by columns into a dictionary:')
print(dict_cols)
コード例 #5
0
from SimPy import InOutFunctions as io

# ---------------
# first run the TestCSVWritter.py to produce the csv file
# ---------------

# test reading by rows
rows = io.read_csv_rows('CSVFolder/myCSV.csv',
                        if_ignore_first_row=True,
                        if_convert_float=True)
print('Testing reading by rows:')
for row in rows:
    print(sum(row[1:]))

# test reading by columns
cols = io.read_csv_cols('CSVFolder/myCSV.csv',
                        n_cols=4,
                        if_ignore_first_row=True,
                        if_convert_float=True)
print('Testing reading by columns:')
for j in range(1, 4):
    print(sum(cols[j]))

# rest reading by columns into a dictionary
dict_cols = io.read_csv_cols_to_dictionary('CSVFolder/myCSV.csv',
                                           if_convert_float=True)

print('Testing reading by columns into a dictionary:')
print(dict_cols)
コード例 #6
0
import SimPy.Plots.EffectiveSampleSize as P
import SimPy.InOutFunctions as IO

# read likelihoods
data = IO.read_csv_cols(file_name='csv_files/TBLikelihoods.csv',
                        n_cols=1,
                        if_ignore_first_row=True,
                        if_convert_float=True)

P.plot_eff_sample_size(likelihood_weights=data[0],
                       if_randomize=True,
                       y_range=(0, 10),
                       file_name='results/EffSampleSize.png')