Esempio n. 1
0
 def eindexFail(self, ):
     x = np.arange(0, 10, 0.5)
     y1 = curve().logistic(x, a=1, b=1, c=1, d=5)
     y2 = curve().logistic(x, a=1, b=1, c=2.5, d=5)
     print(len(x))
     print(len(y1))
     print(len(y2))
     dd1 = newtonDividedDifference().getDivDiffDiag(x, np.array(y1))
     dd2 = newtonDividedDifference().getDivDiffDiag(x, np.array(y2))
     print(dd1[-1], dd2[-1])
     y_line = 0.1 * x
     labels = ['logistic curve 1', 'logistic curve 2', 'y=0.1*x']
     plt.plot(x,
              y1,
              marker='',
              color='royalblue',
              label=labels[0],
              linewidth=3,
              alpha=0.5)
     plt.plot(x,
              y2,
              marker='',
              color='r',
              label=labels[1],
              linewidth=3,
              alpha=0.5)
     plt.plot(x,
              y_line,
              marker='',
              color='grey',
              label=labels[2],
              linewidth=2,
              alpha=0.4)
     plt.annotate("Three curves meet \nat point (0.5,0.5).",
                  fontsize=9,
                  xy=(0.52, 0.48),
                  xycoords='figure fraction',
                  xytext=(+0.52, +0.36),
                  bbox=dict(boxstyle="round4,pad=.5", fc="0.8"),
                  arrowprops=dict(
                      arrowstyle="fancy",
                      color="0.5",
                      shrinkB=5,
                      connectionstyle="arc3, rad=0.3",
                  ))
     plt.legend(fontsize=10)
     plt.xlabel('Time')
     plt.ylabel('Biomass')
     axe = plt.gcf()
     axe.set_size_inches(w=8, h=5.5)
     plt.show()
Esempio n. 2
0
 def LymphoidCurve(self, ):
     x = np.arange(0, 10.2, 0.5)
     y = np.exp(x) / (1.5 + 1 * np.exp(1.15 * (x - 5)))
     dd = newtonDividedDifference().getDivDiffDiag(x, np.array(y))
     print(dd[-1])
     fig, ax = plt.subplots(nrows=1, ncols=1, num=1)
     plt.plot(x,
              y,
              marker='',
              color='grey',
              label='Lymphoid-typed Tissue',
              linewidth=3,
              alpha=0.9)
     plt.hlines(y=68,
                xmin=0,
                xmax=10,
                colors="purple",
                linestyles="dashed",
                linewidth=1.5,
                alpha=0.6)
     plt.legend(fontsize=10)
     gca = plt.gca()
     gca.axes.get_xaxis().set_ticks([])
     gca.axes.get_yaxis().set_ticks([])
     ax.spines['right'].set_visible(False)
     ax.spines['top'].set_visible(False)
     plt.xlabel('Time')
     plt.ylabel('Growth')
     axe = plt.gcf()
     axe.set_size_inches(w=8, h=6.5)
     plt.show()
Esempio n. 3
0
    def mouseCaseStudy(self, ):
        """
        Data pooled from SM/J and 10 LG/J 535 F2 animals by James M. Cheverud.

        .. @Cite:
           ------
           James M. Cheverud. Quantitative Trait Loci for Murine Growth. Genetics, 1996.

        :return:
        """
        weeks = rob.IntVector(np.arange(10) + 1)
        weights = rob.FloatVector([
            4.83, 8.26, 12.56, 19.21, 24.80, 27.37, 29.72, 31.44, 33.71, 35.51
        ])
        dd = newtonDividedDifference().getDivDiffCrafted(
            np.array(weeks), np.array(weights))
        print('Divided difference: {}'.format(dd[-1, -1]))
        df = rob.DataFrame({'weeks': weeks, 'weights': weights})
        rob.globalenv["y"] = df.rx2('weights')
        rob.globalenv["week"] = df.rx2('weeks')
        rob.globalenv["weight"] = rob.r('log((35-y)/y)')
        lreg = stats.lm("weight ~ week")
        a1 = lreg.rx2('coefficients')[0]
        a2 = lreg.rx2('coefficients')[1]
        # print(a1, a2)
        t = np.array(rob.r('seq(1, length(week), 0.01)'))
        z = 35 / (1 + np.exp(a1 + t * a2))
        _, ax = plt.subplots(nrows=1, ncols=1, num=1)
        plt.plot(t, z, color='purple', linewidth=3, alpha=0.65)
        plt.plot(np.array(weeks),
                 np.array(weights),
                 color='grey',
                 linestyle='none',
                 marker='o',
                 alpha=0.7)
        plt.xlabel("Week", fontsize=12)
        plt.ylabel("Weight", fontsize=12)
        plt.annotate(
            "logistic function: " +
            r'$ weight = \frac{35}{1+exp({2.35-0.602*week})}$',
            fontsize=12,
            xy=(0.47, 0.48),
            xycoords='figure fraction',
        )
        plt.xticks(np.arange(10) + 1)
        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)
        axe = plt.gcf()
        axe.set_size_inches(w=9.5, h=6.5)
        plt.show()
        print(t)
Esempio n. 4
0
 def poplarBCCase(self, file_path, file_name):
     to_do = np.transpose(
         pd.read_table(file_path + file_name + '.csv', sep=',',
                       header=None))
     # print(to_do)
     x = np.arange(11) + 1
     # print(x)
     div_diff = []
     for i in range(1, to_do.shape[1]):
         dd = newtonDividedDifference().getDivDiffDiag(
             x, np.array(to_do[i].astype(np.float)))
         print(i)
         div_diff.append(dd[-1])
         print(dd[-1])
     print(div_diff)
Esempio n. 5
0
 def calcDivDiffs(self, file_path, file_name):
     to_dos = []
     for i in range(len(file_name)):
         f = np.transpose(
             pd.read_csv(file_path + file_name[i] + '.csv',
                         sep=',',
                         header=0))
         to_dos.append(f)
         # print(f)
         # print(pd.DataFrame(f))
     div_diffs = np.zeros([10, 3])
     for i in range(len(file_name)):
         for j in range(to_dos[i].shape[1]):
             dd = newtonDividedDifference().getDivDiffDiag(
                 np.arange(10) + 1, to_dos[i][j])
             div_diffs[j][i] = dd[9]
             print(dd[9])
     pd.DataFrame(div_diffs).to_csv('./calc_dd.txt',
                                    sep='\t',
                                    header=None,
                                    index=False)
     return pd.DataFrame(div_diffs)