|
You know, I'm not sure exactly why I get the results I do, but:code:
code:
code:
|
# ? Jun 3, 2008 22:45 |
|
|
# ? May 14, 2024 02:38 |
|
JoeNotCharles posted:
This is splitting on all whitespace, and calling echo for every word. JoeNotCharles posted:
This isn't splitting at all, and calling echo exactly once, with the entire output of foobar. JoeNotCharles posted:
This isn't splitting at all, and calling echo exactly once, with the entire output of foobar. Because the variable isn't quoted, it is split into multiple words on whitespace, which are then all passed to echo as separate arguments. Echo doesn't know how its arguments were split, so it assumes a single space. This should work: code:
|
# ? Jun 3, 2008 22:59 |
|
JoeNotCharles: Yup, I was hung up trying the same things and still not getting the behavior I wanted (as ShoulderDaemon pointed out: you're results are deceiving, none of them work). ShoulderDaemon: I was hoping there was a simpler solution but I was kinda expecting that the solution would involve changing the delimiter somehow. Didn't know how to do that tho, but now I do
|
# ? Jun 3, 2008 23:26 |
|
Lexical Unit posted:JoeNotCharles: Using the shell builtin 'read' may be a more straightforward way to iterate over line-based output code:
|
# ? Jun 4, 2008 00:35 |
|
covener posted:Using the shell builtin 'read' may be a more straightforward way to iterate over line-based output The only gotcha with that is it opens a subshell, so you can't set environment variables within the loop and have them propagate outside it unless you jump through some extra hoops. Depending on what kind of processing he's doing inside the loop, that may or may not matter.
|
# ? Jun 4, 2008 01:43 |
|
covener posted:Using the shell builtin 'read' may be a more straightforward way to iterate over line-based output
|
# ? Jun 4, 2008 14:50 |
|
A Scheme question here... (note that this is using DrScheme, which I think replaces some of the more weird definitions like 'car' and 'cdr' with the more clear 'first' and 'rest'. If something isn't clear, let me know) I was assigned to write a Scheme function (calc-running-sums L) which evaluates to a list that is the running-sums of the list L. For example, (calc-running-sums '(1 2 3)) gives '(1 3 6). My solution is, in my view, not very elegant. It's something that came to me early on when I approached the problem, but which I put on the backburner because of its inelegance. I spent a good amount of time trying to find a more elegant solution, but I haven't been able to. My solution uses several helper functions which I've also included. code:
|
# ? Jun 6, 2008 09:47 |
|
Oops, double post.
Meganiuma fucked around with this message at 14:54 on Jun 6, 2008 |
# ? Jun 6, 2008 14:52 |
|
My scheme is very rusty, but here's a shorter solution. There might be a way to do this without all the reversing i've done, but I can't think how off the top of my head.(This is essentially the same as your solution, but just using the built-in fold-right)code:
Meganiuma fucked around with this message at 15:04 on Jun 6, 2008 |
# ? Jun 6, 2008 14:54 |
|
You can do it without a reverse and with a single pass through the list by carrying an accumulator with the previous element's sum.code:
|
# ? Jun 6, 2008 19:35 |
|
ShoulderDaemon posted:You can do it without a reverse and with a single pass through the list by carrying an accumulator with the previous element's sum. of course! this was actually my original plan for this but I guess it got retarded down into my crappy solution. Thanks. Meganiuma posted:another good solution
|
# ? Jun 6, 2008 20:30 |
|
Is trying to learn Objective C (for use w/ XCode and Cocoa) a terrible idea if I don't know anything about the C language? I've heard people recommend it, and others say you're doing yourself a big disservice by not learning C first. I'm trying to learn an OOP language this summer, and the only programming experience I have lies in a bit of Pascal, Perl, and PHP.
|
# ? Jun 7, 2008 19:03 |
|
myownsavior posted:Is trying to learn Objective C (for use w/ XCode and Cocoa) a terrible idea if I don't know anything about the C language? I'd say you'll probably find it easier without knowing C, because you won't be bouncing off the Smalltalk-isms saying, "But, but, that's nothing like C!"
|
# ? Jun 7, 2008 19:58 |
|
This isn't a programming question per se - more of a windows question - but I think it's appropriate: Say I have an application (a computer game), and I want to associate my save files (.sav) with the application, so that I can just double-click on them and the game will start up and load that save automatically. Now, say also that my game has a whole bunch of external files it relies on - textures, sounds, whatever. Suppose that these files are located in subdirectories, relative to the game directory (e.g. C:\MyGame\Textures, C:\MyGame\Sounds, etc.) My problem is this: When you run the game through file-association (that is, by double-clicking on a .sav file) or by dragging and dropping the .sav file onto the executable, the application uses the location of .sav file, not the .exe as the working directory. This creates problems if you run the .sav from, say, C:\MySaveFile and then the application goes looking for C:\MySaveFile\Textures. Has anyone worked with this problem before? Can anyone think of a way around it? So far my best guess would be to write the location of the .exe to the registry, and then read and use that value as the working directory when the program starts up. But I'm hoping there's an easier way...
|
# ? Jun 9, 2008 06:11 |
|
Cody Watts posted:Can anyone think of a way around it?
|
# ? Jun 9, 2008 12:42 |
|
Cody Watts posted:Has anyone worked with this problem before? Can anyone think of a way around it? So far my best guess would be to write the location of the .exe to the registry, and then read and use that value as the working directory when the program starts up. But I'm hoping there's an easier way... The standard way on Unix is to look at argv[0], which has the full path to the executable. I'm not sure if Windows does the same or just has the filename, but it's work a try. (Of course, on Linux this is usually pretty useless because all the executables are together in /usr/bin.) I think it's pretty standard to have the installer write the locations of data files to the registry, though. Old CD-ROM games used to do this because they'd install some data files and leave others on the CD - I remember tricking them into doing full installs by copying everything off the CD and then changing the paths in the registry.
|
# ? Jun 9, 2008 15:31 |
|
JoeNotCharles posted:The standard way on Unix is to look at argv[0], which has the full path to the executable. code:
|
# ? Jun 9, 2008 15:50 |
|
Mustach posted:Not necessarily. I put an argv-printing program in a directory in my path and get whatever string that I call the program as: This is (and always has been) the way it will/should work.
|
# ? Jun 9, 2008 15:57 |
|
Mustach posted:Not necessarily. I put an argv-printing program in a directory in my path and get whatever string that I call the program as: Uh, you're right, I don't know what I was thinking. This is how things like busybox work - you symlink the same executable to a bunch of different names, and then check which function of the program to run by checking argv[0] to see which name was used to invoke it. It still might work in this case, though, because it's the OS filling in the file path so I'd assume it'd use the absolute path.
|
# ? Jun 9, 2008 16:04 |
|
Cody Watts posted:Has anyone worked with this problem before? Can anyone think of a way around it? So far my best guess would be to write the location of the .exe to the registry, and then read and use that value as the working directory when the program starts up. But I'm hoping there's an easier way... You want to use GetModuleFileNameW() to find the canonical path to your running executable, then work your way backward to some directory of interest.
|
# ? Jun 9, 2008 17:45 |
|
Mustach posted:I'm pretty sure the Windows API has a call to set the current working directory. I don't remember what it's called, though. JoeNotCharles posted:It still might work in this case, though, because it's the OS filling in the file path so I'd assume it'd use the absolute path. covener posted:You want to use GetModuleFileNameW() to find the canonical path to your running executable, then work your way backward to some directory of interest. Thanks for your help, guys! Between the three of you, I managed to get it working.
|
# ? Jun 9, 2008 17:49 |
|
Apologies if this is a huge wall of words, but I figure worst case is no one reads or replies to it, best case I get some help. I've been trying to change a genetic algorithm which is normally done in serial to run in parallel. Because I'm using Python and just read a tiny bit about functional programming I decided it would be easier for me to get rid of internal states as much as possible and just use different immutable dealies and functions, as it might be easier to understand where the bugs were, and how to parallelize it. Unlike regular approaches where you take a "population" and replace it with a new one of the same size (i.e. a generation), this algorithm says you have to take a population and perform operations where you remove one and add a new one at the same time. This it improves the search because the "frontier" gets updated every time something is evaluated, rather than every time the entire population is evaluated. The algorithm looks like this: code:
The problem is I don't know how to combine the different populations we get from the different processors, after its done the parallel part. I want it to kind of fork and merge the improvements without losing anything. Since the third part of the inner loop is random (i.e. not a pure function) each processor should return a different population after the parallel part is done. So the problem is I have these resulting sets with some elements in common and some disjoint, and I want to merge them into a new unified set of the same size. This single unified set has somehow got to losslessly incorporates all of the changes to the population experienced by the seperate processors. I can compare a resulting set to the prior unified set to see how many elements are disjoint. If there is an element that is disjoint between either, that means it is either a loser who was removed, or a child who was an improvement. What do I do if population A and population B both have new improvements but they both removed the same loser? Population C can't have both improvements because its only got the one loser to remove and then theres no more space left. Has anyone done anything remotely similar in the past?
|
# ? Jun 10, 2008 10:44 |
|
tripwire posted:I've been trying to change a genetic algorithm which is normally done in serial to run in parallel. Python isn't really designed for fast number crunching.
|
# ? Jun 10, 2008 21:52 |
|
Scaevolus posted:Are you trying to optimize something in Python? Maybe you should look into Pyrex or some similar tool before trying to parallelize it. The NumPy people disagree. (No, wait, they agree, but they fixed it by extending the language with native modules.) Anyway, make sure you're using NumPy for your genetic algorithms and such because it'll fix many performance problems right off the bat and contain infrastructure for fixing the rest.
|
# ? Jun 10, 2008 23:56 |
|
Tripwire what you want to do is divide your population into n parts where n is the number of processes you want to run in parallel. Each child process finds the worst and best member of their segment of the population and returns the results. Then the parent thread makes n comparisons from the results and finds the best/worst of the entire population and generates the new offspring. This is probably the easiest way to distribute the work. I know jack poo poo about python, so your efficiency problems might be solved by the other recommendations.
|
# ? Jun 11, 2008 04:28 |
|
Thanks for the responses guys. To clarify, I'm not really asking how to optimize my code in python, it was more of an algorithm question. As it is, the vast majority of cpu time is spent on the evaluation step which isn't done in python. My focus isn't optimizing the algorithm so much as foremost figuring out how to reimagine it in parallel, and secondly making it clear, understandable and useful for exploring search dynamics. When I'm satisfied that those objectives are complete I'll switch in numpy and start considering dropping in either c++ extensions or refactoring in pyrex. Forget I ever mentioned python, what I'm asking is for an appropriate way to merge the n disparate sets into a single unified one. MEAT TREAT: You make a useful suggestion, but unfortunately I cannot distribute the work in that way; ultimately the function I want to parallelize has to receive the complete population for it work, the search dynamics would not function properly if it only received disjoint subsections. Imagine I have a function called "tick". It takes a population object, with at least 1 member that is unevaluated. The unevaluated is/are assigned a score, and the lowest score in the population is removed. Finally a new unevaluated dude is appended. The resulting population object is returned. The part of my algorithm I am trying to make parallel will look like this: code:
The hosed up thing is though, knowing which people got removed is almost as important as knowing who is new; if someone gets removed thats like the algorithm saying "this guy is not going to be a stepping stone to anything useful, so lets not waste our time keeping him around". So I have to kind of figure out a principled way of choosing who to include in the new population.
|
# ? Jun 11, 2008 19:16 |
|
tripwire posted:genetic algorithms stuff
|
# ? Jun 11, 2008 19:46 |
|
_aaron posted:This doesn't really answer your question, but I'm curious. From your explanation, it seems like what you want to do is evaluate the same population on multiple processors, and each evaluation has the potential to select a different "loser." If that's the case, why not just evaluate it once and choose however many random losers you want? I may be missing something fundamental here, so go easy on me if I sound like a retard. Since removing a guy effectively biases the search from going in that direction, enforcing parallel ticks FORCES search to go in many directions at once (this is a really really good thing). In order to benefit the most from that enforced diversity though, I have to figure out how to take the diverse results of the consecutive concurrent ticks and merge them nondestructively. Theres some properties about the resulting populations that might make this easier; for example.. Lets say I have reference_pop, and I do a bunch of ticks on 3 different cpus, ending up with result1, result2, result3. If result1 has 4 new guys, that means compared to reference_pop its also MISSING 4 guys; however it might be missing a different set of people than result2 is; or they both could have removed exactly the same guys; or they both could have removed SOME of the same guys, but other different ones. My unified population at the end somehow has to have the same number of people, so I even if I remove everyone who was removed in any of the results I still won't have enough room for all the new guys who replaced them (between the different resulting populations, some of the removed dudes overlap, but none of the new guys should overlap). tripwire fucked around with this message at 23:15 on Jun 11, 2008 |
# ? Jun 11, 2008 19:58 |
|
Can anyone tell me how to use Sed to remove all text in a file that is not an IP address? For example: Name: somesite.com Address: 39.100.204.200 Name: somesite.com Address: 202.110.30.50 should turn into: 39.100.204.200 202.110.30.50
|
# ? Jun 11, 2008 20:03 |
|
checkeredshawn posted:Can anyone tell me how to use Sed to remove all text in a file that is not an IP address? probably cleaner ways to do it but sed 's/[a-Z]*[:] //' | sed /[a-Z]/d To clarify: 's/[a-Z]*[:] //' will substitute every occurence any number of alphabetic characters (including where there is none) followed by a colon and a space with nothing. The second sed command hides lines with any remaining alphabetic characters. tripwire fucked around with this message at 20:32 on Jun 11, 2008 |
# ? Jun 11, 2008 20:29 |
|
If the file is always in that format it sounds more like a job for awk than sed, for example: awk '/^Address/ { print $2 }' file
|
# ? Jun 11, 2008 20:43 |
|
So this a Fortran 95 question. I've got a data file with about 4 columns of 50000 entries consisting of numbers each. I want my code to scan through lines 30000 - 35000 of column 4 and find the highest entry there. How exactly would I go about doing this? Sorry if this is a basic question, but I'm pretty new to this coding business.
|
# ? Jun 11, 2008 23:05 |
|
I asked this in the Flash Questions thread but it's not really Flash-specific. Does anyone have experience writing an FTP client? I'm trying to create a proof-of-concept in actionscript that uses binary sockets to connect to the server. I can get it connected and logged in, but I'm having problems with commands like LIST and PUT. Research tells me it has something to do with being in PASSIVE mode, or that FTP uses one connection for control and another for data. Can anyone shed some light on this for me, please?
|
# ? Jun 11, 2008 23:24 |
|
Montalvo posted:So this a Fortran 95 question. I've got a data file with about 4 columns of 50000 entries consisting of numbers each. I want my code to scan through lines 30000 - 35000 of column 4 and find the highest entry there. How exactly would I go about doing this? When you open the file you need to specify the record length. It has been a while since I've done it, so double check my syntax with a reference, but basically open(LUN, file='filename', recl=rl, access=direct) Then to read read(LUN, rec=##) number1 number2 number3 number4 Where the rl is the line length in bytes (which must be the same for everyline otherwise this won't work). And ## is the record number you want to read (ie line number). And LUN is the LUN you want to use for your file (don't forget to close it at the end). Then to find a max, simply read each record 30k - 35k and do a simple check to see if the just read value exceeds your current max (held in a different variable). If is is too hand-wavy, let me know and I can code something up this weekend. edit: If the line lengths aren't consistent you'll have to resort to a stupid styled loop that reads every line, and skips to the next line when you are below 30k and bails out of the loop at 35k.
|
# ? Jun 11, 2008 23:26 |
|
Yes, unfortunately the lines do not have the same length (actually, on second thought, they might do -- I'll have to check tomorrow, when I get to the computer with the data on it). What you explained is quite new to me, but I recognise some of the commands and will look them up on my Fortran book at some point. The last time I did something like this was very convoluted: I established a loop that looked at each value of the data and compared it to the previous one -- if the new value was bigger, it added a counter to an array. Whenever there was a discontinuity in the array's counters, it marked the value as a maximum. It worked, but I'm afraid it might take way too long for this program, since it needs to look at several data files with 50000 entries each. If knowing the context of what I'm doing helps, I'm trying to find the maximal points in a set of sinusoidal graphs with varying amplitudes.
|
# ? Jun 12, 2008 00:26 |
|
delete me
Lamb-Blaster 4000 fucked around with this message at 04:49 on Jun 12, 2008 |
# ? Jun 12, 2008 03:37 |
|
nolen posted:I asked this in the Flash Questions thread but it's not really Flash-specific. Anyone?
|
# ? Jun 12, 2008 05:49 |
|
ftp passive mode is just that- port 21 is for connection then it picks a random port within a specified range for data, or vice versa, I only remember that much from setting up an ftp server at home. by setting up I mean installing filezilla. check out http://en.wikipedia.org/wiki/File_Transfer_Protocol for a low down on some ideas about why your implementation may not be working. I know that I had a lot of problems with certain ftp clients getting angry about passive and no passive. This is probably basic stuff- but make sure if you're in passive, that the port range for passive is open and forwarded as well as port 21
|
# ? Jun 12, 2008 06:01 |
|
Dog Named Duke posted:ftp passive mode is just that- port 21 is for connection then it picks a random port within a specified range for data, or vice versa, I only remember that much from setting up an ftp server at home. Yeah, I can set the mode to passive then parse the IP and port that it returns. I guess I'm just confused about if I'm supposed to open another socket using that IP and port combination and then send my LIST and whatever commands over that socket instead of the control socket that's originally created. If so, my way of doing it isn't working.
|
# ? Jun 12, 2008 07:02 |
|
|
# ? May 14, 2024 02:38 |
|
Montalvo posted:So this a Fortran 95 question. I've got a data file with about 4 columns of 50000 entries consisting of numbers each. I want my code to scan through lines 30000 - 35000 of column 4 and find the highest entry there. How exactly would I go about doing this? Hang on; can't I just feed the values into an array and then use the maxval(array) command? Edit: this seems to have worked. I get a data set out of the code, but I'm not sure if it shows the right thing. Either way, it's something! Montalvo fucked around with this message at 12:27 on Jun 12, 2008 |
# ? Jun 12, 2008 10:47 |