Objects and Concurrency Lab: Neural Network Generator: Spring 2026

Learning Objective(s)

  • Learn about simple neural networks
  • Learn to use command line arguments
  • Learn about serializable objects
  • Learn about concurrency in Java

Overview of the Program

Design and implement a neural network generator using your Neuron object.

The network must:

  • Be generated from an input file specification
  • Contain fully connected layers
  • Have one input neuron and one output neuron
  • Train using labeled data
  • Generate three similar networks with small random changes
  • Select the best performing network

Specifics

No code is provided for this lab. The program must be run from the command line.

The driver class should be called: !NeuralNetworkProgram

Constraints:

  • number_of_layers ≥ 2
  • input layer must contain exactly 1 neuron
  • output layer must contain exactly 1 neuron
  • each neuron in layer n-1 must connect to each neuron in layer n

Input

Input is to be done via command line arguments. Sample 1: training
java NeuralNetworkProgram 0 inputFile.txt 0.95 100
0 -> training, inputFile.txt -> file with names of data to traing, 0.95 -> train until 95% accurate, 100 -> or until 100 iterations
Sample 2: analyzing/testing
java NeuralNetworkProgram 1 inputFile.txt
1 -> analyzing, inputFile.txt -> file with names of data to test
  • Argument 1: flag to indicate if training or analyzing mode
    • 0 → training
    • 1 → analyzing/testing
  • Argument two: File name
    • if training (first line is the number of layers and the number of neurons per layer (other than the input and output layers which only have one neuron each)
      • 0 filename1.txt
      • 1 filename2.txt
      • 0 filename3.txt
    • If testing
      • filename1.txt
      • filename2.txt
      • filename3.txt
  • Argument three: (only if training): Desired level of accuracy
  • Argument four: (only if training): Max number of iterations allowed

If training, output is the serialized neural network in a file called "neuralnetwork.dat" If testing, the program loads "neuralnetwork.dat" and runs it on each file and reports filename and a 0 or 1.

Network Requirements

  • Each neuron in layer n-1 must connect to each neuron in layer n.
  • Training is done by copying the network and the making small random changes to the weights and thresholds.
  • The output of a neuron is either a 0 or 1 (1 if >= its threshold).
  • Weights are initially set to 1 and thresholds are initially random
  • The best of three random networks (based off the network of the previous round) is saved for the next iteration
  • An iteration is done after training on all data sets. The network (of the three) that did the best is used for the next run. That is one of the three networks for the next round, and then two slightly different networks are also used.
  • The entire network must be Serializable.

Prelab: Reading for Details

Complete the reading for detail quiz at least 24 hours ahead of time.

If you pass with a 90% you are done.

If you score less than 90%, you must take a hard copy of this lab and highlight where the answers are to the quiz and bring it to lab. The quiz questions will be reposted about 24 hours before the lab so you can do this task.

Phase 1

  • Design the program and develop a testing plan.
  • The design must include a complete UML diagram and should correctly include all major functions.
  • Develop unit tests for major components.
  • The testing plan should include unit testing and integration testing.
  • Submit a Software Design Report in only one pdf.

Phase 2

Using your graded software design report:

  • Implement the full neural network
  • Implement training
  • Implement serialization
  • Implement testing mode

Create a Software Development Report incorporating any necessary changes from the software design report.

Be sure to include detailed instructions on how to run your program, including training and testing examples.

Include statement coverage (in addition to unit testing and integration testing) in your testing report.

If you create unit test programs, for unit testing you can refer to each section in your report (no need to list input/output, but you must describe the purpose of each group of tests).

Create a zip folder containing only the following (and submit it):

  • Only one file (as a pdf) with the completed software development report
  • All the .java files needed to run the program
  • Any input files you want the grader to use
  • Any unit testing .java files

Phase 3

Modify your working Phase 2 solution to use concurrency.

  • The three similar neural networks generated during training must be evaluated concurrently.
  • The algorithm must remain the same.
  • Only the evaluation of candidate networks should be made concurrent.
  • You must implement clean concurrency
  • You must ensure:
    • Thread safety
    • Correct selection of best network
    • No race conditions

Update your Lessons Learned to include the following. This is a very important part of this phase and will be weighted appropriately

  • Explanation of your concurrency approach
  • Description of synchronization strategy
  • Discussion of any concurrency issues encountered
  • Comparison of sequential vs concurrent behavior

Optional Improvements

  • Allow different numbers of neurons per hidden layer
  • Report timing comparisons between sequential and concurrent execution

Optional improvements should only be worked on once the program is completely working.

Post Lab

  • Compare and contrast your solution to the posted solution.
  • In your writeup, indicate anything that was different between the two and comment on that.
  • Also include at least two things that you learned from the comparison.


This topic: CenterForComputing > WebHome > Syllabi > SyllabiSpring2026 > CSC221SylS2026 > CSC221S2026Lab5
Topic revision: r1 - 2026-03-03 - CathyBareiss
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback