Skip to content

navarhontes/Simple-Perceptron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple-Perceptron

Written for 2023 Summer CSC207H1Y (Software Design) at the University of Toronto. Assignment: AI-Assisted Design Exercise. The code written here is based on code generated by ChatGPT. My understanding is that the goal of this exercise was to give the students a better understanding of the strengths and weaknesses of ChatGPT as a programming tool. I did a simple linear perceptron purely because this assignment seemed to allow us to write very simple programs and it seemed fitting to do an early ML algorithm for the AI-assisted design exercise.

This course emphasizes Clean Architecture and SOLID design principles, hence the arguable overengineering.

What is implemented?

A simple perceptron. In this repository, ChatGPT and I have implemented a very basic algorithm for learning a linear binary classifier. It can handle multi-dimensional inputs, but only single-dimension outputs.

Features

  • Simple implementation of a perceptron algorithm.
  • Text interface
  • Supports two different labeling conventions: {-1, +1} and {0, 1}.

Known bugs and code smells

  • Lets you put down multiple integers at a time on the same line when it only takes one. In those cases, it just takes the first one.
  • The method for handling user 'vector' input should be rewritten.
  • I had considered writing the PerceptronFacade class as a façade for even smaller components to better fulfill the single responsibility principle. I haven't done so because the class is fairly small, we're not implementing many training algorithms, and I'd need to either pass a large number of parameters or copy many instance attributes which introduces a new code smell.
  • I think there's a CA violation in TextInterface.chooseLabellingConvention(), but I left it there because I felt that it was actually more easily extensible there since I'd otherwise need to make changes in multiple layers every time I wanted to support new conventions; not only would TextInterface need to be changed to give the user a new option, but PerceptronFacade would also need either make the new LabellingStrategy object or make what seems to be an unnecessary factory since there are only two at the moment.

Design Patterns

Strategy: used to support multiple label types

Dependency injection: PerceptronFacade uses LabellingStrategy but has no direct dependency on the classes that implement it.

Façade: PerceptronFacade delegates to Perceptron and LabellingStrategy. It could delegate more, but there are diminishing returns.

Usage

Prerequisites

  • Java Development Kit (JDK) 8 or later.

Installation and running this program

  1. Clone this repository
  2. Navigate to the project directory (the folder is most likely titled Simple-Perceptron)
  3. Compile TextInterface.java from this folder. Command line: javac src/TextInterface.java
  4. Run the program: java src/TextInterface

Extending the Program

The Perceptron Program is designed to be extensible. To add new labeling strategies:

  1. Create a new LabelingStrategy implementation by implementing the LabelingStrategy interface.
  2. Modify the Perceptron class or create new classes as needed to accommodate the new feature.
  3. Update the TextInterface class if necessary, to expose the new functionality to clients.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages