Blog, ECS 145 Winter 2018

Wednesday, March 14, 11:00 pm

You may find the R function invisible() to be useful. It's main use is in a situation in which your last statement within a function body produces a result that you do NOT want returned to the caller. Type ?invisible for details.

Wednesday, March 14, 4:10 pm

Just to make sure we are all on the same page: Our group quiz is this Friday, in the regular lecture time slot/room. There will be no discussion section.

Tuesday, March 13, 10:05 pm

Sorry, but I will need to impose the following rules for Friday's group quiz. Thanks in advance for your cooperation.

Sunday, March 11, 3:05 pm

Just made a post to NotPiazza.html.

Saturday, March 10, 5:15 pm

I have resumed writing posts to our NotPiazza.html site, for the Term Project.

Thursday, March 8, 11:45 pm

Sorry for the delay in grading Quiz 6 (and Quiz 0). Will do this in the next day or so.

Wednesday, March 7, 11:55 am

A CS faculty meeting was suddenly scheduled yesterday for 4 pm today. So I will again need to postpone my office hour until 5.

Tuesday, March 5, 2:40 pm

IMPORTANT: In working a quiz problem, if your code works partially but on some parts either has syntax errors or results in an execution error, COMMENT OUT THOSE PARTS SO THAT THE CODE DOES RUN. This way you demonstrate that your code is at least partially correct, and the grader (me) can focus on the faulty code, now in comments but still visible to the grader.

Tuesday, March 5, 1:30 pm


Here is a followup to yesterday's coverage of the example in Sec. 6.6. As noted, even though X1 appears to be of R's numeric type, it is actually an R factor, with levels "0", "5", "12" and "13". When we tried to assign 3 to its first element, R said, "No, you can't do that, because 3 is not one of the official levels for this factor variable." Let's look closer:

> str(d$X1)
 Factor w/ 4 levels "0","12","13",..: 1 4 2 3
> levels(d$X1)
[1] "0"  "12" "13" "5" 

Look for example at that 4. It means that d$X1[2] is the fourth level, which you can see is 5. (The levels are character strings, in alphabetical order.)

Note too the warning message above, which explicitly shows usage of replacement functions. Here is an example using vectors rather than factors:

> x <- c(13,12,5,8)
> x <- '[<-'(x,3,18)  # what actually happens inside when we do x[3] <- 18
> x
[1] 13 12 18  8

Sunday, March 4, 4:40 pm

The Term Project is ready!

There is a considerable amount of code to be written, not too hard, but requiring a LOT of thinking. Plus writing and research on how the simmer package works. You have 18 days left; if you don't start soon, you will NOT finish.

Sunday, March 4, 3:45 pm

Please note: I am in the midst of writing up the Term Project. It is NOT ready yet, though hopefully it will be later. Also, note that the handin site listed by Zheng today for the Term Project is incorrect; I will be grading it, so it will be under my account. Details to follow.

Saturday, March 3, 3:20 pm

Version 1.2.5 of OMSI is now on GitHub. For reasons explained in the last post, I strongly recommend that you upgrade to this version. However, Version 1.2.4 is still usable. Note that, by the blog post of Sunday, February 25, 12:05 pm, it is required that you have at least version 1.2.4.

Saturday, March 3, 2:55 pm

I have mentioned a number of times that, given that ECS 145 is a course in software development, I feel a responsibility to teach issues in software development that go beyond mere programming. Yesterday's troubles with OMSI provide us with what people call a "teachable moment" in this sense.

I believe strongly that OMSI provides the instructor with a more accurate assessment of your insight into the course material, i.e. you get a better grade., and I hope you agree. By providing feedback -- your code produces the wrong answer -- you have a chance to correct it and get full credit for the question. Nevertheless, this is only the second quarter in which OMSI has been used fully in a course, so issues may arise.

Yesterdya morning, the OMSI exam questions failed to download to the student clients. This was due to the some TCP/IP subtlety related to the unusual length of the questions file at the server. Both Zheng and I tested it, but unfortunately we tested it only on 'localhost' in our own machines, not on CSIF. There can be a difference, and that turned out to be the case. Zheng and I should have checked for this.

So, we moved the quiz to the afternoon lecture slot. The questions download went fine, but during the quiz a number of students had trouble submitting their answers. This was due in part to the unusual length of the answers and likely network congestion, but mainly to a long-latent bug in OMSI. Bear with me here, as I believe you will find the following educational.

As written originally (two years ago), the client code for submitting an answer file to the server SHOULD HAVE looked like this:

# code for configureSocket(); returns socket connection to server
while True:
      connect to server
      return socket 
      print error mess

Inexplicably, what the code actually looked like was

# code for configureSocket(); returns socket connection to server
   connect to server
   return socket 
   print error message
   call configureSocket()

In other words, the author of that particular part of the code took what should have been an ordinary loop and made a recursive call out of it. Much worse, he/she did not return the return value of the recursive call. So, if the connection is not made on the first try, even if it is successfully made later, IT GETS LOST, not returned to the original caller.

The OMSI authors formed the Dream Team, all of them first-rate students and first-rate programmers. They developed a highly sophisticated system with very little input from me. Two of them are now in grad school at top universities. (I of course wrote glowing letters of recommendation for them.) But even first-rate people can take some wrong turns.

This bug lay dormant until Version 1.2.4, when it became exposed due to a timeout limitation I added to the "try" portion. So, my Bad; when I put in the timeout, I should have worried more about "ecological" effects. (And again, the new version passed all my tests.)

So, two "learning opportunities" here.

Friday, March 2, 1:25 pm

In preparation for this afternoon's quiz, please copy your MachRep.R file to both omsi_answer3.R and omsi_answer4.R.

Friday, March 2, 1:25 pm

Sorry, I typed that last message on my phone, necessarily brief.

My standard policy is that your two lowest quiz grades (letter grades) are thrown out. Sometimes I change it to three, and I am doing so now. This is because at least one student will not be able to make this afternoon's quiz. (But everyone will get this bonus, whether they participate in the quiz or not.)

Friday, March 2, 11:45 am

Due to today's error, some may not net able to take thequiz this afternoon. Compensating policy to be announced.

Friday, March 2, 11:05 am

We will conduct the quiz in lecture TODAY.

Make sure DES.R, MachRep.R and MM1.R are in the directory from which you launch OMSI.

Tuesday, February 27, 10:05 pm

In preparation for Friday's quiz, I strongly recommend that you actually run the two examples, MachRep.R and MM1.R, using source() to load the library.

Tuesday, February 27, 10:00 pm

I have another 4-5 meeting tomorrow, so will not meet my office hour until about 5:15 or so.

Tuesday, February 27, 2:20 pm

As noted, the two main built-in debugging tools in R are the debug() and browser() functions. Though I am really big on using debugging tools, remember that in OMSI you have no keyboard input. Thus you will have to resort to print() calls.

If you are having an execution error, place a return() call before the spot where it occurs.

Monday, February 26, 9:00 pm

As noted in the last post, download the des files (from GitHub, not from our Web page), and place at least DES.R, the library file, in the same directory as The code you will be given to work on in the quiz will begin with a line


The source() function executes the contents of the specified file, in this case just definitions of the library functions.

ALSO: For the quiz, make sure you understand the R sort() function (just with default arguments). It's very simple, but note that it has no side effects;

y <- sort(x)

will place the sorted version of x in y, but x itself will not change.

Sunday, February 25, 12:25 pm

Following up on my post of Thursday, February 22, 11:10 am, please download the three .R files from my DES site and place them in your OMSI directory (AFTER upgrading OMSI; see below). These will be used on this week's quiz.

Sunday, February 25, 12:05 pm

Please download Version 1.2.4 of OMSI, and use it from now on.

The new version deals with the following problem: Near the end of a quiz, many students hit the Submit button, causing temporary network congestion. In some cases OMSI hangs (e.g. spinning rainbow wheel on Macs), and does not recover even when the network traffic subsides. The only remedy with OMSI Versions 1.2.3 and below has been to kill the OMSI process and restart. With Version 1.2.4, there is now a call to settimeout() so that this can be avoided.

Saturday, February 24, 2:40 pm

I am e-mailing the Quiz 5 results as a I write this. Overall good, though of course unfortunately with some exceptions.

I messed up part (b) of Question 1. Unfortunately, I didn't catch it, and our TA didn't catch it either. (I always send the draft quiz to my TA for comment, and indeed Zheng made a good suggestion in terms of clarification on this quiz.) So, I only counted part (a). However, please read the solution (which has the question repaired.)

Saturday, February 24, 8:55 am

I strongly recommend that you review the material on SimPy in our Python book before Monday's lecture on the R des package.

Thursday, February 22, 11:10 am

Regarding my blog post of Thursday, February 22, 12:00 am:

I have placed the three files of my des package on our Web page:

The first two files are applications, and the third is the library code.

Please make hard copies, ready for my lecture of February 25 and our quiz on March 2.

These files illustrate general R principles (e.g. performance issues), and will set up your Term Project.

As I mentioned, the latter will have a discrete-event simulation (DES) theme. Here is an overview of the main features:

Thursday, February 22, 12:00 am

As I stated in class today, our Term Project will have discrete-event simulation as its theme. So, I want to cover a better version of the book example that we skipped today. Please make hard copies of the three R files in, which we will discuss next Monday. The quiz a week from Friday will likely be partly or fully on this material.

Wednesday, February 21, 8:30 pm

A couple of weeks ago, a student sent me e-mail, asking to see his OMSI answer file for a certain quiz. I did not immediately dig it up for him, but now that I have time to do so, I can't find his e-mail message. If this was you, please contact me.

Wednesday, February 21, 4:15 pm

In Problem A, you really must do a merge, O(n), not a sort, O(n log n).

Tuesday, February 20, 7:50 pm

I have been planning to put a Problem B on Homework III. The one I had in mind is pretty complicated, so I decided to actually work it out myself. I'm mostly done, but I see that it is complex enough for me to make it a Term Project instead of an ordinary programming assignment. I will give it to you in about a week.

Sunday, February 18, 9:00 pm

I just added an example (without '+'()) for Problem A.

Saturday, February 17, 11:00 pm

Earlier this evening I e-mailed your Quiz 4 scores. In general, the results were quite good. A few students had code which was tailored to the specific test case but would generally fail; please look carefully at the solution.

I am in the midst of e-mailing your cumulative quiz records. Note that our course syllabus contains a full, detailed description of the formula under which your course grade will be computed.

Saturday, February 17, 4:40 pm

Problem A of Hwk III is now up on the Web. I will probably put Problem B there tomorrow.

I am grading Quiz 4 now.

Friday, February 16, 10:50 am

Happy Chinese New Year!

You don't have to be Chinese to enjoy this fun holiday.

Congratulations to all Dogs!

Unfortunately, I will not be passing out red envelopes. :-)

Wednesday, February 14, 11:50 pm

In composing Quiz 4, I see it is getting a bit long. So, I will not have a problem in which you write SimPy code; sorry for the inconvenience. Note carefully, though, that I may still have questions about SimPy on the quiz.

Wednesday, February 14, 6:00 pm

Two students told me today that my blog post of Monday, February 12, 10:30 pm had said, "Make sure R is installed on your laptop for Friday's quiz." Actually, it said nothing about R, and it read "Make sure is installed on your laptop for Friday's quiz." Clearly there was a missing word -- rather than including "the 'R' word."

The missing word was "SimPy." Actually, it was in my HTML in that posting, but I messed up the link. Here is the official, correct version:

Make sure SimPy is installed on your laptop for Friday's quiz.

I believe I mentioned in class that this week's quiz would only be on Python. Anyway, that is the case; there will be no R in Friday's quiz.

Tuesday, February 13, 1:20 pm

ECS 145 news:

Monday, February 12, 10:30 pm

ECS 145 news:

Saturday, February 10, 4:45 pm

Our schedule on Friday, February 16 will be flipped. I will lecture in the discussion section time slot, 10-10:50, and Zheng will administer Quiz 4 during the lecture time slot, 3:10-4.

Thursday, February 8, 10:25 am

An alert student called to my attention the following situation. He ran the server in Sec. on CSIF machine, and then launched two clients on his laptop. It worked only for the first 5 characters, after which the clients started hanging. He said it worked fine when he put the clients on CSIF machines.

I just tried it, and confirmed what he said. I don't know the cause, other than that I've encountered various network problems on CSIF in recent weeks.

At any rate, keep in mind that our rules state that your code must work on CSIF. Thus it is not an issue here, but let me know if anything pops up.

Sunday, February 4, 12:15 am

When I e-mailed your quiz grades this afternoon, I forgot to post the solutions to our class Web page. I have now done so.

Saturday, February 3, 3:45 pm

I just posted several items to NotPiazza.html,

There appear to be some groups -- or more precisely some individual students who apparently are trying to do the assignment alone and then integrate with their group -- who are having serious trouble understanding the REAL-WORLD GOAL of this assignment. As I said today in NotPiazza.html, if you don't understand the goal, it is hopeless to try to write the code.

As you may recall, I stated in the specs,

In terms of pure coding, this is not a challenging assignment. But for most of you, it will not be easy. You will need to do a lot of planning, picturing in your mind the roles of the servers, clients and manager, and anticipating and dealing with various special cases. For many of you, you will at first be unsure of exactly what the assignment is supposed to do.

I also joked in class, "If you don't understand the specs, don't blame me!" :-) Actually, feel free to blame me if you like. :-)

But we are not in "ECS30Land" anymore. This is an advanced course, in which the instructor does not give a "Step A, Step B..." recipe for an assignment. You should have the ability to take a real-world problem, somewhat unstructured, and come up with a solution. It really matters to me that you have this ability, or develop it if you don't already have it.

Therefore I am taking the following actions.

Friday, February 2, 5:05 pm

I clarified something in the NotPiazza file.

Friday, February 2, 2:35 pm

I just added an entry to the NotPiazza file.

Thursday, February 1, 10:55 pm

A new version of OMSI, 1.2.2, is now on GitHub. I urge you to use it. (Since the server hasn't changed, Version 1.2.1 is still usable, though discouraged.)

The main change is as follows: A couple of students had accidentally clicked the CopyQtoA button, wiping out the contents of their Answer box. In the new version, CopyQtoA results in the contents of the Question box being APPENDED to the Answer box, not REPLACING the existing contents. So, now accidentally clicking CopyQtoA will be harmless, just requiring the student to delete the unwanted lines.

Be sure to TRY the new version before using it. The font size in the answer box has been reduced a bit, so make sure you have no problems seeing the characters. (If you do, please let me know.)

Thursday, February 1, 2:50 pm

An alert student pointed out that I neglected to include the port number as a second argument to dInit(). I've fixed the specs accordingly.

Thursday, February 1, 1:15 pm

I've been getting a lot of e-mail on how to do our current homework. However, the type of questions I am NOT getting may be rather telling, suggesting that most/all groups are missing a MAJOR aspect of file access.

Suppose the file x consists of


Now consider the following:

>>> f = open('x')
>>> z1 =
>>> z1
>>> z2 =
>>> z2

The entity f here is called a file pointer, because it points to the current position in the file. Of course, this is how things work generally, not just in Python (and Python calls C inside anyway), and you undoubtedly learned this in ECS 40 or equivalent. But in case you forgot, this blog post is a reminder about this highly important issue. Make sure your code addresses this point.

Wednesday, January 31, 8:30 pm

The campus e-mail spam filter problems seem to be unresolved (in spite of assurances to the contrary). If you send me e-mail and don't hear from me, please try sending with a different title etc.

Wednesday, January 31, 8:20 pm

If you wish to run some of the code in our book -- which I highly encourage -- the.tex source files for the book are in this directory. The one exception is the material threads, which is here.

Wednesday, January 31, 10:45 am

Reminder: The syllabus states, "When you submit Homework code, it is not considered valid unless it works on the Linux PCs in CSIF."

Wednesday, January 31, 9:30 am

I wrote yesteray,

All of your code [in your file] is in the form of FUNCTIONS. There is no freestanding code required in the specs, though you may wish to write some.

You may wish to place your freestanding code for a server in a separate file. That's fine; name it

If you do submit more than one file, also submit a README file that explains the role of the extra file(s).

Tuesday, January 30, 7:50 pm

Two functions that you may find useful in Homework II and should be part of your toolkit anyway are illustrated here:

>>> x = 3
>>> eval('x')
>>> exec('x += 5')
>>> x
Tuesday, January 30, 7:20 pm

I ask my TAs to dispense hints on assignments slowly, rather than tell the whole story all at once. The latter results in the students just endng up working on the coding details, no intellectual growth accrued. For that reason, I am not a fan of Piazza, and anyway, UC is having ethical problems with Piazza.

But for the purpose of Homework II, I've set up a file, NotPiazza.html, on our class Web site. In the next few days, I'll post some of the questions students ask me in e-mail about the assignment, and my responses. I already have several questions up there now.

Monday, January 30, 3:20 pm

I said yesterday, and in the homework specs, that this assignment will require a LOT of careful thought on your part. I just received an e-mail message from a strong student that proves the point. Here are a few comments that I made in response to him:

Any class programming assignment should enhance students' learning processes, and hopefully challenge the students. As I said, in this assignment the challenge in the actual coding is very small; it's the setting up of the structures that is challenging.

Monday, January 29, 10:30 pm

It is paramount to keep in mind a point made in the OMSI README file (and by me in class):

Submit your answers often. Near the end of an exam period, the network may be very busy, possibly making it difficult to get in. Each submission will overwrite the last.
Sunday, January 28, 12:20 am

I mentioned in class a point about "NAT addresses." If your Internet access is through an ISP, your computer is probably given a dynamic IP address every time it boots up. This is a "secret" address known only on your local network, and is duplicated on many other networks. For communication with the outside world, your local address gets translated to a NAT address, a fake. By translating addresses in both directions, it all works out, say when you access from home.

However, without special arrangement, this prevents you from, for instance, running a server at home that is accessed from the outside world. I said in class, though, that you should be able to access a server on one machine at home from another machine at home.

I just tried this to verify that it still works, which it does. On my Linux desktop, I ran 'ifconfig' (the command whose name I couldn't remember yesterday), and found that the desktop's IP address was I then started the server, bottom of p.78 in our book, on the desktop. Then from my Mac laptop, I ran the client, with host =, and it worked fine.

Saturday, January 27, 4:10 pm

Hwk II is now on the Web!

Saturday, January 27, 12:45 pm

In the discussion section on Friday, February 2, Zheng will give a special lecture instead of our having a quiz.

Wednesday, January 24, 11:00 am

The function sum() can be used on boolean lists, e.g.

>>> sum([True,False,True])
Wednesday, January 24, 10:40 am

The reduce() function has an optional third argument, which is the intial value to be used in the reduction process.

Wednesday, January 24, 10:10 am

You will have 50 minutes on quizzes from now on.

Tuesday, January 23, 11:35 pm

Our texbook shows how to respond to an exception, but how can one raise one? Here is an example:

>>> def f(s,t):
...   if s > t: raise ValueError('s must be <= t')
...   return s+t
>>> f(2,5)
>>> f(5,2)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
ValueError: s must be <= t
Saturday, January 20, 3:55 pm

In Problem B, dtree is specified as a character string.

Saturday, January 20, 3:30 pm

The quiz questions and solutions are in the Exams/ directory on our class Web page, in the files W18*.

Saturday, January 20, 1:25 pm

I am sending out the quiz results right now. On the whole, they were good, in fact with 15 scores of 100! Of course, not everyone did well; if you had a low score, you may wish to discuss your situation with me.

Friday, January 19, 8:35 pm

Fixed a couple of typos in Problem A.

Friday, January 19, 8:20 pm

The campus is apparently is having e-mail problems, involving an overly-aggressive spam filter setting. This has affected quite a bit of e-mail in our department. They are working on it now, but always keep in mind that you must check our blog at least once a day. I try to send an e-mail announcement each time I post to the blog, but do not rely on this.

Thursday, January 18, 9:15 pm

Most quiz problems will ask to write a function or a class, and will provide some of the code for you, including test code that, when run, will validate your code. It's like the situation in Problem A of our homework. Needless to say, do not alter the test code.

Thursday, January 18, 4:15 pm

Just to make sure everyone is clear in Problem A: The operators + and * will produce a new object of class polynom, and drv() will return such an object. E.g. with the sample code given, we'd have that

dp1 = p1.drv()
print dp1.poly
dp2 = p2.drv()
print dp2.poly

would output

[6, 6, 0]
[2, 1]

The intg() function merely returns a number.

Tuesday, January 16, 11:55 pm

In line 29, page 12, note that remove() only removes the first instance of the value. For instance:

>>> y
[5, 12, 13, 12, 8]
>>> y.remove(12)
>>> y
[5, 13, 12, 8]
Monday, January 15, 11:55 pm

To those on the waiting list: The list hasn't budged for a while now. Sadly, most of you will not be able to enroll. (And you will not be able to work in a group until such time, if any, that you are able to enroll.)

Saturday, January 13, 11:30 pm

Our class syllabus is now available.

Saturday, January 13, 1:35 pm

Problem B of the homework is now on the Web, and the assignment is complete. (You will need to read ahead, in the files/directories chapter.)

Friday, January 12, 10:45 am

I fixed a typo involving drv() in Problem A of the homework.

Thursday, January 11, 10:50 pm

Homework I will be due Monday, January 22. I am still working on writing Problem B, but I will finish that either this evening or tomorrow.

Zheng, our TA, has either contacted you or will do so soon, concerning the homework groups. The deadline for you to contact him will be this coming Monday, 1/15, and he will reply by Tuesday. Group size must be either 3 or 4. If you know people in the class and wish to form your own group, let Zheng know; if you wish him to place you into a group, then indicate this.

Thursday, January 11, 7:45 pm

Something happened on pc28, not sure what. I am now running the server on pc36, port 2000.

Thursday, January 11, 2:55 pm

In the programming assignments and quizzes, you are not allowed to use modules or packages not in our textbook.

Thursday, January 11, 7:55 am

When you hit the Submit button in OMSI, wait for the confirmation window to pop up before htting any other button.

Wednesday, January 10, 10:30 pm

Some students are a little confused on the Extra Credit offer. The EC comes from successfully running OMSI on the quiz this Friday. The server we have running now on pc28 is there to give you a chance to practice, so as to ensure that Friday's quiz will go smoothly for you and you receive the EC associated with that quiz.

Wednesday, January 10, 9:00 pm

I will be placing the full Syllabus on our Web page in a day or so. It will tell you how to submit homework, etc.

Wednesday, January 10, 6:20 pm

Please see this document on seeking coding help.

Tuesday, January 9, 9:40 pm

The first problem of Homework I is now on our class Web page .

Tuesday, January 9, 9:25 pm

In testing OMSI on your machine, make sure you can RUN the code in a problem. This will be REQUIRED on Friday.

Tuesday, January 9, 4:15 pm

Correction: The server is running on pc28, not pc29.

Tuesday, January 9, 10:35 am

My office hours will be W 4:30-6:30.

Tuesday, January 9, 10:30 am

I am running the OMSI server on pc29, port 1919, and Zheng will restart it there Wednesday and Thursday mornings. (CSIF reboots each night.) The questions file includes an R problem and no gcc problem (we will not be using the latter). Please make SURE to test this by Friday morning's discussion section.

Tuesday, January 9, 12:40 am

Also: Make sure you can get onto the Internet with your machine from campus.

Monday, January 8, 9:25 pm

Please make absolutely SURE that you heed the e-mail message of Jan. 3, which stated:

You must have R and Python installed on the laptop, making sure that the search path issues discussed in the file are resolved.

In other words, make sure that R and Python are in your search path, so that e.g. you can just type "R" into a terminal window to run R.

I've pushed a new Questions.txt file to the OMSI package, which has an R example.

Monday, January 8, 7:25 pm

Please note again that ALL official ECS 145 messages will be posted to the blog.

Monday, January 8, 7:15 pm

Whenever you send e-mail to me, please include '[ecs 145]' in the Subject line, to make sure your message doesn't get lost in the ocean of mail I receive.