Assignment 8, due Mar 25

Solutions

Part of the homework for CS:2820, Spring 2016
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: Look at Machine Problem 4, and note the need to compute an interesting mathematical function involving exponentiation.

    a) What Java library class or package supports the the exponentiation operation this requires? (0.2 points)

    Class Math

    b) Is it a class or a package? (0.2 points)

    It is a class.

    c) Do you have to import this class or package prior to using its members, or is the import implicit? (0.2 points)

    It is implicit (class Math is part of the java.lang package).

    d) Is there an alternative class or package that can do the same thing? (0.2 points)

    Class StrictMath does all the same things.

    (Why the difference? Math may be faster, while StrictMath guarantees exactly the same results no matter what machine you operate on. Given that real functions such as exponentiation and the trig functions are computed by approximation algorithms, these may differ slightly.)

    e) Give the Java code for corresponding to the assignment statement in the machine problem assignment. You are free to use stupid variable names like t1 where the original code said t1. (Later, in your solution to the machine problem, you might want to re-think some of these names.) (0.2 points)

    v2 = (v1 * (float)Math.exp( t1 - t2 )) + s;
    

    Note that the Math.exp function is double precision, while we are (perhaps foolishly) using single precision floating point. Therefore, we need to explicitly discard precision with the (float) cast. The widening of the argument to Math.exp() does not need casting because Java widens without complaining.

  2. Background Some authors of simulation code use events (or event service routines) as their primary coding tools. So, instead of calling a method to do something now, they schedule an event at the current time. In our neuron network simulator, this would lead to something like the following (we're ignoring secondary synapses here):

    a) Which of the actions listed above must involve scheduling new events and cannot be done by simple method calls. (0.5 points)

    • Synapse is kicked at time t. Schedule this synapse to fire at time t+delay.

    b) Which of the above do not even necessarily involve different methods but could be folded together into the same method of the same object. (0.5 points)

    • Neuron is kicked at time t. Adjust the voltage on that neuron, and if the result is that the neuron should fire, schedule this neuron to fire at time t.
    • Neuron fires at time t. Schedule each outgoing synapse to be kicked at time t.

    The rules used to solve the above: If an event causes another at a later time, event scheduling must be involved. If one event causes another at the same time, and the code for the two are naturally embedded in the same class and operate on the same object, then they can be combined into one method.

  3. Background: If you wanted to extend the outline of the simulation program presented in problem 2 to include secondary synapses, you would have to make some changes in order to account for the fact that when a secondary synapse fires, the message is delivered to a primary synapse.

    a) Which bullet points from problem 2 would you need to change to account for the existence of secodary synapses? Give the necessary change(s). (0.5 points)

    • Synapse fires at time t. Schedule its destination neuron to be kicked at time t.
    becomes
    • Synapse fires at time t. Schedule its destination neuron or synapse (depending on the subclass of this synapse) to be kicked at time t.

    b) What bullet point(s) would you need to add to account for the existence of secondary synapses? (0.5 points)

    • Synapse is kicked (by a secondary synapse) at time t. Adjust its strength accordingly.