{ "info": { "author": "KenLeung", "author_email": "devyat192002@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta" ], "description": "ReadMe\r\nPDRandom by Ken Leung\r\nThe MIT License (MIT)\r\nCopyright (c) 2015 Ken Leung\r\n###Update 1.0.2####\r\nNew Feature: \r\n1. support multiprocessing\r\nfor function: RandList, GetCountList, GenCountList, OutputRawRandom, OutputGenCountList,\r\nYou can set argument nproc=NUM_OF_PROCESS\r\ne.g. gen.OutputGenCountList(int(1e6),[100,100],\"cosine2\",nproc=4,foption='a')\r\n**for windows users, u should start the program with if __name__==\"__main__\":\r\n\r\n2. you can append the existing data files\r\nset foption='a' for appending\r\n*for appending a countlist file, the binNum should be matched with the file\r\n\r\n3. new function: GenCountList(number,binNum,nproc=1) ---- directly generate and return a countlist\r\n\r\nmisc: tidy up\r\n\r\n*any bugs, tell me via email or github\r\n\r\n#===== Information =======\r\nGenerate random numbers according to your probability function, e.g. sin(x), cos(x) , sin(x)sin(y)\r\nf: R^n -> R\r\n\r\nLogic/Method:\r\nUse acceptance-rejection method, Step Function to be the bound function\r\n\r\n\r\nHow TO Use:\r\n*** for dimension > 1 (multivariable function) , please pass list arguments\r\n\r\n1. Define Your probability density function, e.g.\r\ndef test(input):\r\n\treturn abs(math.sin(input))\r\n\r\n*If it is multivariable function, please pass a list argument. e.g.\r\n\ttest([1,2]) # for 2D function\r\n\r\n\r\n2. create a PDRandom object\r\nranObject = PDRandom.PDRandom(test, lowerBound, UpperBound, NumDiv, NumSubDiv, dimension )\r\n\r\n# test: your density function\r\n#\r\n# lowerBound, UpperBound: x \u03f5 [lowerBound,UpperBound) \r\n#\t\t\tfor dim >1 : x0 \u03f5 [lowerBound[0],UpperBound[0]), x1 \u03f5 [lowerBound[1],UpperBound[1]) , ..............\r\n#\r\n# NumDiv: divide the [UpperBound - LowerBound] into numbers of divisions for the Step function (bound function)\r\n#\t\t NumDiv >=1 . NumDiv increases -> Rejection Rate decreases (i.e. increases the acceptance chance of random numbers) ,\r\n#\t\t\tBUT large NumDiv would cause performance hit \r\n#\t\t\t* this parameter related to the performance(Speed)\r\n#\r\n# NumSubDiv (Optional): used to find the maximum value in a division, related to the accuracy, and initialization time. \r\n#\t\te.g. 1000 or [10,10,10]\r\n#\r\n# Dimension: specify how many input varibles\r\n\r\n3. Some Class Function You can Use:\r\nNext(): return one random Number\r\n\r\nRandList(num): Return a list of random numbers\r\n\r\nGetCountList(binNum, randlist): \r\n\t#To count the numbers of random numbers within the range for bins (divisions)\r\n\t# if binLowerBound <= randomNum < binUpperBound, randomNum will be counted for the bin with value = binLowerBound\r\n\t#inclusive lowerbound, exclusive upper\r\n\t\r\n\targument: \r\n\t\tbinNum: divide the range into binNum bins\r\n\t\trandlist: generated by RandList(num)\r\n\r\n\treturn a countlist,e.g. [ [bin1x, bin1y ,count], [bin2x,bin2y,count] ....... ] for two variable function\t\r\n\te.g. randlist = [1.1, 2.4] # lowerBound = 0, UpperBound =5 , binNum = 5 , dimension=1\r\n\t\t\tcountlist= [ [0,0]\r\n\t\t\t\t\t\t[1,1] # 1.1 counted for 1\r\n\t\t\t\t\t\t[2,1]\t# 2.4 counted for 2\r\n\t\t\t\t\t\t[3,0]\r\n\t\t\t\t\t\t[4,0]\r\n\r\n\t\t\t\t\t\t] # total 5 number of bins\r\n\r\nOutputCountList(countlist, filename) : output to a file with filename (space sperate format)\r\n\r\nOutputRawRandom(number, filename): generate rand numbers to a file with filename\r\n\r\nOutputGenCountList (number , binNum, filename): generate and directly output the count list\r\n\r\n#===================================================================\r\n\r\nExample:\r\n1-Dim case:\r\ndef cosine (input):\r\n\treturn abs(math.cos(input))\r\ngen = PDRandom.PDRandom(cosine, -1, math.pi, 10,dimension=1)\r\ngen.OutputGenCountList(100000,50,\"consine2\")\r\n\r\nn-Dim case: n>1\r\ndef sine3(input):\r\n\treturn abs(math.sin(input[0])*math.sin(input[1])*math.sin(input[2]))\r\ngen = PDRandom.PDRandom(sine3, [-1,0,1], [math.pi,math.pi,math.pi], [10,10,10],dimension=3)\r\nlis = gen.RandList(1000)\r\nprint (gen.GetCountList([10,10,10], lis))\r\ngen.OutputGenCountList(100000,[50,50,50],\"sine3\")\r\n\r\n\r\nmisc:\r\n\tcontact: devyat192002@gmail.com\r\n\tfeel free to contact me if any question, bug, opinion, I will response as soon as possible", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/d2fdydx/PDRandom", "keywords": "probability density,random", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "PDRandom", "package_url": "https://pypi.org/project/PDRandom/", "platform": "tested for windows, linux", "project_url": "https://pypi.org/project/PDRandom/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/d2fdydx/PDRandom" }, "release_url": "https://pypi.org/project/PDRandom/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "python module for generating random numbers according to a given probability density function", "version": "1.0.2" }, "last_serial": 1524945, "releases": { "1.0": [], "1.0.1": [ { "comment_text": "", "digests": { "md5": "6aef734c649f0d55ebc667054365fe88", "sha256": "f4b2e7bae67016e41ef205c1a84c456cda804c692ee3567ed0de718d17a7694b" }, "downloads": -1, "filename": "PDRandom-1.0.1.tar.gz", "has_sig": false, "md5_digest": "6aef734c649f0d55ebc667054365fe88", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5488, "upload_time": "2015-04-26T08:15:53", "url": "https://files.pythonhosted.org/packages/e5/8c/b32225375bd168a58769c46e6e821f01f7c772cf38889c920d14cfe2d96d/PDRandom-1.0.1.tar.gz" }, { "comment_text": "", "digests": { "md5": "17a0f98e55abf8cd6d94205fa5740050", "sha256": "2c42b8b4d05ab1adfb396e21db1ede3fd5b8e8e517f0c90666cd40a1789ac41e" }, "downloads": -1, "filename": "PDRandom-1.0.1.zip", "has_sig": false, "md5_digest": "17a0f98e55abf8cd6d94205fa5740050", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6123, "upload_time": "2015-04-26T08:15:02", "url": "https://files.pythonhosted.org/packages/38/a2/954e9db5ef94f0252379846c376e74170f273181eaf998e8fc4d6613730e/PDRandom-1.0.1.zip" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "3bfd560d8fb5b456ed7bd810b14d5290", "sha256": "6627350e985968bf907f8ace54b46376a2e68b81108582ee6738bd707cce2fbc" }, "downloads": -1, "filename": "PDRandom-1.0.2.tar.gz", "has_sig": false, "md5_digest": "3bfd560d8fb5b456ed7bd810b14d5290", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6887, "upload_time": "2015-04-28T18:03:48", "url": "https://files.pythonhosted.org/packages/2b/86/c6da44904f64338cafd05e614cf5914b68b6c54141f67f68ea22a1988959/PDRandom-1.0.2.tar.gz" }, { "comment_text": "", "digests": { "md5": "e990dc2a252a971510e088692d58e859", "sha256": "6c0e4054ac7e641e4125dffdfaa92d197238543fff348e382a1113bef5cc4de6" }, "downloads": -1, "filename": "PDRandom-1.0.2.zip", "has_sig": false, "md5_digest": "e990dc2a252a971510e088692d58e859", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7588, "upload_time": "2015-04-28T18:03:51", "url": "https://files.pythonhosted.org/packages/5b/7e/1e71f1cd1083a3e11e38d1352d544b2312ecef528fa5cd2fb47ddcd8bc57/PDRandom-1.0.2.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3bfd560d8fb5b456ed7bd810b14d5290", "sha256": "6627350e985968bf907f8ace54b46376a2e68b81108582ee6738bd707cce2fbc" }, "downloads": -1, "filename": "PDRandom-1.0.2.tar.gz", "has_sig": false, "md5_digest": "3bfd560d8fb5b456ed7bd810b14d5290", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6887, "upload_time": "2015-04-28T18:03:48", "url": "https://files.pythonhosted.org/packages/2b/86/c6da44904f64338cafd05e614cf5914b68b6c54141f67f68ea22a1988959/PDRandom-1.0.2.tar.gz" }, { "comment_text": "", "digests": { "md5": "e990dc2a252a971510e088692d58e859", "sha256": "6c0e4054ac7e641e4125dffdfaa92d197238543fff348e382a1113bef5cc4de6" }, "downloads": -1, "filename": "PDRandom-1.0.2.zip", "has_sig": false, "md5_digest": "e990dc2a252a971510e088692d58e859", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7588, "upload_time": "2015-04-28T18:03:51", "url": "https://files.pythonhosted.org/packages/5b/7e/1e71f1cd1083a3e11e38d1352d544b2312ecef528fa5cd2fb47ddcd8bc57/PDRandom-1.0.2.zip" } ] }