Setting out to learn Python. Anyone wanna join?

boogle wrote:

I have never felt more secure in my ability to find employment than listening to you guys complain about maths.

It seems to me that software is a pretty big space now, and there's room for all of us. A lot of software problems are mathematical, and a lot of them aren't.

I'm a systems guy. I get paid to write software every day, in a bunch of languages, but the most complex mathematical function I ever apply is probably 'mean'. I don't believe that software engineers need to be mathematicians, but I'm very glad that there are mathematical software engineers, and I'd like to thank you collectively for matplotlib, real-time FFT libraries, and every 3D game I've ever played.

Given a solid previous course and a tough, but not unfair first week, I'm willing to suffer this one and see how it turns out. I should be able to start the mini project for the week tomorrow and I'll share my experiences.

Malor wrote:

edit: and note, I've gotten perfect scores on everything so far. I'm not an idiot, I just don't have the background to do what they're asking.

No one who has spent any time in the build a pc thread would think you're an idiot.

I managed to open the homework with some free time tonight and have been cracking my head against problem 1 for a while. The wording on the explanations is definitely very poor. I kept rereading trying to figure out where I went wrong and finally checked the forums only to realize I had been solving the wrong problem the whole time. Was actually rather fun to solve once I figured out what the hell I was doing. I've always been frustrated with the whole idea of professors for this kind of undergrad-level work. People who are good at something are not necessarily good at teaching it (in fact the inverse is often the case).

Well the first phase of week 1 mini project is pretty rote, but satisfying. I've got bugs in phase 2 that are tricky.

In one of the videos they showed a version of CodeSkulptor capable of proper debugging and inspecting variables and stepping through code. Do we have access to that?

Yeah, that's called Viz Mode, and you can get to it here:

http://www.codeskulptor.org/viz/inde...

You can't save your work in Viz Mode, however, so you have to copy and paste from another window, run it, and then make changes back in the first window. It's so awkward that I never found much use for it.

Wow yeah that's hard to use, but I did find a bug with it. I think its showing me I need to export this stuff and run it in PyCharm

I've actually been doing everything in notepad++ and using idle to test and just pasting it into codeskulptor when I need it. I started off with python on the learn python the hard way site so it's just what I'm used to. I want to try to use some other environments like maybe learning to use vim or ipython but I'm focused on just learning the language for now so doing things the long way I figure is actually keeping me on my toes for now.

So I finished the homework this morning and got an 80. Thought I'd post my thought processes and maybe ask some of you math people for some pointers on the stuff I didn't quite get or that I'm thinking about incorrectly.

So I've actually been thinking about this as an RTS, Warcraft 2 specifically because it's the only one I remember well enough to bring to mind easily. If you're not aware, in that game building a lumber mill would increase the amount of lumber per harvest (from 100 to 125 IIRC).

Q1: Write a function
Fairly straightforward (once you understand what the damn thing is asking). If you're having trouble you probably just aren't understanding what they want. I'm willing to clarify if anyone has a question.

Q2: Which value
Just modified the simpleplot code to plot the 4 lines, easy enough. The question is basically asking: what will lead to more lumber, faster: when lumber mills cost 0, .5, 1, or 2 gold?

Q3: Is it straight? Take the log of current_time and total_resources_generated and see if it plots as a straight line.
Simple enough, just needed to add a variable current_time_log = math.log(current_time), ditto for total_resources_generated and append them instead of the originals.

Q4: Which one?
This one took some doing. It's asking if lumber mills are free, then how much longer will it take before you can buy a new lumber mill after every purchase? For this I went to the old standby of printing variables, specifically within a
for item in range(num_upgrades):
print item, '/', next_upgrade

then set the number of passes to 100 to see patterns. One jumped out:

Spoiler:

0 / 1.0
1 / .5
2 / .333
3 / .25
4 / .2
Them's fractions!

Spoiler for next_upgrade if you want to figure it out yourself:

Spoiler:

next_upgrade = upgrade_cost / resource_gen_rate

Q5: Which function models question 4's answer?
Basically I just plugged in the numbers for each. None of them seemed ideal, but I picked the only one that was close. Turns out I was right because there's apparently this thing. I'm sure there's a fancy math way of doing it, but to model the sum of the answer to 4 I just went brute force and put into IDLE:

Spoiler:
stupidvariable = 0 for item in range(1, 50): stupidvariable += 1.0 / item

and compared it to what I got in the functions they provided.

Q6: The annoying question Malor posted above.

To conclude our analysis of this case, we wish to express total resources generated in terms of time. Examining the output when upgrade_cost_increment == 0, we observe that the total resources after n upgrades is simply n. Based on this observation, we observe that we can easily express the time t as a function of the resources r via t=f(r) where f() was the solution to problem 5. To model the total resources as a function of time, we seek a function g() that relates total resources r to the time t via r=g(t).
Enter g(t) as a math expression. Remember to use the Preview button (as well as the Help link) to make sure that your expression is formatted correctly.

No idea. I entered 'moo' to simulate a cow. I've got it in my head that I should be able to solve this algebraically but have no idea how to do that with functions. I know I need to switch something around. Help, math people?

Q7:

Plotting the output of resources_vs_time() in Log/Log form yields a graph which is nearly a straight line. This observation signals that the function may be a polynomial function. Compute the slope of this line and round it to the nearest integer to estimate the degree of the polynomial.

I think I'm reading this wrong. I entered 1 because why the hell would I round a slope to the nearest integer? It was nearly a straight 45 degree line. Maybe I was supposed to enter what the author's mom screams in the throes of passion or something. Anyway, I've turned on the bat signal for the math people.

Thanks for the answer to question 3 though.

Q8: what sum models the total resources generated after n upgrades?
Did the same thing I did for Q4, but modified the printed variable to what this question asked for. Clear as day when you do so.

Q9: What fancy math crap can you do to current_time that will equal total_resources_generated? (Be sure to set upgrade_cost_increment to 1.0!)
Same thing as for Q8 and Q4, just changed the variables that printed.
I actually recognized this pattern from playing with the answers to question 5. They gave you the answer as a bogus answer to that question.

Q10: First lumber mill costs 1. Every successive Lumber Mill is 15% more expensive. How expensive is the nth?
Pretty sure I made a dumb mistake.

Spoiler:

I entered n + n * 1.15 but I should have entered 1.15 ** n, right math people?

Q11: Which makes more lumber, Q10's solution or Q8's solution?
Had to plug in the solution to Q10 and print it out (was easier than fiddling with the simpleplot stuff they have), but pretty clear when you do it. Check me on this though as there's still lots of room for error:

Spoiler:

To implement Q10's solution in the code, I just changed upgrade_cost += upgrade_cost_increment to upgrade_cost *= 1.15. To make that easier if you're not looking at the code I also built a simple function just to do that in idle so it might be easier to check me there:

def fifteen(number): ret = 1 for item in range(number): ret = ret * 1.15 return ret

Any help with the above questions is appreciated! I'm not worried about the grade, just want to see how I'm doing with this stuff.

2nd mini project down. This ones not bad at all. Felt like practice.

I'm not sure if this belongs here on in the math thread. I did the project euler problem where you have to calculate the number of possible routes from top left to bottom right in a 20 by 20 grid, moving only down and right. I knew there was a mathematical formula that would do this easily, and sure enough, it comes out to 40 factorial / 20 factorial x 20 factorial.

There were some other options on how to calculate this, but the greek was too much for me to decipher.

So anyway, my question is, if there were a 2x2 block in the middle that was impossible to cross, what would the math be? I 'd like to understand this, since it seems like an important concept. There still have to be 40 moves to get there, and 20 right and 20 downs, but there are less possibilities now, since you have the obstruction. Once you get to the obstruction, you can choose either right or down, then you next move is already determined. If you went right, you have to go right again. If down, down again, to get around it. So 40! / 20!20! minus something. Is it 2! 2? Am I close? Way off?

The number of possible routes when a block or blocks is/are untraversable is equal to the total number of routes over the grid minus any routes which traverse the blocked space or spaces.

This week in the Coursera python course was much better overall. Homework was tricky because I've got no idea what any of the formula questions want. All the trouble they went through to teach probabilities in the videos this week was wasted as it's completely unnecessary for the mini-project. I think I prefer it that way in this case.

I'm mostly in this for the mini-projects, so scoring high on this week's was a point of pride. The project is to code an AI to play against you in Tic Tac Toe that never loses by simulating hundreds/thousands of random matches based on the current state of the game and picking the next best move that can lead to a win.

This time around, they provided an extremely minimal template to work from, which made completing the project less about filling in blanks and more about writing a whole module, so it was pretty satisfying.

Have a few hours this afternoon I thought I would dump into the coursera course. I was going over the notes for the practice project and they mentioned the Monty Hall problem, which I had never heard of before. tl;dr:

"Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?"

Since the probability of the original door being correct is still 1/3, the probability the remaining closed door hides the car is 2/3 since the probabilities must sum to one. Thus, the advantageous choice is to always switch.

I cannot make my brain accept this.

Yeah, I've had a few lengthy arguments over it. It works out though.

I unfortunately unenrolled from the class to get a refund. This session is more time demanding and I've got too many summer distractions. I hope they re-offer it soon though as I still want to finish the full course.

I know they're re-offering the first class later in the year so they'll probably be offering them all again in sequence, though you might have to wait a bit. Sorry to see you go.

stupidhaiku wrote:

Sorry to see you go. :(

I really didn't want to drop it as I was looking forward to staying "in phase" with everyone else. Now I'm being held back a year. It looks like I'm still in the class, just not on the paid Signature Track now. I may still try to audit it so that I'm better prepped for the next offering anyway.

It's all those jerks breaking the GWJ Minecraft server. "Summer distractions" indeed.

stupidhaiku, it does take some thinking. I recall one helpful scene from **cough* Numb3rs **cough** that may elucidate, or may make you cringe.

I cannot make my brain accept this.

The big thing about the switch/no-switch is this: Monty has more information than you do. He knows where the car is.

When the game starts, there are goats behind 2 of 3 doors, right? So, whatever you pick, you have a 1/3 chance of being right, and a 2/3 chance of being wrong. You 'own' your door, and a 1/3 chance of winning, and Monty 'owns' the other two doors, and thus he would have a 2/3 chance to win, if he could pick both doors.

So, Monty has either two goats, or a goat and a car. When he does the reveal, he always shows a goat. What he's doing, in other words, is condensing his two doors down to one. If the reveal could ever show a car, then you would immediately lose when that happened, and then switching would be worthless. But he always shows a goat, which means that the remaining door now has a 2/3 chance of having the car.

Switching, in other words, will give you Monty's chance of winning, instead of yours.

Again, it only works because Monty knows where the car is. If his reveal was actually random, then in 1 game out of 3, opening the door would reveal the car, and you would lose. But that never happens, and thus you double your winning odds by switching.

Oh, and on the Coursera course: I went ahead and swallowed my pride, and did that stupid math test that I was completely unqualified to deal with. I managed to pull out an 85, which I consider nearly miraculous.

It's the first points I've lost in either course, and it really pisses me off. I've had a perfect score up to now.

I got a 100 on the project, and struggled with it a little more than I should have... I had a couple of subtle bugs that I just wasn't seeing. I eventually managed to track them down by using other people's test suites. One of my bugs was the assumption that I could only buy one thing per second; it made me structure my fundamental run_clicker loop the wrong way. I ended up going to a while True: loop, and then breaking out of it when appropriate.

In looking at the Top Scores thread, I got what appears to be the 'normal' score that most students get. I could probably do a little better with a more detailed strategy, but, meh, who cares. It's within a couple percent, good enough.

LiquidMantis wrote:
stupidhaiku wrote:

Sorry to see you go. :(

I really didn't want to drop it as I was looking forward to staying "in phase" with everyone else. Now I'm being held back a year.

Don't worry, I'll keep you company
And it should only be six months actually, I count on the next session starting in November.

Wow, this week's project was really easy. I had one little bug in my implementation (a misplaced comma), which I caught with my first tests, and then wham, everything just worked. Perfect score on my first submission. (edit, well, second: I lost 2 points for not having a docstring in my test routine, which I just commented out for the second try.)

I found that 100 trials was fine for making a perfectly credible Tic Tac Toe opponent.

Because the objective in Tic Tac Toe is not to lose, as opposed to actually winning, giving more weight to blocking good opponent moves seems to work well.

Hey, Mantis, from the current notes on the course page:

Third, we are considering offering Principles of Computing again next spring. However, we don't plan to make any final decisions about when the course will be rerun until the first group of students go through the complete specialization and we better understand the overall demand for the specialization.

So they may not do Principles again, and if they do, it won't be until the spring. You may want to just buckle down, and stick with it if you're interested.

Dammit. Thanks for the notice but I haven't turned anything in yet. I guess I could use the late days features to offset some of that.

[Edit] Well, if I get cracking NOW I guess the only thing I'd really be penalized for is not turning in 2048. I did the Wk0 Homework and the Wk1 stuff has a hard deadline of this afternoon so I'm not out of the game, I just probably can't continue my With Distinction goal.

[Edit: The Seconding] Unless I REALLY bust ass: Please don't let a missed deadline discourage you. Each mini project is worth around 8.5% of your total possible points for the class. Each homework is worth around 6%. You need 70% to earn a Statement of Accomplishment. The Statement is on a pass/fail basis; it will not show your percentage. So if I ace everything else I can still get Distinction.

[Edit: MAKE IT STOP!] Okay, got half a cup of coffee in, declared PTO for today, TIME TO CODE! I probably should have been working on this rather than getting caught up in Tomb Raider over the last couple of nights.

Well I had to beat my head on it for a while while waiting for bourbon fuzzies to wear off and coffee to kick in, but I surprised myself with a 100% on that Week 1 math homework. Now to get some food and really buckle down for the mini-project.

[Edit] Well, if I'd actually watched all the videos I probably wouldn't have spent as much time going through the homework. Oops.

Probably a dumb question, but you get a few attempts to submit to the grader, right? I'm still ironing out some strategy issues and thought I might go ahead and get something submitted soon while working to improve.

Yeah, but use the OwlTest page instead. Those don't count, but OwlTest runs the exact same tests that CourseraTest does. Once you're getting a grade you like (or can tolerate), then submit it to CourseraTest, and you should get an identical score.

Note that CourseraTest will not show your result on the master page for your assignment right away. It can take 15 or 20 minutes for the score to show up. If you're real close to the deadline, you could submit 2 or 3 times, just in case. You get the highest score you submitted before the deadline.

Don't forget to apply your late days before submitting.

I also had good luck with this test suite:

import user34_GhjnBEJSmI_10 as test_suite test_suite.run_simulate_clicker_tests(simulate_clicker,strategy_none,strategy_cursor) test_suite.run_clicker_state_tests(ClickerState)

Just make sure to comment that out before you submit to the machine graders. They won't import the tests properly, and will throw an error.

I found that I couldn't effectively use simpletest on this week's assignment (Tic Tac Toe) because I had to be passed an object and so much of the results depend on some random steps. I basically tested the old fashioned way (which I've gotten good at) by putting print commands for a bunch of variables before and after assignment. Should I have gone through manually setting up a test object, forcing results from the random elements and writing a simpletest suite for it? Is there a better way?

I just eyeballed it, myself, first running it over and over, having it generate individual random boards, making sure they came out with the right number of Xs and Os. Then I tested scoring for one board at a time, manually making sure the numbers came out right.

Once that was running, I started generating 20 boards at a time, and scoring the whole batch, and then making sure the accumulated score numbers looked sensible. (they did).

Then I tested my move picker a little bit, and when that looked good, went ahead and OwlTested it.

This one really came together easy for me. I think it was less than two hours from first Codeskulptor open to final submission, and my testing was never very involved. The algorithms were so simple that it was very easy to see, just with the old Mark 1 Eyeball, if they were producing bad results.

Oh, and Mantis: the 6PM hard cutoff may not be absolute. I think you've got at least a little slop there. I don't know how much, but I think you'll get at least an extra fifteen minutes.

Well I JUST submitted, thinking I was at the wire. I'm at 90% right now, stupid Best strategy is kicking my ass.