2024-11-04 20:03:12 -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_NEURON_H
|
|
|
|
#define COSC_4P80_ASSIGNMENT_3_NEURON_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <assign3/fwdecl.h>
|
|
|
|
#include "blt/std/types.h"
|
|
|
|
#include <assign3/functions.h>
|
|
|
|
|
|
|
|
namespace assign3
|
|
|
|
{
|
|
|
|
class neuron_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit neuron_t(blt::size_t dimensions, Scalar x, Scalar y): x_pos(x), y_pos(y)
|
|
|
|
{
|
|
|
|
data.resize(dimensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
neuron_t& randomize(blt::size_t seed);
|
|
|
|
|
2024-11-06 01:22:52 -05:00
|
|
|
neuron_t& update(const std::vector<Scalar>& new_data, Scalar dist, Scalar eta);
|
2024-11-04 20:03:12 -05:00
|
|
|
|
2024-11-16 18:13:17 -05:00
|
|
|
static Scalar distance(distance_function_t* dist_func, const neuron_t& n1, const neuron_t& n2);
|
2024-11-06 01:22:52 -05:00
|
|
|
|
|
|
|
[[nodiscard]] Scalar dist(const std::vector<Scalar>& X) const;
|
2024-11-04 20:03:12 -05:00
|
|
|
|
2024-11-18 00:53:32 -05:00
|
|
|
neuron_t& set_activation(Scalar act)
|
|
|
|
{
|
|
|
|
activation = act;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void activate(Scalar act)
|
|
|
|
{ activation += act; }
|
|
|
|
|
|
|
|
[[nodiscard]] const std::vector<Scalar>& get_data() const
|
2024-11-04 20:03:12 -05:00
|
|
|
{ return data; }
|
|
|
|
|
2024-11-18 00:53:32 -05:00
|
|
|
[[nodiscard]] Scalar get_x() const
|
2024-11-04 20:03:12 -05:00
|
|
|
{ return x_pos; }
|
|
|
|
|
2024-11-18 00:53:32 -05:00
|
|
|
[[nodiscard]] Scalar get_y() const
|
2024-11-04 20:03:12 -05:00
|
|
|
{ return y_pos; }
|
|
|
|
|
2024-11-18 00:53:32 -05:00
|
|
|
[[nodiscard]] Scalar get_activation() const
|
|
|
|
{ return activation; }
|
|
|
|
|
2024-11-06 01:22:52 -05:00
|
|
|
private:
|
2024-11-04 20:03:12 -05:00
|
|
|
Scalar x_pos, y_pos;
|
2024-11-18 00:53:32 -05:00
|
|
|
Scalar activation = 0;
|
2024-11-04 20:03:12 -05:00
|
|
|
std::vector<Scalar> data;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //COSC_4P80_ASSIGNMENT_3_NEURON_H
|