This is probably my last post on this sLOG. Maybe if I remember I'll update once more after the exam or when I receive my final mark.
Supposedly this week's topic is on hash tables. I must admit that because it's near final seasons I started blanking out a bit during the lectures. It's quite horrible since I hadn't encountered hash tables before. *sigh*
Anyways. Hash tables are a much more efficient data structure as compared to lists and whatnot. It makes up the basis for sets and dictionaries. They have a special run time efficiency for fetching the data inside them -- O(1). Very ideal. How? Similar to how a list can retrieve data almost immediately when given a specific index, Hash Tables put a specific index (hashes?) the objects that are put in them. For example, a simple hashing function is to convert the data into some sort of integer and use the int%capacity. The data will be essentially assigned an unique id. Upon on retrieval, the data will use its specific "key" to find the corresponding storage position in the hash table.
So of course, two items that may have the same key must be considered -- there are usually two methods to deal with this:
1. Probing: exploring in a systematic way to find the next empty position such that eventually all positions of the hash table will be visited once if there were no empty spots.
2. Chaining: keep a small list at each "bucket" of the hash table - append the conflicting elements in the small list and retrieve from it.
Our course focuses more on chaining and uses it in the code, although it was said during class that both methods work well for hash tables.
Thursday, April 7, 2016
Wednesday, March 30, 2016
Entry 10: Week 11: Reminiscence
So the course is finally about to be over. I am both sad and happy at the same time -- sad that I will soon be departing, but happy that the time I spent here were put to good use. Although this isn't the last post on the sLOG, but the feeling of closure is slowly growing upon me.
This week's designated topic was to revisit one of my posts and discuss whether my reviews or opinions had changed. I would like to head back into last week's entry regarding assignment 2, term test 2, and efficiency and run time. However, I'd like to focus on the last topic that I wanted to avoid -- Efficiency and Run Time. In even earlier entries (read: Entry 2: Week 4), I had already admitted to disliking this topic because I am not good at it. This creates a pessimistic loop as I avoid it more because I hate it, and the more I avoid the topic the more I hate it. The main problem here is, I think, my lack of proper understanding. Although taking CSC165 helps with learning the concepts at the same time, there are still some discrepancies between the two courses -- after all, one is more math based and the other more code based. With regards to how my opinions had changed...?
Firstly, after going back and reviewing CSC148 and CSC165 slides, I now have a clearer mindset when I look at the code. Usually what messes me up are loops that have increments of a random amount. While eventually the counting should be math based, Professor Danny Heap's slower method of actually listing out examples of the values the counter can become definitely helps with visualizing. Also, listing out smaller countable examples also can help me find the general pattern to the run time function. He also gave out three basic rules regarding the different forms of code;
This week's designated topic was to revisit one of my posts and discuss whether my reviews or opinions had changed. I would like to head back into last week's entry regarding assignment 2, term test 2, and efficiency and run time. However, I'd like to focus on the last topic that I wanted to avoid -- Efficiency and Run Time. In even earlier entries (read: Entry 2: Week 4), I had already admitted to disliking this topic because I am not good at it. This creates a pessimistic loop as I avoid it more because I hate it, and the more I avoid the topic the more I hate it. The main problem here is, I think, my lack of proper understanding. Although taking CSC165 helps with learning the concepts at the same time, there are still some discrepancies between the two courses -- after all, one is more math based and the other more code based. With regards to how my opinions had changed...?
Firstly, after going back and reviewing CSC148 and CSC165 slides, I now have a clearer mindset when I look at the code. Usually what messes me up are loops that have increments of a random amount. While eventually the counting should be math based, Professor Danny Heap's slower method of actually listing out examples of the values the counter can become definitely helps with visualizing. Also, listing out smaller countable examples also can help me find the general pattern to the run time function. He also gave out three basic rules regarding the different forms of code;
- Sequences: Find the max(O(f(n))) of each statement as O(f(n))
- Lists: (Carefully) Count loop iterations, multiply for each nested loops
- Conditions: Take max(O(f(n))) which comes out of the worst case scenario
From the examples and counting, I can then summarize a pattern to compute Big-Oh for the function. Rather than panicking, I should sit down and comb through the code and work through the knots that are confusing me (ie Incrementations).
I am also very happy that in this course no specific O(f(n)) is required down to every line of the code. Working with patterns and putting them into summations to see the general trend may be one thing, but working out and expanding the summations is something completely different and definitely more difficult. After trying out a few examples the class had looked over together, I feel more reassured at my ability to judge Run Time and Big-Oh. Thanks to this course, I now have a better understanding and am more confident in working with them. Although I still feel slightly bothered because I don't know them like the back of my hand, but I am working towards getting better at them one step at a time.
One last trouble I still fret over regarding Run Time and Efficiency is the kind of problem where a chart of run time is given and the requirement is to find the O(f(n)) it belongs to. Even after comparing them to the patterns -- log(n), n, nlog(n), n^2, etc... I remain unsure because some of the patterns are still similar, especially with relatively smaller "n". If the difference in "n" is small between the given examples, the difference in T(n) is also not as significant or telling as it can be with bigger differences in "n". For example, the difference between the run time of O(nlog(n)) and O(n^2) for n = 100 to n = 200 is not as obvious as the difference between the two for n = 100 and n = 10000. This is still something that I've got to work on.
Saturday, March 26, 2016
Entry 9: Week 10: What shall come will come.
And of course I almost forget to write another entry for this week >w<.
My excuse this time was that yesterday was Easter Friday so I went out with friends and went to see BvS: Dawn of Justice and ROOM, so when I got back home, I headed straight to bed.
Anyways. I can't believe this semester is almost over already. We have essentially finished both term tests, both assignments, and all the labs. We did a lot in seemingly very little time. However, since we are still learning and there is a demo to do for A2, the review of the whole course will be done in the next and last entry, as required by the course syllabus.
A2, after sorting out the logic, turned out to be relatively straightforward. The only part that I am personally unsatisfied with is the run time for our WordLadderPuzzle. As compared to some of the other faster ones I've seen, both our DPF and BFS takes time in the double digits. Not only that, the run time is also not always consistent. The fastest recorded run time was around 14 seconds. The longest...? I was too ashamed to keep track of >_>. I would have liked it to be faster.
With regards to Term Test 2, I was right in that I made mistakes here and there take got marks deducted from. I personally feel like although the mark was okay, I was disappointed at myself for not being able to achieve my full potential.
And lastly, what I had feared had finally come -- Efficiency, Run Time, and Big-Oh. I am taking CSC165 along with CSC148, so both courses should compliment each other and help me achieve a better understanding, but my lack of confidence takes away the effect. I am constantly doubting myself when I'm looking at the run time, because some patterns are quite similar. If one doesn't know the clear traits or distinctions(which I don't), it's difficult to accurately identify the function the run time belongs to. I am okay with reading code and identifying Big-Oh from that, but giving me the run time and asking me to, for example, find the difference between n^2 and nlogn takes more time than it should. I think this is the part that I need to improve upon the most.
This concept is rather... conceptual(?) and specific to each sort/search algorithm. That and I don't yet have a solid understanding, so before the exam I must master it.
My excuse this time was that yesterday was Easter Friday so I went out with friends and went to see BvS: Dawn of Justice and ROOM, so when I got back home, I headed straight to bed.
Anyways. I can't believe this semester is almost over already. We have essentially finished both term tests, both assignments, and all the labs. We did a lot in seemingly very little time. However, since we are still learning and there is a demo to do for A2, the review of the whole course will be done in the next and last entry, as required by the course syllabus.
A2, after sorting out the logic, turned out to be relatively straightforward. The only part that I am personally unsatisfied with is the run time for our WordLadderPuzzle. As compared to some of the other faster ones I've seen, both our DPF and BFS takes time in the double digits. Not only that, the run time is also not always consistent. The fastest recorded run time was around 14 seconds. The longest...? I was too ashamed to keep track of >_>. I would have liked it to be faster.
With regards to Term Test 2, I was right in that I made mistakes here and there take got marks deducted from. I personally feel like although the mark was okay, I was disappointed at myself for not being able to achieve my full potential.
And lastly, what I had feared had finally come -- Efficiency, Run Time, and Big-Oh. I am taking CSC165 along with CSC148, so both courses should compliment each other and help me achieve a better understanding, but my lack of confidence takes away the effect. I am constantly doubting myself when I'm looking at the run time, because some patterns are quite similar. If one doesn't know the clear traits or distinctions
This concept is rather... conceptual(?) and specific to each sort/search algorithm. That and I don't yet have a solid understanding, so before the exam I must master it.
Monday, March 21, 2016
Entry 8: Week 9: Of Assignments and Term Tests II
Ah I almost forgot to post this blog D: quite sorry about that. I did remember that I was supposed to write something for this week, but I ended up bring my computer with 20% battery home with no charger, and happened to be out for the weekend.
Yes, while I do understand that I'm finding excuses for myself, I'm also here to catch up.
Last week was Term Test 2 regarding LinkedLists, Trees, and Recursions. Apparently many of the students reflected that it was easier than the first test. However, I believe that rather than easier, it had contained more components that required the student to think before they grab their pencils. For example, docstrings weren't counted so heavily towards the marks because they were provided, and more weight was put on the logic of tracing recursions through lists and trees, and keeping track of linked lists and their nodes. Although focusing on logic is definitely a main part of computer science, I can't help but worry for myself. I am a person that makes small errors easily, so I am afraid that I might be losing marks here and there on random tidbits.
That aside, A2 is due almost immediately after. Just as Term Test 2 had compared to Term Test 1, A2 also requires a lot more thinking than A1. Although the puzzles can be generalized, the generalization is actually harder than I expected. My group and I had finished writing code for the program, but of course there are a lot of bugs and we definitely have to improve the run time. Somehow breadth first search for word-ladder puzzles takes time in the two digits... *sigh*
Also, we were stuck on the class PuzzleNode for quite a bit of time (I won't be telling you we're still stuck on it). On Piazza those who are close to being done or are already finished are saying things like each PuzzleNode should only have a child who leads to the right solution -- which completely makes sense, but is also confusing when first looking upon the list[PuzzleNode] in the docstring. That, and I think we are still having some problems linking each PuzzleNode to their parents. Apparently the trouble we are encountering have children poinging to parents, but not vice versa? But there's a line of code that redirects...???
Last but not least, we still haven't solved the problem of keeping track of seen configurations in depth-first-search. We want to reset the seen configuration list at the beginning of every puzzle solving, but not when the function is called recursively... Okay okay, I admit that we are far from done, but one step at a time right... I'll stuff my head back in there once I'm done here xD.
Friday, March 11, 2016
Entry 7: Week 8: Tree Powers Activate
It seems like we have done a lot after last week... Although only a week has passed? The pace of learning is definitely picked up as there are only a month to school left. Quite scary actually. I had just realized that we have a test next Wednesday after Danny had said so this week, and that the finals are also coming up soon. I am definitely stressed.
From last week to this, there are two topics covered -- even more recursion, and trees, which branches(ahaha) into trees with a defined number of nodes, and binary trees. These two are closely related as most methods for trees requires recursion. The best practice for recursion in trees is probably additional.py under Lab 7 (which the directory can be found here). This file clearly organizes many different useful methods for trees into practices, and can be used as a reference "library" to the class trees.
Recursion:
From last week to this, there are two topics covered -- even more recursion, and trees, which branches
Recursion:
- Base Case: stopping condition
- may have several!!!
- Recursive step: subcall of own function
Trees (Branched):
- Number nodes uncertain
- Arity = max(num children under node)
- Height = max(num level)
- Node -(edge)- children -- grandchildren --etc
- has children [list] == root
- has no children == leaf
- Path: sequence of nodes from a1 ->???->an
- length = num(edge of path)
- Depth: # layers in
- More terminology found here.
- Pre-order:
- node => children
- Post-order
- children => node
- Level-Order:
- Depth by depth
- using WHILE loop
- recursing using call(n-1)
- recursing using queue
Trees (Binary):
- Left/Right = 2 children only
- Subtypes:
- Binary Search Trees: L < N < R
- run time \lceil log_2 numnodes \rceil
- Arithmetic Trees
- data = operation
- leaf = values
- Difference in Traversals:
- in-order: L -> node -> R
- post-order: R -> node -> L
Usable Code:
- all([list of bool] = \forall = for all
- any([list of bool]) = \exists = there exist
- {sets, of, elements}
- unordered
- mutable (unless "frozen set")
- iterable
- considers only value of elements
- ex: dictionary
Wednesday, March 2, 2016
Entry 6: Week 7: Recursion
Recursion seems like a big concept for beginners who are learning it -- I remember when I first encountered computer science using recursion I was confused as to how recursion actually ran. Back then, the tracing method I learned was a slightly inefficient one (basically writing out each of the steps and variables on stack by hand, like a human debugger), so it took me longer than I expected to grasp the concept. However, after I understood the gist of the self-calling functions, everything became a lot more clear. Here I will sum up what I have learned.
First of all, the structure of recursion is very important. Professor Heap's (Danny's) slides sum it up very well.
(This can be found in the slides for Feb. 29th)
It is absolutely essential to have a base case. Why? Assume a recursive function with no base case. What would happen? Since the program is recursive, one execution will lead to one or more execution, which will subsequently lead to more executions with no end. If there is no stop to the program, it will run on forever. Unless you purposefully want your program to run forever (which is entirely up to you), I'd suggest putting a stop at the end. It doesn't matter whether the base case be a lower limit (like counting down), or an upper limit (like the number of layers the recursion is into), as long as there is something. And then the expression without recursion. Whether it be an executable line of code, or a return statement, as long as it doesn't generate another loop and jump out of the infinite circle, anything's good.
Of course, next comes the part with recursion. Placing it in the else: statement is definitely a safety measure. Though if the expression without recursion is a return statement, an else is not necessary? The expression that follows is the key part that recurs. This is the part where the function calls itself within itself. If no recursion occurs, then there will be no progress because the function execute once on the outer layer of the recursion. Recursion is the repeated calls from outer to inner to go through every layer, like unstacking a matryoshka, or peeling an onion. The function recurs until arriving at the base case, the stop mentionned above.
The most classic example I have encountered is using recursion to find a certain number in the Fibonacci Sequence. The stopping condition is usually n, the nth element in the sequence, and also the number of times the function executes. The non-recursive expression returns the a_(n-2) + a_(n-1) while the recursive expression calls on the function itself again, passing in the next element in the sequence (i+1, i being the current element), the upper limit (n), and the current a_(i-1) and a_(i-2) + a_(i-1).
Other than lists and trees, a lot of sequencing, like geometric and arithmetic sequences can be modeled by recursion. There are also a lot of other usages, such as solving for factorials, solving games (cue: A2, Tower of Hanoi, etc.), and drawing beautiful fractals.
tl;dr - have a base case to prevent infinite loops, than have recursion where the function calls itself within itself, and it's nice to use recursion to solve nested/layered problems.
First of all, the structure of recursion is very important. Professor Heap's (Danny's) slides sum it up very well.
(This can be found in the slides for Feb. 29th)
It is absolutely essential to have a base case. Why? Assume a recursive function with no base case. What would happen? Since the program is recursive, one execution will lead to one or more execution, which will subsequently lead to more executions with no end. If there is no stop to the program, it will run on forever. Unless you purposefully want your program to run forever (which is entirely up to you), I'd suggest putting a stop at the end. It doesn't matter whether the base case be a lower limit (like counting down), or an upper limit (like the number of layers the recursion is into), as long as there is something. And then the expression without recursion. Whether it be an executable line of code, or a return statement, as long as it doesn't generate another loop and jump out of the infinite circle, anything's good.
Of course, next comes the part with recursion. Placing it in the else: statement is definitely a safety measure. Though if the expression without recursion is a return statement, an else is not necessary? The expression that follows is the key part that recurs. This is the part where the function calls itself within itself. If no recursion occurs, then there will be no progress because the function execute once on the outer layer of the recursion. Recursion is the repeated calls from outer to inner to go through every layer, like unstacking a matryoshka, or peeling an onion. The function recurs until arriving at the base case, the stop mentionned above.
The most classic example I have encountered is using recursion to find a certain number in the Fibonacci Sequence. The stopping condition is usually n, the nth element in the sequence, and also the number of times the function executes. The non-recursive expression returns the a_(n-2) + a_(n-1) while the recursive expression calls on the function itself again, passing in the next element in the sequence (i+1, i being the current element), the upper limit (n), and the current a_(i-1) and a_(i-2) + a_(i-1).
Other than lists and trees, a lot of sequencing, like geometric and arithmetic sequences can be modeled by recursion. There are also a lot of other usages, such as solving for factorials, solving games (cue: A2, Tower of Hanoi, etc.), and drawing beautiful fractals.
tl;dr - have a base case to prevent infinite loops, than have recursion where the function calls itself within itself, and it's nice to use recursion to solve nested/layered problems.
Saturday, February 27, 2016
Entry 5: The Actual Week 6: A1->A2
Okay I lied. Reading week apparently didn't count as a numbered week.
Also, no excuses for me. Although I did remember that I should update my blog during my Friday lectures, I had completely forgotten about it until this lunch when I was munching on some ___ did I realize that... maybe I should have completed my entry by Friday. Maybe I'll set an alarm for it some time later.
We finally started recursion this week, and by the looks of it, this topic will go on for quite a bit longer. I've seen enough people crack jokes about recursion (ie, pretending to recurse their sLOGs, so I won't do it here). Although many people haven't done recursion and doesn't realize it, I believe teaching us LinkedList(Nodes) was a good prequel. One can argue that the form of it drawn out like a long chain has nothing to do with recursion, which I admit is true, but actually the definition of linkedListNodes do look like recursion -- calling an object within an object, just like calling a function within a function. However, I guess I shouldn't write too much about recursion here because Week 7 sLOGS should be more focused on recursion.
Therefore, labs and assignment 1. Although Assignment 1 is now up and running (my version on events.txt and events_small.txt anyways), I must reflect on this time. I don't believe that I had done enough testing for all the different possible cases because I finished coding on Wednesday. Our group had only simulation.py and monitor.py to finish after reading week, so we thought we had some spare time and let down our guard during the last week. This should not happen in order to finish earlier for testing purposes. We should not have relaxed just before the finish line -- like a race, we should dash past the finish line before relaxing. Testing should be done anyways. The program is in fact more complicated (with more modules) than the ones before, but is still tiny as compared to major software programs. Testing should be done along the way to ensure there are no future problems. I think unittests were only written up until event.py. Doctests were rarely done. There is definitely for improvements there.
Also, finding a good group becomes essential in working in larger projects -- just as mentioned in class, there were many divorces and late constructions of groups. It is reasonable that since students don't know each other well and conflicts can happen, but at the last minute, changes like these don't seem appropriate? I guess, at least try working with someone before you decide whether you work well with them?
Usable Code:
Also, no excuses for me. Although I did remember that I should update my blog during my Friday lectures, I had completely forgotten about it until this lunch when I was munching on some ___ did I realize that... maybe I should have completed my entry by Friday. Maybe I'll set an alarm for it some time later.
We finally started recursion this week, and by the looks of it, this topic will go on for quite a bit longer. I've seen enough people crack jokes about recursion (ie, pretending to recurse their sLOGs, so I won't do it here). Although many people haven't done recursion and doesn't realize it, I believe teaching us LinkedList(Nodes) was a good prequel. One can argue that the form of it drawn out like a long chain has nothing to do with recursion, which I admit is true, but actually the definition of linkedListNodes do look like recursion -- calling an object within an object, just like calling a function within a function. However, I guess I shouldn't write too much about recursion here because Week 7 sLOGS should be more focused on recursion.
Therefore, labs and assignment 1. Although Assignment 1 is now up and running (my version on events.txt and events_small.txt anyways), I must reflect on this time. I don't believe that I had done enough testing for all the different possible cases because I finished coding on Wednesday. Our group had only simulation.py and monitor.py to finish after reading week, so we thought we had some spare time and let down our guard during the last week. This should not happen in order to finish earlier for testing purposes. We should not have relaxed just before the finish line -- like a race, we should dash past the finish line before relaxing. Testing should be done anyways. The program is in fact more complicated (with more modules) than the ones before, but is still tiny as compared to major software programs. Testing should be done along the way to ensure there are no future problems. I think unittests were only written up until event.py. Doctests were rarely done. There is definitely for improvements there.
Also, finding a good group becomes essential in working in larger projects -- just as mentioned in class, there were many divorces and late constructions of groups. It is reasonable that since students don't know each other well and conflicts can happen, but at the last minute, changes like these don't seem appropriate? I guess, at least try working with someone before you decide whether you work well with them?
Usable Code:
- zip(a, b)
- //maps every ele of a to b
- zip([1,2], ["a","b"])
- [(1,"a"), (2, "b")]
- *zip() //unzips a zip
- filter(bool f'n/expr, iterable/list/etc)
- //goes through iterable and filter by checking each element with boolean statement
- filter(1, len(x) for x in ["a", "bc", "d"])
- expr1 if bool else expr2
- if bool: expr1
- else: expr2
- there must be something else here, but i can't quite remember...
- maybe i'll add on later.
Friday, February 19, 2016
Entry 4: Week 6: Reading Week Freaking Week
And so I resort to blogging on Fridays.
Next week is Week 7, we will be starting recursions, and so I have to update by Thursday to print the entry out. Okay. Got it. Mental noted.
As opposed to actually having reading week to catch up on reading, I found myself doing more work. Huh. But all's well, because computer science is being worked on -- especially A1.
To be honest in some aspects A1 is easier than I thought, but in others, harder. The complexity of the code actually needed to be written wasn't as bad, but the "figuring out" what to write part was worse. Actually reading the whole document, mapping the thoughts out, and clearing up which module belongs where takes up quite some time. The tips here is to DRAW LOTS OF PICTURE!!! Okay maybe not pictures of little cars and little people, but definitely flowcharts and diagrams of classes, objects, and their connections. Especially when two classes can share a common attribute or subject, but in actuality said thing can only belong to one of them.
We are quite lucky that many of the APIs are given to direct us in the correct direction, but finishing them up are sometimes also a handful. MAKE SURE TO COMPLETE THEM!!! It gives readers and everyone else (even the coder as they come back to this program) a lot of readability.
There isn't much to say while coding, other than KEEP YOUR CODE AS SIMPLIFIED AS POSSIBLE. This is for running and reading code. Why complicate it when it could save so much space/run time/read time? Although, for a relatively smaller program like this, it is arguable to have code executable in one line written out in several lines for clarity, but I feel that it is best to simplify everything as much as possible. For this assignment, there shouldn't be a lot of hard coding in my opinion, especially for the first few classes.
TEST AS YOU GO! After writing code for a section, it is essential to test them. As much as I had complained about unittest in my previous post, I cannot deny how useful they are -- especially as programs grow larger and larger and it's almost impossible to test but simple doctests and feeding code in through the program by hand like a little baby. I found that I actually wanted to do unittests after I finish bigger classes like Events and even Dispatcher. However, unittests are extremely time consuming, so I would suggest NOT doing that unless you are sure you have enough time, or shorten them and test only the most essential cases.
Last but not least, a progress update. My group and I did originally WANT to finish the programming by this week, but it turned out to be more than we thought, given there were so many other subjects to do. However, here's a # TODO list:
- test Events; - do Simulation.py + test; - do Monitor.py + test
I'd say we are "almost" done, but those two being the two harder classes, I'd say we are ~1/3 way to go.
Next week is Week 7, we will be starting recursions, and so I have to update by Thursday to print the entry out. Okay. Got it. Mental noted.
As opposed to actually having reading week to catch up on reading, I found myself doing more work. Huh. But all's well, because computer science is being worked on -- especially A1.
To be honest in some aspects A1 is easier than I thought, but in others, harder. The complexity of the code actually needed to be written wasn't as bad, but the "figuring out" what to write part was worse. Actually reading the whole document, mapping the thoughts out, and clearing up which module belongs where takes up quite some time. The tips here is to DRAW LOTS OF PICTURE!!! Okay maybe not pictures of little cars and little people, but definitely flowcharts and diagrams of classes, objects, and their connections. Especially when two classes can share a common attribute or subject, but in actuality said thing can only belong to one of them.
We are quite lucky that many of the APIs are given to direct us in the correct direction, but finishing them up are sometimes also a handful. MAKE SURE TO COMPLETE THEM!!! It gives readers and everyone else (even the coder as they come back to this program) a lot of readability.
There isn't much to say while coding, other than KEEP YOUR CODE AS SIMPLIFIED AS POSSIBLE. This is for running and reading code. Why complicate it when it could save so much space/run time/read time? Although, for a relatively smaller program like this, it is arguable to have code executable in one line written out in several lines for clarity, but I feel that it is best to simplify everything as much as possible. For this assignment, there shouldn't be a lot of hard coding in my opinion, especially for the first few classes.
TEST AS YOU GO! After writing code for a section, it is essential to test them. As much as I had complained about unittest in my previous post, I cannot deny how useful they are -- especially as programs grow larger and larger and it's almost impossible to test but simple doctests and feeding code in through the program by hand like a little baby. I found that I actually wanted to do unittests after I finish bigger classes like Events and even Dispatcher. However, unittests are extremely time consuming, so I would suggest NOT doing that unless you are sure you have enough time, or shorten them and test only the most essential cases.
Last but not least, a progress update. My group and I did originally WANT to finish the programming by this week, but it turned out to be more than we thought, given there were so many other subjects to do. However, here's a # TODO list:
- test Events; - do Simulation.py + test; - do Monitor.py + test
I'd say we are "almost" done, but those two being the two harder classes, I'd say we are ~1/3 way to go.
Friday, February 12, 2016
Entry 3: Week 5: Of Assignments and Tests
I must make a correction to my statement last class. In fact, I do indeed find a difficult aspect for me appearing in this course -- Unit Tests. While it is untrue to say that unit tests are hard in nature (since they have a defined structure so there is little variance in constructing them with code), they are trouble some in their flexibility and range covered.
To test a program fully, all significant cases of a method must be tested. However, what is exactly "significant"? Although we do follow the rule that we should at least test the null (ie 0-sized list) cases, the smallest interesting case, regular cases, borderline cases, and cases where specific variables have values that make a difference in the result, that still leaves a big variation in each one of the cases. Having to consider for all of these is a very good practice, as it prevents unexpected errors in execution, but covering all of them takes a lot of effort. Constructing each unit test also consumes as much time, or even more, than writing the code. Fixing the code for unit test is also difficult, having to consider for all cases and make it still functional. There then exists a problem of how much error prevention is needed in each method -- the open ended question of the type of improper input the end user can enter expands into a completely different universe of possibilities for the program.
As helpful as unit test is, as dreadful as I am to it.
Here's what I learned this week:
List and Linked List Based Queues:
- List based Qs are too slow
- asymmetric
- add @ front + remove @ back: shift right for add, too slow
- add @ back + removed @ front: shift left for remove, too slow
- Stacks are faster: access @ one end = ~same ease of access/speed
- LinkedList Based Qs:
- more symmetric @ both ends
- doubly linked (previous + next) = more symmetric
- if singly linked: add @ back + remove @ front:
- del front = change first
- add back = append
- other way: remove cannot do "previous" of back
- if doubly linked: both direction works
- though slower @ middle
Linked Stacks:
- Instead of append (like Q), prepend (to invert order)
- add front, remove front
- not necessarily slower than stack
Friday, February 5, 2016
Entry 2: Week 4: Stacks, Qs, and Linked Lists
I think the most difficult thing for me during this course is to actually settle down and read the notes. Up until now, I have been doing relatively well (hopefully...) understanding the concepts in class and practicing during lab. However, I always find a million things I need to do and never really review my notes and concepts... Which this blog serves at least a part of the purpose for coming back and looking at what we learned.
I haven't yet found any aspects to be extremely challenging because I have had some minimal experience in coding in other languages. I do need to be careful though, because after all, some things like linked lists are still new concepts to me. The most challenging concept will probably be efficiency and Big-O in the later half of the course -- I was never good at it.
And for this week (as a summary of this week's lecture and Friday's class. I have not decided on a set schedule to post yet, though I probably should. I was hoping for bi-weekly):
Stacks:
I haven't yet found any aspects to be extremely challenging because I have had some minimal experience in coding in other languages. I do need to be careful though, because after all, some things like linked lists are still new concepts to me. The most challenging concept will probably be efficiency and Big-O in the later half of the course -- I was never good at it.
And for this week (as a summary of this week's lecture and Friday's class. I have not decided on a set schedule to post yet, though I probably should. I was hoping for bi-weekly):
Stacks:
- NOT built into Python
- Last In First Out (LIFO?)
- Good for balancing parenthesis/delimiters
- left in (, [, { //opening: add to stack
- right out ), ], } //closing: match with most recent, remove from stack
- balanced if out = last in
- concatenation of balanced = balanced
Queue:
- First In First Out (FIFO)
- Coffee Line/Ticket Line
Linked Lists:
- Separate bits of data
- Easier to grab in storage
- Value + "Pointer" // 2 parts
- Concept can be viewed in two ways
- Quite literally like the format of its declaration:
LinkedListNode( value1, LinkedListNode( value2, LinkedList( value3, ...)))
A box inside a box inside a box inside a box insi-... - A flowchart
Node(v1, pointer-)-> Node(v2, pointer2-)->Node(v3)
One points to another points to another until arrive @ no pointer - Node vs Wrapper
- node: self, next
- wrapper: front, size, back
- Append/Prepend/Delete
- change related variables
- Prepend: 1st, 1st's next, size
- Append: (if not first) oldLast's next, last, size
- Delete: oneInFront's next, size
Usable Code/Miscellaneous:
- A subclass of std lib class cannot simple overwrite methods of SUPER
- super.method() //parent class's method
- random
- import random (package)
- random.randint (smallest, largest)
- inclusive
- list.insert(i,x) insert @i before original x
- Abstract Classes: Simple API for all the child classes to be file under
- basically a container
- convenient
- no var/fn of its own
- var_ //distinguish names from std py names
- isinstance(var, type) vs type(var).__name__
- walk-a-list:
- current = first
- while!=last:
- current=next
- assertion
- bool fn, a checking statement
- crash if false
- __contains__ maps to "in"
- __repr__ maps to return print value
- def __repr__(self):
- return "Ahaha %s nope %s" %(self.x, self.y)
- >>> var
- Ahaha selfXval nope selfYval
- __getitem__ enables printing parts
- print(LinkedList[0:3])
Wednesday, January 27, 2016
Entry 1: Week 3: Introductions
Oh man I really hate decision making.
Of all the freedom of choice among the available blogging services on the Internet, deciding on settling with Blogger (or "Blogspot") was a difficult decision for me. Although I have had experience with most of the blogging services (ie. Tumblr, WordPress, LiveJournal, Blogger, etc), weighing between the pros and cons of each still took a bit of time. In the end, I deemed Tumblr to be too distracting, did not like WordPress' post editor, and found LiveJournal to be a bit too buggy for my liking. That left me with Blogger. I have actually done a similar course blog (as compared to sLogs) on Blogger before, so it probably was a decent choice since I am already familiar with this environment.
However, to fully set up this blog with "style" and other components such as background music or extensions as such, it's probably going to take me a bit (which is within expectation). Hopefully I will update this blog every time a topic concludes. If not, then once a week (and no less frequent).
To be honest, I do find blogging a good idea to help organize and refresh the material learned in class. In order to write a blog post, one must fully understand both clearly and logically the material to express it in their own words. It would also be beneficial to come back and reread the posts written (as mentioned in the instruction PDF) for review. Although most notes are written in the notes.pdf, I will sum up what I found interesting and significantly notable taught in class.
Up until now, here is a brief list of aforementioned knowledge (in the format such that a study sheet can be formed for myself towards the end of the semester).
Objects/Classes:
Of all the freedom of choice among the available blogging services on the Internet, deciding on settling with Blogger (or "Blogspot") was a difficult decision for me. Although I have had experience with most of the blogging services (ie. Tumblr, WordPress, LiveJournal, Blogger, etc), weighing between the pros and cons of each still took a bit of time. In the end, I deemed Tumblr to be too distracting, did not like WordPress' post editor, and found LiveJournal to be a bit too buggy for my liking. That left me with Blogger. I have actually done a similar course blog (as compared to sLogs) on Blogger before, so it probably was a decent choice since I am already familiar with this environment.
However, to fully set up this blog with "style" and other components such as background music or extensions as such, it's probably going to take me a bit (which is within expectation). Hopefully I will update this blog every time a topic concludes. If not, then once a week (and no less frequent).
To be honest, I do find blogging a good idea to help organize and refresh the material learned in class. In order to write a blog post, one must fully understand both clearly and logically the material to express it in their own words. It would also be beneficial to come back and reread the posts written (as mentioned in the instruction PDF) for review. Although most notes are written in the notes.pdf, I will sum up what I found interesting and significantly notable taught in class.
Up until now, here is a brief list of aforementioned knowledge (in the format such that a study sheet can be formed for myself towards the end of the semester).
Objects/Classes:
- has type(/class), value, methods/functions/operators
- mutable
- attaching method to class blueprint:
- Class.method = outside_method
- own methods defined (dented) within class body
- Big Three:
- __init__(self) //construction, 2 stages
- Brand "new" object created with attributes
- init method declares initial state
- __str__(self) //print
- __eq__(self, other) //equals ==
- Optional + Applicable Only:
- __add__; __lt__; __mt__; //standard operations, etc.
Properties:
- manages access by end users
- private (instead of public)
- notations/conventions/grammar:
- _var
- _method_name
- #"""
- #comments
- #"""
- maps usage of var to its private methods
- var = property(_getter,_setter,_del,_documentation)
- leave out methods/set to "None" to disable corresponding functions
- Example: _var = (_get_var, _set_var, None, """@param type var:description""")
Composition:
- parallel structure
- borrow other class/code
- instance of one class in another
- individual sets of attributes/properties
Inheritance:
- no duplicate code (avoid error)
- group objects w/ similar attributes/properties
- hierarchy
- Parent: Super class
- Child: subclass
- def subclass (Superclass):
- subclass is an instance/child of Superclass
- avoiding duplication of documentation:
- Inherited: no need
- Extended: how extended
- Overridden: how overridden
Abstract Data Types (ADTs):
- suppress technical details to end users; expose value + what var is worth
- OBJECTS (ie):
- list: sequence of items, add, remove, access position;
- stack: specialized list, only access to most recent item, Last In First Out (LIFO)
- dict: collection of items, accessed by associated keys
Usable Code (misc.):
- pass //"continue"
- if __name__== "__main__": //executing only if in own module
- import doctest //doctests
- doctest.testmod()
- @type var: type //variable type declaration
- description
- @rtype; type //return type declaration
- description
- @param type var: description //"better" variable declaration
- "str{}",format(var) //can use simply {} w/o ints
- from module import Class //importing
- TIPS; MAKE SHALLOW (shadow?) copies to prevent accidental modification
- ie: new_list = old_list[:]
- new_list = [expr for x in L if condition //list comprehensions + filters
- TIPS: circular for loops for lists
- for i in range(len(s)):
- function([i] + [i-1]) // 0 can go to -1 to loop from first back to last element
- type(var).__name__ //returns class name
- str = "seperator".join(str(x) for x in list) //using list comprehensions
- unittest //written before code, represent interesting cases
- setUp(self) //set up for each individual test case, used before each
- tearDown(self) //reset to none (default), used after each
- assert bool, "error msg"
- testSmallestArgs, testBoundaryCases, testTypicalCases
And last but not least, IMPATIENCE, HUBRIS, LAZINESS.
Subscribe to:
Posts (Atom)

