Пример #1
0
    ph = np.concatenate([phenotypes(i) for i in mat2par(mat)])
    result = ph["apd90"]
    result[np.isnan(result)] = 0
    return py2ri(result)

@ri.rternalize
def appeak(mat):
    ph = np.concatenate([phenotypes(i) for i in mat2par(mat)])
    result = ph["appeak"]
    result[np.isnan(result)] = 0
    return py2ri(result)

#             mu   mu.star     sigma
#Cm   -0.4348831 0.6603604 0.9338907
#Vmyo  0.1264869 0.1264869 0.1657938
#             mu   mu.star     sigma
#Cm    0.6716927 0.6716927 0.3328038
#Vmyo -0.3135712 0.3135712 0.3033346

if __name__ == "__main__":
    binf = 0.5 * unstruct(m.pr[factors])
    bsup = 1.5 * unstruct(m.pr[factors])
    r.pdf("morrisplot.pdf")
    r.plot(r.morris(apd90, factors=factors, r=2, design={"type": "oat", "levels": 10, "grid.jump": 5}, binf=binf, bsup=bsup))
    r.dev_off()

#    saved = np.load("/tmp/saveme.npy")
#    ph = [phenotypes(i) for i in saved]
#    fail = [np.isnan(i).all() for i in ph]
#    result = np.logical_not(fail).astype(float)
Пример #2
0
    """Make a function to return a named field of the phenotype array."""
    
    @ri.rternalize
    def fun(rmatrix):
        """Scalar function for use with R's sensitivity::morris()."""
        ph = np.concatenate([phenotypes(i) for i in mat2par(rmatrix)])
        return py2ri(ph[field])
    
    return fun

if __name__ == "__main__":
    # Sensitivity analysis
    baseline = unstruct(m.pr[factors])
    lower = 0.5 * baseline
    upper = 1.5 * baseline
    result = dict()
    for field in "appeak", "apd90", "ctpeak", "ctbase", "ctd90":
        r.set_seed(20120221)  # repeatable random sampling
        result[field] = r.morris(scalar_pheno(field), factors=factors, r=2, 
            design={"type": "oat", "levels": 10, "grid.jump": 5}, 
            binf=lower, bsup=upper)
    # Print and visualize results
    r.png("sensitivity.png", width=1024, height=768, pointsize=24)
    r.par(mfrow=(2, 3))  # multiple figures in two rows, three columns
    for k, v in result.items():
        print "===================================================="
        print k
        print v
        r.plot(v, log="y", main=k)
    r.dev_off()  # close image file