def testBetaPDF6(self): print "\n test Beta PDF 6: Skewed" ZPoints = 101 ZmeanPoints = 1 ZvarPoints = 1 ZMin = 0 ZMax = 1 ZmeanMin = 0.1 ZmeanMax = ZmeanMin ZvarMin = 0.01 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 PDF = np.zeros(ZPoints) PDF[0] = 5.93 PDF[1] = 1.43 PDF[2] = 0.209 PDF[3] = 0.01557 PDF[4] = 0 PDF[5] = 0 # calculate PDF bTest = b.pdfVal(Z, bPdfValM) # test for k in range(ZPoints): bPDF[k] = bPdfValM.GetVal(0, 0, 20 * k) """ print "PDF[0] = inf, bPDF[0] = " + str(bPDF[0]) print "PDF[1] = " + str(PDF[1]) + ", bPDF[1] = " + str(bPDF[1]) print "PDF[2] = " + str(PDF[2]) + ", bPDF[2] = " + str(bPDF[2]) print "PDF[3] = " + str(PDF[3]) + ", bPDF[3] = " + str(bPDF[3]) print "PDF[4] = " + str(PDF[4]) + ", bPDF[4] = " + str(bPDF[4]) print "PDF[5] = " + str(PDF[5]) + ", bPDF[4] = " + str(bPDF[5]) print "PDF[6] = inf, bPDF[5] = " + str(bPDF[6]) """ self.assertTrue(np.abs(bPDF[1] - PDF[1]) < 0.01) self.assertTrue(np.abs(bPDF[2] - PDF[2]) < 0.01) self.assertTrue(np.abs(bPDF[3] - PDF[3]) < 0.01) self.assertTrue(np.abs(bPDF[4] - PDF[4]) < 0.01) self.assertTrue(np.abs(bPDF[5] - PDF[5]) < 0.01) self.assertEqual(bTest, 0)
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 testBetaPDF1(self): print "\n Beta PDF 1: Zero Variance" 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 b = pdf.BetaPDF(Zmean, Zvar) bPdfValM = matrix3d.Matrix3D(ZvarPoints, ZmeanPoints, ZPoints) # expected PDF values PDF = np.zeros(ZPoints) PDF[1] = 1 * (ZPoints - 1) # calculate PDF test = b.pdfVal(Z, bPdfValM) PDFCalc = np.zeros(ZPoints) # test for k in range(ZPoints): PDFCalc[k] = bPdfValM.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, bPdfValM, postTrapz, Trapz) c = convolute.convVal_func(Z, testData, bPdfValM, 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)
def testBetaPDF3(self): print "\n Beta PDF 3: Symmetric" Points = 6 ZPoints = 101 ZmeanPoints = 1 ZvarPoints = 1 ZMin = 0 ZMax = 1 ZmeanMin = 0.5 ZmeanMax = ZmeanMin ZvarMin = 0.05 ZvarMax = ZvarMin Nodes = 10 # 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(Points) # expected PDF values PDF = np.zeros(ZPoints) PDF[0] = 0 PDF[1] = 0.96 PDF[2] = 1.44 PDF[3] = 1.44 PDF[4] = 0.96 PDF[5] = 0 # calculate PDF bTest = b.pdfVal(Z, bPdfValM) # test for k in range(Points): bPDF[k] = bPdfValM.GetVal(0, 0, 20 * k) """ print "PDF[0] = inf, bPDF[0] = " + str(bPDF[0]) print "PDF[1] = " + str(PDF[1]) + ", bPDF[1] = " + str(bPDF[1]) print "PDF[2] = " + str(PDF[2]) + ", bPDF[2] = " + str(bPDF[2]) print "PDF[3] = " + str(PDF[3]) + ", bPDF[3] = " + str(bPDF[3]) print "PDF[4] = " + str(PDF[4]) + ", bPDF[4] = " + str(bPDF[4]) print "PDF[5] = inf, bPDF[5] = " + str(bPDF[5]) """ self.assertTrue(np.abs(bPDF[1] - PDF[1]) < 0.2) self.assertTrue(np.abs(bPDF[2] - PDF[2]) < 0.2) self.assertTrue(np.abs(bPDF[3] - PDF[3]) < 0.2) self.assertTrue(np.abs(bPDF[4] - PDF[4]) < 0.2) self.assertEqual(bTest, 0) # 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, bPdfValM, postTrapz, Trapz) c = convolute.convVal_func(Z, testData, bPdfValM, postQuadr, Quadr) for j in range(ZmeanPoints): filterTrapz[j] = postTrapz.GetVal(0, j) filterQuadr[j] = postQuadr.GetVal(0, j) self.assertTrue(np.abs(filterTrapz[j] - 1) < 0.01) self.assertTrue(np.abs(filterQuadr[j] - 1) < 0.01)
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) pdfValM = matrix3d.Matrix3D(ZvarPoints, ZmeanPoints, ZPoints) for i in range(ZvarPoints): for j in range(ZmeanPoints): for k in range(ZPoints): pdfValM.SetVal(i, j, k, 0) pdfValReturn = d.pdfVal(Z, pdfValM)