|
I don't have any real formal background in math either, so it's entirely possible that your idea will work. It seemed like the wrong approach to me, because you aren't interested in finding the shortest path. Even if you select a random adjacent number, it will still take you the exact same number of steps to get down the pyramid. But now that I re-read your answer, I think I see your idea: you want the number in the pyramid to represent the distance. Bigger numbers are "closer", so you look for the "shortest" path in that sense. That seems workable (but then see my first sentence).
|
# ? Nov 11, 2015 02:51 |
|
|
# ? Apr 18, 2024 11:45 |
|
Grain of salt cause I only know this from a Coursera algorithms class that just covered the topic this week, but yeah, I think he's looking for the shortest path in a weighted directed acyclic graph. Djikstra's algorithm isn't wrong, but if since we can stipulate that it's acyclic there's an easier solution based on topological sorting. e: again, I just barely understand this stuff, but I'm guessing the key might be that you can omit the actual work of doing the topological sort since the graph is structured the way it is? KICK BAMA KICK fucked around with this message at 04:47 on Nov 11, 2015 |
# ? Nov 11, 2015 04:35 |
|
Fergus Mac Roich posted:Yeah... it's still not intuitive to me why this algorithm can't do this(note that my script does model the constraint you mentioned) but I guess I should have read further. There are other internet resources making it clear that this algorithm is just inapplicable to longest path in a DAG, assuming that I'm right that this problem actually can be modeled in that way. I guess I'll come back to this problem one day when I understand graph algorithms better and maybe it'll make more sense. At least I have a solution. Thanks. I think your issue is something to do with this: From looking at this, it's obvious the longest path has to go through both 20s and that 8 Because of the way the numbers fall, that heavy 20 on the left hasn't had its distance set yet, because the 1 above it hasn't been visited. But we've already set both the distances of the other 20's neighbours, including the 8 at the bottom. Because they have the heaviest distances, they're going to get visited next and get removed from the unvisited group. There's barely anything left unvisited, and only now are we hitting that 20 The 20 checks its neighbours and adds its distance to them - the other 20 gets bumped up to 43 (in your implementation - Djikstra wouldn't do this, it only checks unvisited nodes, but it doesn't matter). What it really needs to do is propagate that to its neighbours, so the 8 can be updated to 51. But because the lower 20 has already been visited, it won't change its neighbours again. The last unvisited nodes are calculated, and the highest distance is 43 - which is wrong, and isn't from a node at the bottom of the graph either I think your issue is basically that your graph is one-way - you can only move downwards, which limits the ability of the algorithm to reach out to its adjoining nodes and keep a consistent smallest/biggest distance score. You only get one chance to visit a node, and once it's visited its distance can't be updated (in Djikstra's algorithm anyway - yours updates neighbours whether they're visited or not as far as I can see), but this pyramid has separate, distinct routes into each node since there's no backtracking, so each one needs to be evaluated. With Djikstra it's down to luck whether when you visit a node it has all its incoming route information in place, because you can't go upwards looking for it, if you get me If you're interested, this is how it plays out (I think...) without the 'downwards only' neighbour check, but still looking for the largest route instead of the smallest (red is going up, against the rules) So yeah, it looks like going for the heavier weight works fine, it's just the limitation on the direction you can go that makes it a bad fit (sorry for the megapost, I couldn't see anything wrong at first so I got curious)
|
# ? Nov 11, 2015 15:09 |
|
I didn't check your implementation, but I think Dijkstra's would work if you set up the graph structure correctly (i.e. in the triangle every node has two children in the level below it, except for the final layer which all feeds into a "sink" node that is your target). The solution is going to be dynamic programming of some sort; my first pass would be somethng like: 1. Assign each node in the tree DAG a weight w_n equal to the intial weight supplied 2. Starting at the lowest level and moving up, for each node n in the level, set w_n = w_n + max(w_m for m in children) The number at the top of the node should be the number you want after this process is finished (this might be the same as the topological sorting mentioned earlier, but I'm too lazy / hung over to check)
|
# ? Nov 11, 2015 15:47 |
|
Emacs Headroom posted:I didn't check your implementation, but I think Dijkstra's would work if you set up the graph structure correctly (i.e. in the triangle every node has two children in the level below it, except for the final layer which all feeds into a "sink" node that is your target). I'm not sure if that's topological sorting because I haven't studied it yet(thanks for the heads up to whoever posted it, I am definitely going to read up), but that's actually pretty much the solution I ended up with. baka kaba posted:(sorry for the megapost, I couldn't see anything wrong at first so I got curious) This post is great and I feel like it improved my understanding of the algorithm, so thank you.
|
# ? Nov 11, 2015 21:25 |
|
If not for the downward only constraint the longest path is any of the many possibilities that touch every node. For the downward only version, why wouldn't you just start at the bottom and work back to the top? For the row one up from the bottom, each node is worth its weight plus the greater of the two below it. Assign that as the new weight for the node and repeat for the row above. O(n)
|
# ? Nov 12, 2015 06:23 |
|
Cingulate posted:Ah well, my 3.5/Anaconda/MKL woes continue. ...
|
# ? Nov 12, 2015 11:04 |
|
code:
So it generally works fine if I make a keypress, however if no keypress is made in the time-window the program crashes with an 'IndexError: list index out of range' error. Instead, what I'd like for it to do is 'acc_resp = '1'' if no keypress is detected. But I cannot find the appropriate documentation regarding this. Edit: I feel silly. I solved this one on my own moments after posting this. When I was testing solutions, I kept putting the check for the empty list last in the stack of conditions. It needs to come first. For anyone interested, the solution was: code:
PoizenJam fucked around with this message at 19:00 on Nov 12, 2015 |
# ? Nov 12, 2015 18:39 |
|
How about ...code:
Also yes Psychopy is the worst-documented, and generally worst, project I'm using. Still, so much better than the alternatives.
|
# ? Nov 12, 2015 20:16 |
|
That solution is beautifully elegant. Python is all quite new to me, only other programming experience I've had is Visual Basic.
|
# ? Nov 12, 2015 21:08 |
|
What's the preferred way to interface with DB2 databases? PyDB2 looks pretty out of date.
|
# ? Nov 12, 2015 21:51 |
Good lord I am absolutely in love with TensorFlow. I'm hoping this isn't just the honeymoon phase before everything falls apart, but everything about it feels better engineered and more Python than Theano with no loss of generality. Has anyone else played with it?
|
|
# ? Nov 13, 2015 07:56 |
|
I'll be happy to play with it once this is fixed: https://github.com/tensorflow/tensorflow/issues/1
|
# ? Nov 13, 2015 14:30 |
|
Lysidas posted:I'll be happy to play with it once this is fixed: https://github.com/tensorflow/tensorflow/issues/1 It's funny how many issues end up having to have someone telling everyone to stop posting +1 or whatever. I mean, come on you people are supposed to be developers!
|
# ? Nov 13, 2015 17:07 |
|
Bob Morales posted:What's the preferred way to interface with DB2 databases? PyDB2 looks pretty out of date. SQLAlchemy and https://github.com/ibmdb/python-ibmdb
|
# ? Nov 16, 2015 15:04 |
|
Is there a way to search all pip libraries ordered by most popular? Right now I'm just trying to find which unit testing library is the best for flask, but with other languages I like to browse the most downloaded to see what groupthink has deemed the most useful packages.
|
# ? Nov 17, 2015 15:36 |
|
obstipator posted:Is there a way to search all pip libraries ordered by most popular? Right now I'm just trying to find which unit testing library is the best for flask, but with other languages I like to browse the most downloaded to see what groupthink has deemed the most useful packages. http://pypi-ranking.info/search/test/
|
# ? Nov 18, 2015 00:17 |
|
Sweeet, thanks!
|
# ? Nov 18, 2015 03:42 |
|
I have a terribly inefficient Pandas loop. Is there any way to optimize this? I have a range of long-ish data frames. They look like this: code:
I'm using this for loop to assign IDs: code:
|
# ? Nov 20, 2015 21:34 |
|
There may be a more direct way, but this is the first alternative that comes to mind:Python code:
SurgicalOntologist fucked around with this message at 23:29 on Nov 20, 2015 |
# ? Nov 20, 2015 23:26 |
|
Consider using numpy for calculations after reading the csv; pandas is orders of magnitude slower.
|
# ? Nov 20, 2015 23:55 |
|
SurgicalOntologist posted:There may be a more direct way, but this is the first alternative that comes to mind: Dominoes posted:Consider using numpy for calculations after reading the csv; pandas is orders of magnitude slower.
|
# ? Nov 21, 2015 01:54 |
|
Dominoes posted:Consider using numpy for calculations after reading the csv; pandas is orders of magnitude slower. Numeric columns in pandas are stored as numpy arrays.
|
# ? Nov 21, 2015 02:38 |
|
The indexing is slower though. There is a tradeoff for the convenience. In Cingulate's case, we sped up the operation by indexing only once with a boolean array instead of performing a lookup for every row. Perhaps further speed up could be made by doing all the indexing with numpy instead of pandas but I doubt it is necessary here.
|
# ? Nov 21, 2015 03:34 |
|
I thought that was some fairly readable and elegant code myself.
|
# ? Nov 21, 2015 04:34 |
|
I'm researching how to (ab?)use 3.5's asyncio coroutines for complex event processing but I'm having trouble putting it all together. Pre "async" & "await", I had a half cocked idea of using the coroutine pattern from generators in place of a state machine. The primary mechanism was having multiple value = (yield)/generator .send() entry-points to my generator function. E.g. code:
|
# ? Nov 24, 2015 20:19 |
|
Reposting this here because it might be of interest to those who also believe Python is the language of the master race, and javascript on mobile devices needs to die:code:
I'll let you all know more when I finish, but my gently caress javascript quest is heading towards glory right now. edit: BAM code:
Remaining tasks: 1) Scour the zip etc for dylibs or .so files to make sure I'm not being apple violating., 2) If there are any, modify my build chain to statically link them, or if they look apple violating , remove them all together. 3) Integrate this all into QT Designers tool chain. 4) Party. Hard. None of this is made easier by the fact that QT's brand of C++ is completely perplexing, but I'm getting there. duck monster fucked around with this message at 13:43 on Nov 25, 2015 |
# ? Nov 25, 2015 13:39 |
|
duck monster posted:Reposting this here because it might be of interest to those who also believe Python is the language of the master race, and javascript on mobile devices needs to die: I'm intrigued, please tell me more.
|
# ? Nov 25, 2015 14:38 |
|
Its basically importing pyotherside which is a QT binding to python that works with QT5 , and hence works on mobile devices, and isnt PyQt (GPL or $$$$$). The basic difference is, PyQt hosts QT in a python program, pyotherside hosts python in a QML program. There where Android ports and a port to "SailfishOS", whatever that is. But no IOS So I've been hacking away trying to get it to work on the iphone. I'm basically at the "Hello world" stage of it passing unit tests. Now its just a case of getting it to work with QT Designer projects. Because gently caress javascript. This is a project fueled by hate. (I've spent the last month staring into the abyss of Angular.JS gently caress.that.poo poo its time for python on the telephone) duck monster fucked around with this message at 14:58 on Nov 25, 2015 |
# ? Nov 25, 2015 14:53 |
|
Could this also be made to run on Android with NDK? You could have a neat cross-platform kit if you got that figured out, but just getting it working on iOS would be plenty cool all on its own.
|
# ? Nov 25, 2015 15:11 |
|
Munkeymon posted:Could this also be made to run on Android with NDK? You could have a neat cross-platform kit if you got that figured out, but just getting it working on iOS would be plenty cool all on its own. I believe it already runs on Android.
|
# ? Nov 25, 2015 17:01 |
|
duck monster posted:I believe it already runs on Android. Ah, so it does. Not sure why that didn't come up when I googled earlier. E: google auto-corrects pyotherside to otherside haha thanks goog Munkeymon fucked around with this message at 18:53 on Nov 25, 2015 |
# ? Nov 25, 2015 17:52 |
|
If you were looking at Angular, its no surprise it drove you to run away from JS. Angular is not very good. Well, I take that back, its better than most of what came before it (putting aside Angular's atrocious documentation...both official and unofficial. It's amazing to me how bad the situation is with Angular and documentation and best practices.), but there's (IMO) much better alternatives available nowadays like React+redux. I think Suspicious Dish first told me this, and I now agree with him: javascript is very similar to python.
|
# ? Nov 25, 2015 18:04 |
|
Thermopyle posted:I think Suspicious Dish first told me this, and I now agree with him: javascript is very similar to python. And becoming more and more so with all the new features they're adding.
|
# ? Nov 25, 2015 18:54 |
|
Yeah. We were using Mozilla's "JavaScript 2.0" back in 2008 for writing desktop applications, and even back then, the simple additions of let and destructuring assignment made me feel a lot more at home as a former Python guy. Traceur sort of happened but Google never pushed it, and then Node.js, then Browserify, then Babel, then Webpack happened. I've really been enjoying the Babel / Webpack experience, and I've looked into porting Xplain to it as a trial run. There's still plenty of whacko in JavaScript, like eval, but it's isolated enough not to matter.
|
# ? Nov 25, 2015 20:45 |
|
duck monster posted:Because gently caress javascript. This is a project fueled by hate. bless you, bless you.
|
# ? Nov 25, 2015 21:42 |
|
My project partner's turning out to be either a lazy sack of poo poo or in way over his head in terms of time management, so I'm having to work around that. I have a Python program that calls a jar file which spits some stuff back out. It would be nice for it to just spit out one number representing what we're interested in, but that's what my partner hasn't done for two or three weeks. So, I figure I can get around it by counting the lines in the output, since that'll roughly correlate to what we want. However, I want to stop counting newline characters when Python sees a "=" in the output. Is there a neat way to do that?
|
# ? Nov 26, 2015 13:07 |
|
hooah posted:My project partner's turning out to be either a lazy sack of poo poo or in way over his head in terms of time management, so I'm having to work around that. I have a Python program that calls a jar file which spits some stuff back out. It would be nice for it to just spit out one number representing what we're interested in, but that's what my partner hasn't done for two or three weeks. So, I figure I can get around it by counting the lines in the output, since that'll roughly correlate to what we want. However, I want to stop counting newline characters when Python sees a "=" in the output. Is there a neat way to do that? input.split("=")[0].count("\n")
|
# ? Nov 26, 2015 13:42 |
|
Ooh, yes, exactly like that, thanks!
|
# ? Nov 26, 2015 14:24 |
|
|
# ? Apr 18, 2024 11:45 |
|
Or this should also work: input[:input.index("=")].count("\n") (.index finds the first occurrence) I guess if these files are very long or you call that very often, you'd choose a method that doesn't take the entire file. But this should work for now.
|
# ? Nov 26, 2015 14:28 |