{ "info": { "author": "Richard Keene", "author_email": "rmkeene@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# TWIT - Tensor Weighted Interpolative Transfer\n\nRichard Keene September 2, 2019\npython PtPI package https://pypi.org/project/twit-rkeene/\nPython 3 only.\n\n# Concept of TWIT\nThe purpose of TWIT is to allow transfer of values from a source tensor to a destination tensor\nwith correct interpolation of values. The source and destination do not have to have the same number of dimensions, \ne.g. len(src.shape) != len(dst.shape).\nAlso the range of indices do not have to match in count. For example given two one dimensional tensors (vectors of values)\none could say copy from source range (2,7) to destination range (0,2) and use source to destination multipliers of (0.5, 0.9). This will\ncopy source values at indices 2,3,4,5,6,7 to destination indices 0,1,2 (obviously 'scale' the data) and multiply \nsource[2] by 0.5 to go to destination[0] and interpolate the multiplier (weight) up to 0.9 for subsequent indices.\n\n### Energy Conservation\nIn the above example of scaling down the naive approach would just sum in the source values multiplied by the interpolate\nweights would result in a destination that is 6/3 or 2x 'brighter' than the source.\nWhat TWIT does is maintain constant energy or brightness while scaling up or down.\n\nFar more intuitive is the example of a 3D tensor which happens to be a color image, going to a destination tensor \nthat is a 2D grey scale image. We want to maintain brightness and the dimensions do not match.\n\nThis image scale operation might be a source image that is 300x400x3 to a destination that is 400x600. Nothing matches.\nLets take the example of input to TWIT of \n*Note: One can use square brackets for clarity, twit does not care.*\n\n([(0, 0, 1.0), (299, 399, 1.0)], [(0, 0, 1.0), (399, 599, 0.5)], [(0, 0, 1.0), (3, 0, 1.0)])\n\nThe parameters are pairs of tuples describing the start and end for each axis, outermost to innermost in order.\nSo (0, 0, 1.0), (299, 399, 1.0) indicates to use the sourece range 0 to 299 and destination range 0 to 399\nand a weight range of 1.0 to 1.0 for the outermost axis, the height of the images.\nThen (0, 0, 1.0), (399, 599, 0.5) says to use source 0 to 399, destination 0 to 599, and weights 1.0 down to 0.5\nfor the height to destination copy. This will fade the image horizontally from 1.0 to medium dark 0.5.\nThe last pair (0, 0, 1.0), (3, 0, 1.0) says to use the RGB of the source to the single destination 'pixel'\nand use the average (r + b + g)/3.0 as the value.\n\n# Iteration\nOnce you have set up a twit, which is an iterator, it will return successive (sourceindex, destinationindex, weight) tuple sets.\nIn the image example above one iteration might return\n((50, 67, 1.0), (100, 150, 0.7), (1, 0, 1.0)) I made those numbers up, but they indicate:\n\ndestination[67, 150, 0] += source[50, 100, 1] * (1.0 * 0.7 * 1.0)\n\nIf you have loaded a color image into source, and destination starts as all zeros, then you get\na destination image stretched tall, and fading dimmer to the right.\nNotice that the image does not have to be range 0 to 255, nor even ranges 0.0 to 1.0 pixels. It can be any range\nand the ranges only have meaning to your program.\n\nOne can also specify only a sub range in any dimension. It does not have to be 0 to N. This will crop and \nscale to the destination cropped area.\n\nSide note: The old fashioned way to the above is to use PIL and make an image from the source, scale it, do the fade,\nthen convert back to a tensor. Ugly solution.\n\n# Reuse of twit results\nIf you are going to use the twit result repeatedly you should make the iterator, generate all the tuple triplets\nonce and then reuse the cached array.\n\n# Why TWIT?\nThe motivation for TWIT is to support the development of the SRS cognition algorithm and Cognate. The system has\nlots of concept maps that are N dimensional tensors represent some concept space. They are neurons and they are\nconnections between the concept maps. Every system tick we do a twit transfer (using cached twit iterator values)\nto transform data. The fact this library can als be used for image scaling in tensors is a side effect.\n\n# Range strings\nThere is also a range definition string format used for Neural net concept map editing and viewing.\nInput s is like \"{5,17} <2,3> [-0.1, 0.9]\" (see doc string for the module)\nFormat is ((srcstart, srcend), (dststart, dstend), (weightstart, weightend)).\nsrc, dst, etc are to determine the ranges. The ..._shape_idx are which dimension of the array to use\nfor defaults.\nBoth indices and weights can be revered to indicate a reversed interpolation along that axis.\nIndexes are inclusive \"start value to end value\", so {5, 9} means 5,6,7,8,9. \nThis is in support of editors for people to easily enter ranges and weights for neural nets.\n(See Cognate and NuTank)\n\n# Helper Functions\nTWIT includes some static functions to help do things.\n\napply_twit(twt, t1, t2) will iterate the twit twt and do the copy and multiplies from t1 to t2. If t1 and t2 are not the\nsame number of dimensions it will create the appropriate view and then do the work. There is a clear destination flag to \nzero out the destination before iteration. t2 MUST be a array style tensor since it gets written to in-place. You can pass\nin an optional twit cache.\n\ntensor_transfer(t1, t2) builds the twit iterator to map all of t1 to t2 with 1.0 weight on all axes and then does the transfer\n\nmake_twit_cache(twt) Simply fills a list with the triples from the twit iterator.\n\nA little helper function if you need it, match_tensor_shape_lengths, will make the views and return them given a t1 and t2.\n\n# Command Line Arguments to twit.py\nAs a helper one can run python twit and it will print out the \nparams for those source and estination shapes with weight 1.0. This helps prevent mistakes in \nparameter count and order when developing with twit. For example:\n\npython twit (5,6) (7,8,9)\n\nand it prints\n\n(((0, 0), (0, 6), (1.0, 1.0)), ((0, 4), (0, 7), (1.0, 1.0)), ((0, 5), (0, 8), (1.0, 1.0)))\n\nNote that you must not have spaces between the numbers and commas. The paranthises are optional.\n\nNote that the source range is two elements in the shape and the destination is three. The source gets\na 1, appended to the front so the shapes used are (1,5,6) (7,8,9) thus that (0,0) on the front of the tuples.\n\n# Tests\nThere is a twit_test.py file with all the unit tests.\n\n# Examples\nThere is a image_scale.py test file for an example. It is not very generic. (Not yet done.)\n\n# Source GitHub\nAt https://github.com/RMKeene/twit is the project. Any improvements or bug fixes will be appreciated.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/RMKeene/twit", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "twit", "package_url": "https://pypi.org/project/twit/", "platform": "", "project_url": "https://pypi.org/project/twit/", "project_urls": { "Homepage": "https://github.com/RMKeene/twit" }, "release_url": "https://pypi.org/project/twit/0.0.9/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Tensor Weighted Interpolative Transfer", "version": "0.0.9" }, "last_serial": 5793356, "releases": { "0.0.5": [ { "comment_text": "", "digests": { "md5": "83069146654621a65ae5b4d8987604fc", "sha256": "4c2f2a95099e94e8dc32a4c757eec143e5c200c9a1e989ef58d8f40fdbe82c0c" }, "downloads": -1, "filename": "twit-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "83069146654621a65ae5b4d8987604fc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4500, "upload_time": "2019-09-04T04:04:44", "url": "https://files.pythonhosted.org/packages/c1/6b/1a10513143e0f7ad28bac6de8b39543052bea48412e778a13ee5b59dc4ad/twit-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "79e13d746a173857b74cdf070083aa83", "sha256": "fd63ea3b1255477c96de9047b792706cf608d28bc8d1327ac4af02d674177d41" }, "downloads": -1, "filename": "twit-0.0.5.tar.gz", "has_sig": false, "md5_digest": "79e13d746a173857b74cdf070083aa83", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3953, "upload_time": "2019-09-04T04:04:47", "url": "https://files.pythonhosted.org/packages/25/30/3aa49832a8932b79b2864173e9fe88cf69e141ca662b03f90737ef42f475/twit-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "2604294c69b41698239874841188789e", "sha256": "13283df9cc3963cf2c301942fd1fd836cdc1c131a705672246ea47e04b73ab15" }, "downloads": -1, "filename": "twit-0.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "2604294c69b41698239874841188789e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4500, "upload_time": "2019-09-04T17:00:30", "url": "https://files.pythonhosted.org/packages/8a/eb/a46c950791ee465861c0b164efcb37566728dcbefadb029d98baf0761686/twit-0.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b751c4c2e7c80731124b96b2840b8538", "sha256": "15f657f1db5694285af26c1576f881f5eaf5b0177e6e370cbd1405462570baba" }, "downloads": -1, "filename": "twit-0.0.6.tar.gz", "has_sig": false, "md5_digest": "b751c4c2e7c80731124b96b2840b8538", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3954, "upload_time": "2019-09-04T17:00:32", "url": "https://files.pythonhosted.org/packages/8a/4a/abf9eee9833d6c73bbee356aad6121c94cd4da99dccafff299c614cd572b/twit-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "b8400d660a810b4589d2d7b0bcffe120", "sha256": "fade44900aa5b250f20090de4451958ad3bd92a89b1a9f3691364a938551651e" }, "downloads": -1, "filename": "twit-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "b8400d660a810b4589d2d7b0bcffe120", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4501, "upload_time": "2019-09-04T17:17:26", "url": "https://files.pythonhosted.org/packages/42/66/9fd343cb9dcf3da9b4b51c57d5af93d7a1991557ca1770f0976bf074d2ab/twit-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "32eb13dc52f55675e38195a75c4010a7", "sha256": "8a084ee7fc405852652392b8ff963f4de763d347b3c36c2060d9933cc91c1a46" }, "downloads": -1, "filename": "twit-0.0.7.tar.gz", "has_sig": false, "md5_digest": "32eb13dc52f55675e38195a75c4010a7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3955, "upload_time": "2019-09-04T17:17:27", "url": "https://files.pythonhosted.org/packages/8f/a8/86ebca6a8891c1f715e92ed085388cbf2c420450bbbdb61e05c160bfaa3f/twit-0.0.7.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "3e6055462f4d2d2ebaf769538b76ddc7", "sha256": "1cdf0c7be119568adf21b9265f69fcc117448944a1c1092d3d50330e3475e14b" }, "downloads": -1, "filename": "twit-0.0.9-py3-none-any.whl", "has_sig": false, "md5_digest": "3e6055462f4d2d2ebaf769538b76ddc7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4830, "upload_time": "2019-09-06T18:08:39", "url": "https://files.pythonhosted.org/packages/57/e5/0e4c92189af92e17a731cf4b527efc865089e705f34a0067b29b08dc831c/twit-0.0.9-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "85d4d46833500606c2a5785c3209b7b8", "sha256": "7c3551e50c26c750e0448a77cd35e9e0bc9085f0a81ecac42c2ba745f7f0829c" }, "downloads": -1, "filename": "twit-0.0.9.tar.gz", "has_sig": false, "md5_digest": "85d4d46833500606c2a5785c3209b7b8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4402, "upload_time": "2019-09-06T18:08:40", "url": "https://files.pythonhosted.org/packages/99/19/aed3fb56535e90659c4baf985a1ad8d829fd57053f0515133bde907e3f7b/twit-0.0.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3e6055462f4d2d2ebaf769538b76ddc7", "sha256": "1cdf0c7be119568adf21b9265f69fcc117448944a1c1092d3d50330e3475e14b" }, "downloads": -1, "filename": "twit-0.0.9-py3-none-any.whl", "has_sig": false, "md5_digest": "3e6055462f4d2d2ebaf769538b76ddc7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4830, "upload_time": "2019-09-06T18:08:39", "url": "https://files.pythonhosted.org/packages/57/e5/0e4c92189af92e17a731cf4b527efc865089e705f34a0067b29b08dc831c/twit-0.0.9-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "85d4d46833500606c2a5785c3209b7b8", "sha256": "7c3551e50c26c750e0448a77cd35e9e0bc9085f0a81ecac42c2ba745f7f0829c" }, "downloads": -1, "filename": "twit-0.0.9.tar.gz", "has_sig": false, "md5_digest": "85d4d46833500606c2a5785c3209b7b8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 4402, "upload_time": "2019-09-06T18:08:40", "url": "https://files.pythonhosted.org/packages/99/19/aed3fb56535e90659c4baf985a1ad8d829fd57053f0515133bde907e3f7b/twit-0.0.9.tar.gz" } ] }