|
This is amazing and I simultaneously need to and don't want to look at the source code
|
# ? Sep 30, 2013 17:32 |
|
|
# ? May 9, 2024 03:57 |
|
It's the same trick I used for gwfal. https://github.com/magcius/toenail/blob/master/gwfal_example.py https://github.com/magcius/toenail/blob/master/gwfal.py
|
# ? Sep 30, 2013 17:45 |
|
Dren posted:I think what you'll have to do here is unpack the array in your overloaded __getitem__ method and feed it to np.ndarray.__getitem__() one value at a time. Thanks, this got me in the right path! Python code:
Other than pure curiosity, here's my motivation for this: A lot of numpy code seems to revolve around passing arrays as indices and when you get an array with crazy values you use np.clip and limit those values so you don't get errors and still keep going. The thing is though that this kind of interpolation sometimes gives you some silly results, like look at this guy: So I'm thinking instead of passing through np.clip just using some sort of "defaultarray" and then get a result like this: Without really needing to rethink the whole "passing arrays as indices" approach. EDIT: The code doesn't actually work on higher dimensional arrays and oh god this looks like a nightmare to get right. Symbolic Butt fucked around with this message at 19:45 on Sep 30, 2013 |
# ? Sep 30, 2013 17:48 |
|
Pollyanna posted:Cool, thanks. I updated it: tick_world is still doing the mutate-its-argument thing. Pollyanna posted:Now I'm trying to figure out how to make it return an image of the array. PIL has an Image.fromarray function for creating an image out of a numpy array. Alternatively you can use matplotlib.
|
# ? Sep 30, 2013 18:45 |
|
Dren posted:I mostly like this but I think you should move _step() and tick() out of your Universe class. That way Universe is a representation of the game board and there would be a clean separation between the model (Universe) and the business logic (_step() and tick()). Also, why is _step() a property? _step calculates the cells that should be set to live/die by tick(), I wanted to be able to access the points before calling tick() so I could throw a quick view with pygame together. I wasn't familiar with the GoL so I wrote the tests for the requirements first, and in writing the code I took that intention of _step() returning the next state and not applying it too literally. In the process of cleaning it up, I made _step() a method that returns the next frame for tick() and made _live_points() and _dead_points() methods with the current live/dead points, and scrapped writing a getter/setter to make them a property. Didn't think python would choke so easily on the naive method I posted, so I cleaned it up a bit so it can handle 100x100 Universe instances without chugging along. Pulled out the subfuncs out of _step() and neighbors() so that they aren't created/destroyed a dozen a times a tick. Also using sets/frozensets sped things up considerably. I'll play with numpy arrays when I have some time at work, just running the script through pypy almost triples the speed it takes to tick(). Anyone want to pick this apart and tell me what I could do better? Where would _step() and tick() better be implemented? https://gist.github.com/thismachinechills/6767584 game logic https://gist.github.com/thismachinechills/6767628 pygame (this was just thrown together) edit: For future reference: is there a way to interface a module running in Pypy with the standard interpreter? Could I run my model through pypy and have the view layer run in pygame? In this case, numpy + removing redundant cruft will probably speed things up, but I'm still curious. If it isn't feasible, what about setting up a shared resource in memory that the Pypy module writes to and the standard python interpreter can read from? help babby use computer double edit: How do I initialize a 2-d numpy array of booleans? Never mind, figured it out. code:
Accomplishes what I want. Its actually slower than pythons built in types. Pypy flies through the original salisbury shake fucked around with this message at 02:29 on Oct 1, 2013 |
# ? Sep 30, 2013 19:08 |
|
Pollyanna posted:I actually think PyCharm automatically handles tabs and spaces and whatnot already, cause tabbing puts in four spaces for me. Easy enough. TKinter in general sucks. I have had some experience with PyQt and wxpython, and they both have some good tutorials out there
|
# ? Oct 1, 2013 01:30 |
|
I was unable to resist writing my own game of life implementation. salisbury shake, I benchmarked both of ours and my computation of the next gameboard state is roughly twice as fast as yours. I benchmarked our implementations using the same randomly seeded 200x200 game board and made sure I only benchmarked the methods for computing the next board iteration. Here is my grid class, https://github.com/robwiss/gameoflife_py/blob/master/grid.py. I was pleased with my implementation of _num_alive_neighbors. I also included unit tests and two frontends for the game. One reads/writes to a file every time it is run, https://github.com/robwiss/gameoflife_py/blob/master/flatfile_gol.py. It generates a file like this (you can hand edit it if you like): code:
With a bit more effort I could get the pygame implementation to initialize from one of the text files but I didn't do that. I also didn't spend too much time thinking about making it efficient and I was kind of surprised that it doesn't run faster.
|
# ? Oct 1, 2013 02:41 |
|
code:
Is the expected speed up inherent to the design of numpy's array data structure compared to the standard ones? Or are the numpy arrays supposed to be used in conjunction with the numpy functions/operations to achieve the boost? This leads me to think the bottleneck isn't the data structures but my inefficient operations. I'm also probably abusing the numpy array just instantiating it, that could lend to the poo poo time edit: just saw your post now, Dren. checking out your code now salisbury shake fucked around with this message at 03:04 on Oct 1, 2013 |
# ? Oct 1, 2013 02:52 |
|
I just tried pypy, it is stupidly faster than cpython.code:
|
# ? Oct 1, 2013 03:30 |
|
It seems that some of my slow down was yet again borne of my tests:Python code:
code:
Dren posted:I just tried pypy, it is stupidly faster than cpython. Yea, I was surprised at the numbers. Unfortunately pygame isn't supported by pypy, but I'm not having any luck finding out if there is a solution to that problem though. I don't want to have to generate the frames save them to a file and load them to display them with pygame, as I added some click-to-toggle action for the cells. But I'm coming up dry on sources on how to interface a pypy module/instance/anything with a standard python script. edit: V thanks, I'll give the numpy docs a better look. Trying out numba now salisbury shake fucked around with this message at 05:30 on Oct 1, 2013 |
# ? Oct 1, 2013 04:14 |
|
salisbury shake posted:Or are the numpy arrays supposed to be used in conjunction with the numpy functions/operations to achieve the boost? Another interesting comparison (especially against pypy) would be to jit your code with Numba. I am traveling this week otherwise I would give it a go myself. BigRedDot fucked around with this message at 05:07 on Oct 1, 2013 |
# ? Oct 1, 2013 05:05 |
|
Since we're all comparing GOL implementations now here's mine: http://pastebin.com/zLu8eNWc. I've included the interface Dren's flatfile_gol.py expects for reading/writing grids, but everything of interest happens in tick(). Some times for different sized grids: code:
|
# ? Oct 1, 2013 05:34 |
|
Oh god, I've got a ways to go, don't I? QuarkJets posted:TKinter in general sucks. I have had some experience with PyQt and wxpython, and they both have some good tutorials out there Qt isn't free and I keep hearing bad things about wxpython. Pollyanna fucked around with this message at 05:44 on Oct 1, 2013 |
# ? Oct 1, 2013 05:41 |
|
Pollyanna posted:Oh god, I've got a ways to go, don't I? Just use PySide. Man, now I want to get out of bed and do a GoL implementation.
|
# ? Oct 1, 2013 06:54 |
|
Qt is free as in beer and free as in freedom.
|
# ? Oct 1, 2013 14:17 |
|
Qt didn't used to be free, but it's been free ever Qt 4.5 came out in 2008 (I think?) I know Tkinter sucks, but it really helps if you want to distribute a quick and dirty app to somebody who does not want to install PySide.
|
# ? Oct 1, 2013 14:29 |
|
2009 it was released under the LGPL. It had been GPL'd since 2000.
|
# ? Oct 1, 2013 14:37 |
|
Taking a break from GoL implementations: Am I right that Biopython isn't working under Python3 as yet? That's the main obstacle to me moving across to v3. I've looked at lists of "3 ready" libraries and it seems like most of the big, useful things have gone across: Numpy, elementtree, lxml. Any notable exceptions I might have missed?
|
# ? Oct 1, 2013 17:35 |
|
I've been using Biopython with 3.x for about two years, both 3.2 and 3.3. I keep a clone of their Git repository and just updated my local installation to release 162. setup.py build used to say something like "Python 3 support is still experimental" before it ran 2to3, but that message seems to have disappeared so maybe it's considered production-ready now. I've never had any problems with it on Python 3, but I've probably only used a third of the functionality that the package provides.
|
# ? Oct 1, 2013 17:41 |
|
Nippashish posted:Since we're all comparing GOL implementations now here's mine: http://pastebin.com/zLu8eNWc. I've included the interface Dren's flatfile_gol.py expects for reading/writing grids, but everything of interest happens in tick(). I like the approach of using a convolution kernel. The thought didn't even cross my mind. Can you modify it to also output the indices of the cells that changed and their new values? That way it would work with the pygame frontend. I gave it a shot but I'm not sure if I did it in the fastest way possible. Here it is: https://gist.github.com/robwiss/6781310 I updated the unit tests I wrote to work on the public API of the Grid class. Your stuff passes the tests (I found an error in my stuff). I also made the from_str stuff in flatfile_gol.py a bit more robust. Here's the benchmarks on a 200x200 random grid: code:
code:
I was going to try to get it to compile with numba but wow, llvmpy is a pain in the dick to install. Dren fucked around with this message at 19:13 on Oct 1, 2013 |
# ? Oct 1, 2013 17:41 |
|
Lysidas posted:I've been using Biopython with 3.x for about two years, both 3.2 and 3.3. I keep a clone of their Git repository and just updated my local installation to release 162. setup.py build used to say something like "Python 3 support is still experimental" before it ran 2to3, but that message seems to have disappeared so maybe it's considered production-ready now. Excellent - I couldn't find anything explicitly saying it was okay and biopython is missing from a lot of the "works with 3" lists, so I assumed the news was bad. Another question: pythonbrew seems to have been recently abandoned. Which was a pity, because it worked well. Pyenv is suggested as a replacement, but pyenv suggests you install it via homebrew which complains about the packages you installed using macports ... Since pythonbrew worked, I'll probably just install it. But has anyone else been through this process recently?
|
# ? Oct 1, 2013 19:40 |
|
The Game of Life occurs on an infinite plane, so given that you don't have enough memory to keep the whole thing in memory, how do you get around that limitation? I appreciate that there are other ways to manage things than a simple two-dimensional array of on/off values, for example you could instead have a list of cells that are "on", but (1) the number of cells that are "on" can still grow without bound, (2) your implementation is still incomplete on some level if it doesn't support an arbitrary, potentially infinite set of "on" cells in the initial state.
|
# ? Oct 1, 2013 19:59 |
|
You don't play it on an infinite plane. Or you make it wrap.
|
# ? Oct 1, 2013 20:00 |
|
Who cares how you would play it on an infinite plane? On an infinite plane it would take infinitely long to process an iteration of the game and ain't nobody got infinity time for a game of life iteration to compute.
|
# ? Oct 1, 2013 20:05 |
|
Dren posted:Who cares how you would play it on an infinite plane? On an infinite plane it would take infinitely long to process an iteration of the game and ain't nobody got infinity time for a game of life iteration to compute. Well, everybody was baldly stating that they were implementing "the game of life". They didn't state that they were implementing variants of the game of life that don't take place on an infinite plane. I was curious.
|
# ? Oct 1, 2013 20:08 |
|
Use a defaultdict with keys that are tuples holding coordinates and values of True/False or 1/0 to represent the board. Yeah, that runs out of memory or overflows (built-in wrapping!) at some point in reality, but on magic infinite hardware it works. E: to limit memory you could, say decrement every empty cell on a tick and delete the ones under some threshold, but you can probably make a initial board that grows to consume all memory if you try. You need magical hardware, basically. Munkeymon fucked around with this message at 20:28 on Oct 1, 2013 |
# ? Oct 1, 2013 20:09 |
|
Dren posted:Who cares how you would play it on an infinite plane? On an infinite plane it would take infinitely long to process an iteration of the game and ain't nobody got infinity time for a game of life iteration to compute.
|
# ? Oct 1, 2013 20:10 |
|
Hammerite posted:The Game of Life occurs on an infinite plane, so given that you don't have enough memory to keep the whole thing in memory, how do you get around that limitation? I appreciate that there are other ways to manage things than a simple two-dimensional array of on/off values, for example you could instead have a list of cells that are "on", but (1) the number of cells that are "on" can still grow without bound, (2) your implementation is still incomplete on some level if it doesn't support an arbitrary, potentially infinite set of "on" cells in the initial state. Vulture Culture fucked around with this message at 20:20 on Oct 1, 2013 |
# ? Oct 1, 2013 20:16 |
|
Misogynist posted:You're possibly looking at a sparse matrix, which is the data structure typically used to implement spreadsheets. Since your growth is unbounded, though, this will eventually consume all the memory in your system beyond a certain number of iterations. A certain number is astronomically large if you use good algorithms like HashLife (see Golly)
|
# ? Oct 1, 2013 20:57 |
I've got a form that allows somebody to upload a CSV file, and then I want to read it and display it back to them so they can enter some additional information about what is in each column. What sorts of things do I need to be concerned about for validating the file and displaying it back to them? I was looking at csvvalidator but it seems to be more geared to already knowing the structure of the CSV, which I will not know. Also looked at python-magic but the first random CSV I tried it on came back as assembler source, UTF-8 Unicode text, so that didn't seem like the way to go. So should I just not do any validation before loading it up with unicodecsv? I was just gonna make the assumption that it's UTF-8 encoded, reliably detecting the encoding seems like a big pain in the rear end.
|
|
# ? Oct 1, 2013 22:36 |
|
What things do you want to validate? As far as UTF-8 checking goes, you can check if something is valid UTF-8 but that doesn't tell you if it's gobbledy-gook or not.
|
# ? Oct 1, 2013 23:00 |
|
I just moved over to Python 3 and all my stuff is working, except that the interactive mode in PyScripter is broken. I can't access things inside of list comprehensions when debugging:code:
|
# ? Oct 1, 2013 23:03 |
|
Dren posted:pypy words I just quickly threw together a pyglet script while at work. You can import pyglet from pypy. I've never used pyglet before so beware, but this works and flies w/ pypy. https://gist.github.com/thismachinechills/6785816 edit: im almost positive the x/y axes are all hosed edit edit: theres a distinct lack of these guys: https://upload.wikimedia.org/wikipedia/commons/9/95/Game_of_life_blinker.gif in the pyglet version, where the pygame one generates all the oscillators. Just looking at the table on wikipedia, it seems pyglet version lacks all period 2 oscillators. I'm all GoL'd out to care though. it's probably the increased framerate also import numpypy salisbury shake fucked around with this message at 02:20 on Oct 2, 2013 |
# ? Oct 1, 2013 23:04 |
|
salisbury shake posted:I just quickly threw together a pyglet script while at work. You can import pyglet from pypy. I've never used pyglet before so beware, but this works and flies w/ pypy. Your thrown together pyglet implementation seems to run much nicer than your thrown together pygame one, pypy aside. Plus, it's easy to play with the colors in pyglet. Nice! It might be interesting to extend the display to render text in a chosen font as the starting point for the game. Or to have cells with different colors where the colors combine from the surrounding cells when new cells are born. Dunno what you mean about the x/y axes being broken. Your x/y maps perfectly into my row/col.
|
# ? Oct 2, 2013 00:13 |
Dren posted:What things do you want to validate? I dunno, I'm always paranoid about anything user supplied, and trying to prevent them from causing any harm. I suppose all I can do in this case is make sure I can read the whole file with UTF-8 encoding, and let them know if there was a problem.
|
|
# ? Oct 2, 2013 00:21 |
|
Always late to the GoL party. code:
code:
|
# ? Oct 2, 2013 10:23 |
|
Nice. You only have to process the currently alive cells and the gameboard can grow until it is limited by memory. I think you win until someone implements your approach with a gpu accelerated convolution. Using enumerate() to get indices for the string is a nice trick, too.
|
# ? Oct 2, 2013 18:25 |
|
Are there any free, preferably open-source libraries similar to the proprietary Vizard? It's a virtual reality library, where you can (e.g.) create objects from 3D models, then link a camera object to an external input (e.g., motion tracker) to let the user explore a virtual space. It's very simple to use, but also very expensive (I'd be looking at $4k for a single-use academic license).
SurgicalOntologist fucked around with this message at 19:00 on Oct 2, 2013 |
# ? Oct 2, 2013 18:57 |
|
While we're posting python implementations of games, here's the Countdown numbers round game I started yesterday evening. It's the first real application I've written in python outside of work. https://github.com/sharktamer/numbersround.py It has almost all the rules implemented. One I've thought of just now that I know I missed is not being able to use anything other than integers in your solution, but I haven't thought of how I would implement that. It works perfectly for all cases I have tried. If you lot could try it, break it and poo poo all over the rubbish code, that would be great. If any suggested changes were made as pull requests, that would be cool, just because I haven't seen that done before. Also, some kind of countdown that would interrupt the user if they haven't answered would be nice, but I have no idea how I'd do that in python given its concurrency issues. sharktamer fucked around with this message at 22:46 on Oct 2, 2013 |
# ? Oct 2, 2013 22:37 |
|
|
# ? May 9, 2024 03:57 |
|
I did a Words and Numbers Countdown game in Java for an Android app. If you're looking to expand your app, try implementing a "Rachel Riley" to explain the solution if the player misses it.
|
# ? Oct 2, 2013 22:59 |