Skip to content

Projects regarding neural networks developed during the Computational Intelligence course @cse.uoi.gr

Notifications You must be signed in to change notification settings

Zengineers/neural-networks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Neural Networks

This repo features projects revolving around neural networks developed based on the Computational Intelligence course @cse.uoi.gr.

PROJECT 1: K-Means clustering


This project implements a version of the K-Means clustering algorithm which partitions 2-dimensional points into M clusters. The algorithm is executed multiple times for different numbers of clusters. The minimum clustering error(*) is kept for each number of clusters and a respective plot is generated. Finally, a plot which shows the variation of the (minimum) clustering error per number of clusters is generated.

The project is split in three parts:

  • Random Points Generation
  • K-Means algorithm implementation
  • Experiment with multiple executions of the algorithm

Each part is executed and compiled separately. For ease of use, a shell script (compile.sh) is included which compiles all 3 parts. To execute the script (or any other program of the project) change to dir kmeans (root directory of the project). Moreover, execution rights might be required for the script. This can be done with the following command:
chmod +x compile,.sh

Developed with java 14.0.2.

(*) Clustering error: Sum of the euclidean distances of the example points from the center of the cluster they belongs to, after the algorithm has finished.

Contents


The project contains the following directories:

  1. kmeans (kmeans/kmeans) - kmeans package with the source code.
  2. data (kmeans/data) - directory with .dat files which contain the generated data.
  3. plots (kmeans/plots) - directory with the generated plots.
  4. scripts (kmeans/scripts) - gnuplot scripts which are generated and executed by the programs.

The source code has the following classes:

  1. Point: This class describes a 2-dimensional point.
  2. Cluster: This class describes a cluster of the K-Means algorithm.
  3. Loader: This class is responsible for loading data from a file. It perfoms no error-checking and assumes the data in the file are in proper format.
  4. Plotter: This class is responsible for plotting. It writes data to .dat files, writes gnuplot scripts and runs them to plot graphs for the example points, the resulting clusters and the experiment results.
  5. PointsGenerator: This class is responsible for generating random points in 2D space. It exports the created points in the form of a plot and .dat file.
  6. KMeans: This class implements the K-Means algorithm. It exports the results in the form of a plot and .dat file.
  7. Experiment: This class executes multiple experiments using the K-Means algorithm with different numbers of clusters (M) (3,5,7,9,11 and 13). It saves the minimun clustering error for each number of clusters and produces results in the form a plot with (min) clustering error per number of clusters.

Usage


  • Random Points Generation

    compile command:
    (navigate to kmeans)
    javac kmeans/PointsGenerator.java

    run command:
    (navigate to kmeans)
    java kmeans/PointsGenerator

    outputs:
    "data/examples.dat": data file with randomly generated example points.
    "plots/examples.png": plot with the randomly generated example points.
    "scripts.p/examples.p": gnuplot script which generates the plot of the example points.

  • K-Means algorithm implementation

    compile command:
    (navigate to kmeans)
    javac kmeans/KMeans.java

    run command:
    (navigate to kmeans)
    java kmeans/KMeans <number of clusters>

    <number of clusters>: number of clusters the algorithm should create.

    run example for 9 clusters:
    (navigate to kmeans)
    java kmeans/KMeans 9

    outputs:
    "plots/clusters.png": plot with the resulting clusters of the algorithm. The plot showcases the center of each cluster and the members of each cluster in different color.
    "data/cluster_*_members.dat" where * is the number of the cluster: data files containing the members of each cluster.
    "data/cluster_centers.dat": data file containing the centers of the different clusters.
    "scripts/plot.p": gnuplot script which generates the clusters plot.

  • Experiment with multiple executions of the algorithm

    compile command:
    (navigate to kmeans)
    javac kmeans/Experiment.java

    run command:
    (navigate to kmeans)
    java kmeans/Experiment <reps>

    <reps>: number of times the K-Means algorithm is executed for each number of clusters.

    run example for 20 reps:
    (navigate to kmeans)
    java kmeans/Experiment 20

    outputs:
    "plots/clusters_3.png": plot for the execution of 3 clusters with minimum clustering error.
    "plots/clusters_5.png": plot for the execution of 5 clusters with minimum clustering error.
    "plots/clusters_7.png": plot for the execution of 7 clusters with minimum clustering error.
    "plots/clusters_9.png": plot for the execution of 9 clusters with minimum clustering error.
    "plots/clusters_11.png": plot for the execution of 11 clusters with minimum clustering error.
    "plots/clusters_13.png": plot for the execution of 13 clusters with minimum clustering error.
    "plots/results.png": plot with the (min) clustering error per number of clusters. "data/experiment_results.dat": data file with the (min) clustering error per number of clusters.
    "scripts/results.p": gnuplot script which generates the results plot.

    notes:
    The Experiment class loads the example data from the "data/examples.dat" file.
    The Experiment class also uses the following files to plot the executions of different num. of clusters:
    "scripts/plot.p"
    "data/cluster_*_members.dat" where * is the number of the cluster
    "data/cluster_centers.dat"
    These files are rewritten multiple times during the experiments execution.
    Therefore they are not particularly useful as they will only contain the information of the last execution.

About

Projects regarding neural networks developed during the Computational Intelligence course @cse.uoi.gr

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •