COSC-4P80-Assignment-3/include/assign3/som.h

77 lines
2.6 KiB
C
Raw Normal View History

2024-11-06 01:22:52 -05:00
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef COSC_4P80_ASSIGNMENT_3_SOM_H
#define COSC_4P80_ASSIGNMENT_3_SOM_H
#include <assign3/array.h>
#include <assign3/file.h>
#include <assign3/functions.h>
namespace assign3
{
class som_t
{
public:
2024-11-18 16:49:56 -05:00
som_t(const data_file_t& file, blt::size_t width, blt::size_t height, blt::size_t max_epochs, distance_function_t* dist_func,
2024-11-18 19:50:46 -05:00
topology_function_t* topology_function, shape_t shape, init_t init, bool normalize);
2024-11-06 01:22:52 -05:00
blt::size_t get_closest_neuron(const std::vector<Scalar>& data);
Scalar find_closest_neighbour_distance(blt::size_t v0);
2024-11-18 19:50:46 -05:00
void train_epoch(Scalar initial_learn_rate);
2024-11-06 01:22:52 -05:00
2024-11-15 19:06:12 -05:00
blt::vec2 get_topological_position(const std::vector<Scalar>& data);
2024-11-18 19:50:46 -05:00
Scalar topological_error();
void compute_neuron_activations(Scalar distance = 2, Scalar activation = 0.5);
void write_activations(std::ostream& out);
void write_topology_errors(std::ostream& out);
2024-11-18 00:53:32 -05:00
2024-11-06 01:22:52 -05:00
[[nodiscard]] const array_t& get_array() const
{ return array; }
[[nodiscard]] blt::size_t get_current_epoch() const
{ return current_epoch; }
[[nodiscard]] blt::size_t get_max_epochs() const
{ return max_epochs; }
2024-11-18 19:50:46 -05:00
[[nodiscard]] const std::vector<Scalar>& get_topological_errors() const
{ return topological_errors; }
2024-11-06 01:22:52 -05:00
private:
array_t array;
data_file_t file;
blt::size_t current_epoch = 0;
blt::size_t max_epochs;
2024-11-18 00:53:32 -05:00
distance_function_t* dist_func;
2024-11-18 19:50:46 -05:00
topology_function_t* topology_function;
std::vector<Scalar> topological_errors;
2024-11-06 01:22:52 -05:00
};
}
#endif //COSC_4P80_ASSIGNMENT_3_SOM_H