def testDeltaPDF2(self): print "\n test Delta PDF 2:" ZPoints = 6 ZmeanPoints = 1 ZvarPoints = 1 ZMin = 0 ZMax = 1 ZmeanMin = 0.25 ZmeanMax = ZmeanMin ZvarMin = 0 ZvarMax = ZvarMin # create arrays of type "double *" Z = np.linspace(ZMin, ZMax, ZPoints) Zmean = np.linspace(ZmeanMin, ZmeanMax, ZmeanPoints) Zvar = np.linspace(ZvarMin, ZvarMax, ZvarPoints) # create instances of PDF class d = pdf.DeltaPDF(Zmean) dPdfValM = matrix3d.Matrix3D(ZvarPoints, ZmeanPoints, ZPoints) # expected PDF values PDF = np.zeros(ZPoints) PDF[1] = 0.75 * (ZPoints - 1) PDF[2] = 0.25 * (ZPoints - 1) # calculate PDF test = d.pdfVal(Z, dPdfValM) PDFCalc = np.zeros(ZPoints) # test for k in range(ZPoints): PDFCalc[k] = dPdfValM.GetVal(0, 0, k) self.assertAlmostEqual(PDF[k], PDFCalc[k])
def testBetaPDF1(self): print "\n test Beta PDF 1: Var = 0 --> Delta PDF" ZPoints = 6 ZmeanPoints = 1 ZvarPoints = 1 ZMin = 0 ZMax = 1 ZmeanMin = 0.25 ZmeanMax = ZmeanMin ZvarMin = 0 ZvarMax = ZvarMin # create arrays of type "double *" Z = np.linspace(ZMin, ZMax, ZPoints) Zmean = np.linspace(ZmeanMin, ZmeanMax, ZmeanPoints) Zvar = np.linspace(ZvarMin, ZvarMax, ZvarPoints) # create instances of PDF class b = pdf.BetaPDF(Zmean, Zvar) bPdfValM = matrix3d.Matrix3D(ZvarPoints, ZmeanPoints, ZPoints) bPDF = np.zeros(ZPoints) # expected PDF values d = pdf.DeltaPDF(Zmean) dPdfValM = matrix3d.Matrix3D(ZvarPoints, ZmeanPoints, ZPoints) dPDF = np.zeros(ZPoints) # calculate PDF bTest = b.pdfVal(Z, bPdfValM) dTest = d.pdfVal(Z, dPdfValM) # test for k in range(ZPoints): bPDF[k] = bPdfValM.GetVal(0, 0, k) dPDF[k] = dPdfValM.GetVal(0, 0, k) self.assertAlmostEqual(bPDF[k], dPDF[k]) self.assertEqual(bTest, 0) self.assertEqual(dTest, 0)
def testDeltaPDF1(self): print "\n Delta PDF 1:" """ NOTE: Simpson's Rule doesn't work for Delta PDFs; see integrator test for a proof/explanation """ ZPoints = 5 ZmeanPoints = 1 ZvarPoints = 1 ZMin = 0 ZMax = 1 ZmeanMin = 0.25 ZmeanMax = ZmeanMin ZvarMin = 0 ZvarMax = ZvarMin Nodes = 50 # create arrays of type "double *" Z = np.linspace(ZMin, ZMax, ZPoints) Zmean = np.linspace(ZmeanMin, ZmeanMax, ZmeanPoints) Zvar = np.linspace(ZvarMin, ZvarMax, ZvarPoints) # create instances of PDF class d = pdf.DeltaPDF(Zmean) dPdfValM = matrix3d.Matrix3D(ZvarPoints, ZmeanPoints, ZPoints) # expected PDF values PDF = np.zeros(ZPoints) PDF[1] = 1 * (ZPoints - 1) # calculate PDF test = d.pdfVal(Z, dPdfValM) PDFCalc = np.zeros(ZPoints) # test for k in range(ZPoints): PDFCalc[k] = dPdfValM.GetVal(0, 0, k) self.assertAlmostEqual(PDF[k], PDFCalc[k]) # create Integrators Trapz = integrator.Trapz() Quadr = integrator.GLQuad(Nodes) # create Filtered Data Matrices postTrapz = matrix.Matrix(ZvarPoints, ZmeanPoints) postQuadr = matrix.Matrix(ZvarPoints, ZmeanPoints) # create matrix for printing filterTrapz = np.zeros(ZmeanPoints) filterQuadr = np.zeros(ZmeanPoints) # create test data testData = np.ones(ZPoints) # calculate filtered reaction rates c = convolute.convVal_func(Z, testData, dPdfValM, postTrapz, Trapz) c = convolute.convVal_func(Z, testData, dPdfValM, postQuadr, Quadr) for j in range(ZmeanPoints): filterTrapz[j] = postTrapz.GetVal(0, j) filterQuadr[j] = postQuadr.GetVal(0, j) self.assertEqual(filterTrapz[j], 1) self.assertAlmostEqual(filterQuadr[j], 1, 1)
delimiter="\t", usecols=0) # if no Z_grid is specified, Z and Zmean will be equivalent if options["Zmean grid"][0] == 'Z': Zmean = Z else: Zmean = np.linspace(0, 1, int(options["Zmean grid"][0])) Zpdf = options["Zpdf"] # Generate pdf objects print "Generating PDF matrix with", Zpdf[0], "PDF" if Zpdf[0] == "delta": # delta pdf has variance 0 Zvar_grid = [1] Zvar_max = [0] Zvar = np.linspace(0, float(Zvar_max[0]), int(Zvar_grid[0])) d = pdf.DeltaPDF(Zmean) elif Zpdf[ 0] == "beta": # must include user specified variances for beta pdf # currently not supported Zvar_max = iof.read_input("Zvar_max:", inputs) Zvar_grid = iof.read_input("Zvar_grid:", inputs) Zvar = np.linspace(0, float(Zvar_max[0]), int(Zvar_grid[0])) d = pdf.BetaPDF(Zmean, Zvar) else: raise IOError( "Incorrect PDF input %s, currently only DELTA and BETA are supported" % Zpdf[0]) # generate PDF matrix ZPoints = len(Z) ZvarPoints = len(Zvar) ZmeanPoints = len(Zmean)