diff --git a/.idea/workspace (conflicted copy 2024-10-03 130251).xml b/.idea/workspace (conflicted copy 2024-10-03 130251).xml
new file mode 100644
index 0000000..71433f8
--- /dev/null
+++ b/.idea/workspace (conflicted copy 2024-10-03 130251).xml
@@ -0,0 +1,119 @@
+
+
+
+
+
+ {
+ "useNewFormat": true
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 5
+}
+
+
+
+
+
+ {
+ "keyToString": {
+ "CMake Application.COSC-4P80-Assignment-1.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.cidr.known.project.marker": "true",
+ "RunOnceActivity.readMode.enableVisualFormatting": "true",
+ "cf.first.check.clang-format": "false",
+ "cidr.known.project.marker": "true",
+ "git-widget-placeholder": "main",
+ "last_opened_file_path": "/home/brett/Documents/code/c++/BLT_dev/BLT",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "CPPToolchains",
+ "vue.rearranger.settings.migration": "true"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1726720532743
+
+
+ 1726720532743
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 89b1de3..bfc01cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
-project(COSC-4P80-Assignment-1 VERSION 0.0.16)
+project(COSC-4P80-Assignment-1 VERSION 0.0.17)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
diff --git a/include/a1.h b/include/a1.h
index 30fb813..ff638db 100644
--- a/include/a1.h
+++ b/include/a1.h
@@ -22,14 +22,20 @@
#include
#include
#include
+#include
+#include
+#include
namespace a1
{
+ template
+ using matrix_t = blt::generalized_matrix;
+
void test_math()
{
- blt::generalized_matrix input{1, -1, -1, 1};
- blt::generalized_matrix output{1, 1, 1};
- blt::generalized_matrix expected{
+ matrix_t<1, 4> input{1, -1, -1, 1};
+ matrix_t<1, 3> output{1, 1, 1};
+ matrix_t<4, 3> expected{
blt::vec4{1, -1, -1, 1},
blt::vec4{1, -1, -1, 1},
blt::vec4{1, -1, -1, 1}
@@ -41,8 +47,8 @@ namespace a1
blt::vec4 one{5, 1, 3, 0};
blt::vec4 two{9, -5, -8, 3};
- blt::generalized_matrix g1{5, 1, 3, 0};
- blt::generalized_matrix g2{9, -5, -8, 3};
+ matrix_t<1, 4> g1{5, 1, 3, 0};
+ matrix_t<1, 4> g2{9, -5, -8, 3};
BLT_ASSERT(g1 * g2.transpose() == blt::vec4::dot(one, two) && "MATH DOT FAILURE");
}
@@ -53,21 +59,8 @@ namespace a1
return i * j.transpose();
}
- template
- blt::generalized_matrix threshold(const blt::generalized_matrix& y,
- const blt::generalized_matrix& base)
- {
- blt::generalized_matrix result;
- for (blt::u32 i = 0; i < columns; i++)
- {
- for (blt::u32 j = 0; j < rows; j++)
- result[i][j] = y[i][j] > 1 ? 1 : (y[i][j] < -1 ? -1 : base[i][j]);
- }
- return result;
- }
-
- template
- blt::size_t difference(const std::array& a, const std::array& b)
+ template
+ blt::size_t difference(const std::vector& a, const std::vector& b)
{
blt::size_t count = 0;
for (const auto& [a_val, b_val] : blt::in_pairs(a, b))
@@ -78,8 +71,8 @@ namespace a1
return count;
}
- template
- bool equal(const std::array& a, const std::array& b)
+ template
+ bool equal(const std::vector& a, const std::vector& b)
{
return difference(a, b) == 0;
}
@@ -89,16 +82,12 @@ namespace a1
{
output_t output_recall = input * associated_weights;
input_t input_recall = output_recall * associated_weights.transpose();
-
-// BLT_DEBUG_STREAM << "Input: " << input.vec_from_column_row() << "\nOutput: " << output.vec_from_column_row() << '\n';
-// BLT_DEBUG_STREAM << "Recalled Input: " << a1::threshold(input_recall, input).vec_from_column_row() << "\nRecalled Output: "
-// << a1::threshold(output_recall, output).vec_from_column_row() << '\n';
return std::pair{a1::threshold(input_recall, input), a1::threshold(output_recall, output)};
}
- template
- void check_recall(const weight_t& weights, const std::array& inputs, const std::array& outputs)
+ template
+ void check_recall(const weight_t& weights, const std::vector& inputs, const std::vector& outputs)
{
for (const auto& [index, val] : blt::enumerate(inputs))
{
diff --git a/lib/blt b/lib/blt
index bfcb357..7fa4fd0 160000
--- a/lib/blt
+++ b/lib/blt
@@ -1 +1 @@
-Subproject commit bfcb35705910851a6a7466406609793bae3eb2be
+Subproject commit 7fa4fd0af29e7c9eb7c6ab1adf48cef0b6d38850
diff --git a/src/main.cpp b/src/main.cpp
index 896ba19..884eb70 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,5 @@
#include
+#include
#include
#include
#include "blt/std/assert.h"
@@ -12,10 +13,99 @@ constexpr blt::u32 num_values_part_c2 = 7;
constexpr blt::u32 input_vec_size = 5;
constexpr blt::u32 output_vec_size = 4;
-using input_t = blt::generalized_matrix;
-using output_t = blt::generalized_matrix;
+using input_t = a1::matrix_t<1, input_vec_size>;
+using output_t = a1::matrix_t<1, output_vec_size>;
using weight_t = decltype(std::declval().transpose() * std::declval());
-using crosstalk_t = blt::generalized_matrix;
+using crosstalk_t = a1::matrix_t<1, output_vec_size>;
+
+class ping_pong
+{
+ public:
+ ping_pong(weight_t weights, input_t input): weights(std::move(weights)), input(std::move(input))
+ {}
+
+ ping_pong(weight_t weights, input_t input, output_t output): weights(std::move(weights)), input(std::move(input)), output(std::move(output))
+ {}
+
+ [[nodiscard]] ping_pong run_step() const
+ {
+ auto out = input * weights;
+ return {weights, threshold(out * weights.transpose()), threshold(out)};
+ }
+
+ [[nodiscard]] ping_pong pong() const
+ {
+ return run_step();
+ }
+
+ input_t get_input()
+ {
+ return input;
+ }
+
+ output_t get_output()
+ {
+ return output;
+ }
+
+ friend bool operator==(const ping_pong& a, const ping_pong& b)
+ {
+ return a.input == b.input && a.output == b.output;
+ }
+
+ template
+ static a1::matrix_t threshold(const a1::matrix_t& y)
+ {
+ a1::matrix_t result;
+ for (blt::u32 i = 0; i < columns; i++)
+ {
+ for (blt::u32 j = 0; j < rows; j++)
+ result[i][j] = y[i][j] >= 0 ? 1 : -1;
+ }
+ return result;
+ }
+
+ private:
+ weight_t weights;
+ input_t input;
+ output_t output;
+};
+
+class executor
+{
+ public:
+ executor(weight_t weights, std::vector inputs, std::vector outputs):
+ weights(std::move(weights)), inputs(std::move(inputs)), outputs(std::move(outputs))
+ {}
+
+ void execute()
+ {
+ std::vector initial_pings;
+ for (auto [input, output] : blt::in_pairs(inputs, outputs))
+ initial_pings.emplace_back(weights, input, output);
+ steps.emplace_back(std::move(initial_pings));
+ // execute while the entries don't equal each other (no stability in the system)
+ do
+ {
+ auto& prev = steps.rbegin()[0];
+ std::vector next_pongs;
+ for (auto& ping : prev)
+ next_pongs.emplace_back(ping.pong());
+ steps.emplace_back(std::move(next_pongs));
+ } while (!(steps.rbegin()[0] == steps.rbegin()[1]));
+ }
+
+ void print_chains()
+ {
+
+ }
+
+ private:
+ weight_t weights;
+ std::vector inputs;
+ std::vector outputs;
+ std::vector> steps;
+};
// part a
input_t input_1{-1, 1, 1, 1, -1};
@@ -47,14 +137,14 @@ const weight_t weight_5 = input_5.transpose() * output_5;
const weight_t weight_6 = input_6.transpose() * output_6;
const weight_t weight_7 = input_7.transpose() * output_7;
-auto part_a_inputs = std::array{input_1, input_2, input_3};
-auto part_a_outputs = std::array{output_1, output_2, output_3};
+auto part_a_inputs = std::vector{input_1, input_2, input_3};
+auto part_a_outputs = std::vector{output_1, output_2, output_3};
-auto part_c_1_inputs = std::array{input_1, input_2, input_3, input_4};
-auto part_c_1_outputs = std::array{output_1, output_2, output_3, output_4};
+auto part_c_1_inputs = std::vector{input_1, input_2, input_3, input_4};
+auto part_c_1_outputs = std::vector{output_1, output_2, output_3, output_4};
-auto part_c_2_inputs = std::array{input_1, input_2, input_3, input_4, input_5, input_6, input_7};
-auto part_c_2_outputs = std::array{output_1, output_2, output_3, output_4, output_5, output_6, output_7};
+auto part_c_2_inputs = std::vector{input_1, input_2, input_3, input_4, input_5, input_6, input_7};
+auto part_c_2_outputs = std::vector{output_1, output_2, output_3, output_4, output_5, output_6, output_7};
const auto weight_total_a = weight_1 + weight_2 + weight_3;
const auto weight_total_c = weight_total_a + weight_4;