From b7c5dbe10ad9c00cab161552f3514b2f14a75561 Mon Sep 17 00:00:00 2001 From: Olexandr Konovalov Date: Tue, 2 Apr 2024 15:36:58 +0100 Subject: [PATCH] Add changes by Michael Stanway (April 2023) Attempt to do PR #50 properly. --- Category.m | 23 ++++++++++++++--------- Contour.m | 5 ----- ContourFactory.m | 11 ++++++----- NetworkFactory.m | 8 ++++++-- tst/network_test.m | 2 +- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Category.m b/Category.m index 406584c..59db29d 100644 --- a/Category.m +++ b/Category.m @@ -1,20 +1,23 @@ classdef Category % Represents a category of tonal waveforms. % Contains methods for adding contours and calculating - % how much a given contour matches others in this category. + % how much a given contour matches others in this category, as well + % as updating the category with a new contour or removing the contour + % from a category. properties - reference % The average of all contours in the category; - % this is what prospective members are compared to - size % The number of contours in this category + average_cont % The average of all contours in the category; + % this is what new contours are compared to. + num_conts % The number of contours which have already been categorised into this category end methods - function cat = Category(size, reference) - % Construct a new category from the given array, which must - % contain at least one contour - cat.size = size; - cat.reference = reference; + function cat = category(average_cont, numConts) + % Construct a category object. If numConts drops to be below + % zero, the category will need to be deleted from the network + % since it no longer contains any contours + cat.numConts = numConts; + cat.average_cont = average_cont; end function val = compare(cat, contour) @@ -22,6 +25,8 @@ % Compare a given contour object with the reference contour and % return a percentage match value % TODO + + % Incorporate the code from ARTwarp_Calculate_Match end function cat = add(cat, contour) diff --git a/Contour.m b/Contour.m index e066f49..a68985e 100644 --- a/Contour.m +++ b/Contour.m @@ -1,8 +1,3 @@ -% This class represents an abstraction of a tonal waveform -% Using ContourFactory, a dataset can be read into ARTwarp and turned into -% these base units (individual contours), which are then used by the -% neural network. - classdef Contour % Represents a single tonal waveform % Holds the raw frequency values as well as extrapolated variables diff --git a/ContourFactory.m b/ContourFactory.m index d253ecd..f0922de 100644 --- a/ContourFactory.m +++ b/ContourFactory.m @@ -1,15 +1,16 @@ -% A factory to import contour objects from a directory containing a dataset -% Ideally, this file should be ignored and only the created Contour objects -% interacted with. -% Datasets can contain both CSV and CTR files +% A factory to construct an object containing all the contours from within +% the data directory (this directory may contain both ctr and csv files) classdef ContourFactory methods (Static) function contours_shuffled = load_contours(varargin) + % Loads all of the contours from the directory and then + % shuffles them + if length(varargin) == 1 dir_path = varargin{1}; else - dir_path = cd + "/Test_Data"; % temporarily the subdirectory ./Test_Data + dir_path = cd + "/BrazilData"; % temporarily the subdirectory ./Test_Data end % path = uigetdir('Select the folder containing the contour files') % loads folder contours = [ ContourFactory.getCSV(dir_path), ContourFactory.getCTR(dir_path) ]; diff --git a/NetworkFactory.m b/NetworkFactory.m index e5a9b51..138d0c6 100644 --- a/NetworkFactory.m +++ b/NetworkFactory.m @@ -1,5 +1,5 @@ classdef NetworkFactory - % A factory to initialise the network to be used within an ARTwarp run. + % Summary of this class goes here % Detailed explanation goes here methods (Static) @@ -9,9 +9,13 @@ net = Network(weights); end + function load_network % Load a saved network - % TODO: no idea how we would store networks + % This will need to include: + % Weights of each category + % Number of whistles that were previously contained + % in a category end function net = run_categorisation(network, contours, parameters) diff --git a/tst/network_test.m b/tst/network_test.m index eacde1b..f1602f0 100644 --- a/tst/network_test.m +++ b/tst/network_test.m @@ -15,4 +15,4 @@ assert(isequal(network.categories(network.num_categories), cat), "Problem with adding category."); % Further tests can be added after compare function in Category.m has been -% implemented \ No newline at end of file +% implemented