more silly

main
Brett 2024-10-07 19:29:03 -04:00
parent 1a8f828975
commit b58bb4c695
5 changed files with 208 additions and 193 deletions

View File

@ -1,130 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="CMakePresetLoader">{
&quot;useNewFormat&quot;: true
}</component>
<component name="CMakeReloadState">
<option name="reloaded" value="true" />
</component>
<component name="CMakeRunConfigurationManager">
<generated>
<config projectName="COSC-4P80-Assignment-1" targetName="BLT" />
<config projectName="COSC-4P80-Assignment-1" targetName="COSC-4P80-Assignment-1" />
</generated>
</component>
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" />
<configuration PROFILE_NAME="Release" ENABLED="true" CONFIG_NAME="Release" />
<configuration PROFILE_NAME="RelWithDebInfo" ENABLED="true" CONFIG_NAME="RelWithDebInfo" />
<configuration PROFILE_NAME="RelWithDebInfo Addrsan" ENABLED="true" CONFIG_NAME="RelWithDebInfo" GENERATION_OPTIONS="-G Ninja -DENABLE_ADDRSAN=ON" />
<configuration PROFILE_NAME="RelWithDebInfo Clang" ENABLED="true" CONFIG_NAME="RelWithDebInfo" TOOLCHAIN_NAME="Clang" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="c26429cb-3f2d-4b3c-a3dd-031e70b9aeae" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/src/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="clangTidyViaClangd" value="false" />
<option name="formatViaClangd" value="false" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectApplicationVersion">
<option name="ide" value="CLion" />
<option name="majorVersion" value="2024" />
<option name="minorVersion" value="1.3" />
<option name="productBranch" value="Classic" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 5
}</component>
<component name="ProjectId" id="2mH5CM5ppMWsphz4G4xP4A28USH" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;CMake Application.COSC-4P80-Assignment-1.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;RunOnceActivity.readMode.enableVisualFormatting&quot;: &quot;true&quot;,
&quot;cf.first.check.clang-format&quot;: &quot;false&quot;,
&quot;cidr.known.project.marker&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/brett/Documents/code/c++/BLT_dev/BLT&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;CPPToolchains&quot;,
&quot;structure.view.defaults.are.configured&quot;: &quot;true&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}</component>
<component name="RunManager" selected="CMake Application.COSC-4P80-Assignment-1">
<configuration default="true" type="CLionExternalRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true">
<method v="2">
<option name="CLION.EXTERNAL.BUILD" enabled="true" />
</method>
</configuration>
<configuration name="BLT" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="COSC-4P80-Assignment-1" TARGET_NAME="BLT" CONFIG_NAME="Debug">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="COSC-4P80-Assignment-1" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="COSC-4P80-Assignment-1" TARGET_NAME="COSC-4P80-Assignment-1" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="COSC-4P80-Assignment-1" RUN_TARGET_NAME="COSC-4P80-Assignment-1">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="CMake Application.COSC-4P80-Assignment-1" />
<item itemvalue="CMake Application.BLT" />
</list>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="c26429cb-3f2d-4b3c-a3dd-031e70b9aeae" name="Changes" comment="" />
<created>1726720532743</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1726720532743</updated>
<workItem from="1726720533749" duration="20189000" />
<workItem from="1727116071317" duration="39656000" />
<workItem from="1727648722710" duration="1807000" />
<workItem from="1727806367161" duration="2606000" />
<workItem from="1727823589121" duration="4802000" />
<workItem from="1728063301012" duration="9392000" />
<workItem from="1728077207859" duration="2250000" />
<workItem from="1728089514014" duration="3711000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VCPKGProject">
<isAutomaticCheckingOnLaunch value="false" />
<isAutomaticFoundErrors value="true" />
<isAutomaticReloadCMake value="true" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />
<select />
</component>
</project>

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
project(COSC-4P80-Assignment-1 VERSION 0.0.22)
project(COSC-4P80-Assignment-1 VERSION 0.0.23)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

0
build.sh Executable file → Normal file
View File

0
run.sh Executable file → Normal file
View File

View File

@ -9,9 +9,6 @@
#include <blt/parse/argparse.h>
#include <a1.h>
constexpr blt::u32 num_values_part_a = 3;
constexpr blt::u32 num_values_part_c1 = 4;
constexpr blt::u32 num_values_part_c2 = 7;
constexpr blt::u32 input_vec_size = 5;
constexpr blt::u32 output_vec_size = 4;
@ -46,22 +43,19 @@ struct correctness_t
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
[[nodiscard]] ping_pong run_step_from_inputs() const
{
auto out = (input * weights);
return {weights, (out * weights.transpose()).bipolar(), out.bipolar()};
// return {weights, (output * weights.transpose()).bipolar(), input * weights};
}
[[nodiscard]] ping_pong pong() const
[[nodiscard]] ping_pong run_step_from_outputs() const
{
return run_step();
auto in = (output * weights.transpose());
return {weights, in.bipolar(), (in * weights).bipolar()};
}
[[nodiscard]] const input_t& get_input() const
@ -115,37 +109,6 @@ class executor
BLT_TRACE_STREAM << "Weight Matrix: \n" << weights << "\n";
}
void print_crosstalk_table()
{
using namespace blt::logging;
std::vector<std::string> lines;
lines.resize(inputs.size() + 2);
std::vector<output_t> crosstalk_data;
crosstalk_data.resize(outputs.size());
for (auto [k, data] : blt::enumerate(inputs))
(lines[k] += "Input ") += std::to_string(k) += ": | ";
for (auto [i, c] : blt::enumerate(crosstalk_data))
{
for (auto [k, data] : blt::in_pairs(inputs, outputs).enumerate())
{
if (i == k)
continue;
auto [a, b] = data;
(((lines[k] += "b=") += to_string_stream(b.vec_from_column_row()) += ",a=") += to_string_stream(
a.normalize().vec_from_column_row()) += ",cos=") += to_string_stream(
a.normalize() * inputs[i].normalize().transpose()) += " |";
c += (b * (a.normalize() * inputs[i].normalize().transpose()));
}
}
for (const auto& line : lines)
BLT_TRACE_STREAM << line << "\n";
}
[[nodiscard]] std::vector<output_t> crosstalk() const
{
std::vector<output_t> crosstalk_data;
@ -153,13 +116,36 @@ class executor
for (auto [i, c] : blt::enumerate(crosstalk_data))
{
if (print_latex)
{
if (i == 0)
std::cout << "\\hline\nInput " << i + 1 << " & & Cos & Output Vector & Crosstalk Vector \\\\\n\\hline\\hline\n";
else
std::cout << "Input " << i + 1 << " & & & & \\\\\n\\hline\\hline\n";
}
for (auto [k, data] : blt::in_pairs(inputs, outputs).enumerate())
{
if (i == k)
continue;
auto [a, b] = data;
c += (b * (a.normalize() * inputs[i].normalize().transpose()));
auto cos = a.normalize() * inputs[i].normalize().transpose();
auto this_talk = b * cos;
c += this_talk;
if (print_latex)
{
std::cout << "& Input " << k + 1 << " & " << cos << " & ";
print_vec_square(std::cout, b.vec_from_column_row());
std::cout << " & ";
print_vec_square(std::cout, this_talk.vec_from_column_row());
std::cout << "\\\\\n\\hline\n";
}
}
if (print_latex)
{
std::cout << "\\hline\n\\multicolumn{5}{|c|}{Total Vector: ";
print_vec_square(std::cout, c.vec_from_column_row());
std::cout << "}\\\\\n\\multicolumn{5}{|c|}{Total Crosstalk: " << c.magnitude() << "} \\\\\n\\hline\\hline\n";
}
}
@ -181,7 +167,7 @@ class executor
BLT_TRACE("Total Crosstalk: %f", total_talk);
}
void execute()
void execute_input()
{
steps.clear();
std::vector<ping_pong> initial_pings;
@ -196,7 +182,27 @@ class executor
std::vector<ping_pong> next_pongs;
next_pongs.reserve(prev.size());
for (auto& ping : prev)
next_pongs.emplace_back(ping.pong());
next_pongs.emplace_back(ping.run_step_from_inputs());
steps.emplace_back(std::move(next_pongs));
} while (steps.rbegin()[0] != steps.rbegin()[1]);
}
void execute_output()
{
steps.clear();
std::vector<ping_pong> initial_pings;
initial_pings.reserve(outputs.size());
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<ping_pong> next_pongs;
next_pongs.reserve(prev.size());
for (auto& ping : prev)
next_pongs.emplace_back(ping.run_step_from_outputs());
steps.emplace_back(std::move(next_pongs));
} while (steps.rbegin()[0] != steps.rbegin()[1]);
}
@ -209,26 +215,12 @@ class executor
do
{
current = next;
next = current.run_step();
next = current.run_step_from_inputs();
// run until stability
} while (current != next);
return next.get_input();
}
void print_execution_summary()
{
using namespace blt::logging;
for (auto [i, data] : blt::zip(inputs, outputs, steps.back()).enumerate())
{
auto& [input_data, output_data, ping_ping] = data;
BLT_TRACE_STREAM << (input_data == ping_ping.get_input() ? ansi::make_color(ansi::GREEN) : ansi::make_color(ansi::RED))
<< "[Input: " << std::to_string(i) << "]: " << (input_data == ping_ping.get_input() ? "Passed" : "Failed") << "\n";
BLT_TRACE_STREAM << (output_data == ping_ping.get_output() ? ansi::make_color(ansi::GREEN) : ansi::make_color(ansi::RED))
<< "[Output: " << std::to_string(i) << "]: " << (output_data == ping_ping.get_output() ? "Passed" : "Failed")
<< "\n";
}
}
[[nodiscard]] correctness_t correctness() const
{
correctness_t results;
@ -263,6 +255,139 @@ class executor
static_cast<double>(data.correct_input + data.correct_output + data.incorrect_input + data.incorrect_output));
}
void print_execution_results_latex_no_intermediates()
{
std::cout << "\\begin{longtable}{||";
for (blt::size_t i = 0; i < 4; i++)
std::cout << "c|";
std::cout << "|}\n\t\\hline\n";
std::cout << "\tType & Input Vectors & Result Vectors & Result\\\\\n\t\\hline\\hline\n";
std::vector<std::string> input_lines;
std::vector<std::string> output_lines;
input_lines.resize(inputs.size());
output_lines.resize(outputs.size());
for (auto [i, is] : blt::enumerate(input_lines))
(is += "Input ") += std::to_string(i + 1);
for (auto [i, os] : blt::enumerate(output_lines))
(os += "Output ") += std::to_string(i + 1);
for (const auto& step : steps)
{
for (auto [idx, pong] : blt::enumerate(step))
{
if (!(idx == 0 || idx == step.size()-1))
continue;
auto& is = input_lines[idx];
auto& os = output_lines[idx];
is += " & ";
os += " & ";
std::stringstream stream;
print_vec_square(stream, pong.get_input().vec_from_column_row());
is += stream.str();
stream = {};
print_vec_square(stream, pong.get_output().vec_from_column_row());
os += stream.str();
}
}
auto result = steps.back();
for (auto [idx, ping] : blt::zip(result, inputs, outputs).enumerate())
{
auto [pong, input, output] = ping;
auto& is = input_lines[idx];
auto& os = output_lines[idx];
is += " & ";
os += " & ";
if (pong.get_input() == input)
is += "Correct";
else
is += "Incorrect";
if (pong.get_output() == output)
os += "Correct";
else
os += "Incorrect";
}
for (auto [is, os] : blt::in_pairs(input_lines, output_lines))
{
std::cout << '\t' << is << " \\\\\n\t\\hline\n";
std::cout << '\t' << os << " \\\\\n\t\\hline\n";
}
std::cout << "\t\\caption{}\n";
std::cout << "\t\\label{tbl:}\n";
std::cout << "\\end{longtable}\n";
}
void print_execution_results_latex()
{
std::cout << "\\begin{longtable}{||";
for (blt::size_t i = 0; i < steps.size() + 3; i++)
std::cout << "c|";
std::cout << "|}\n\t\\hline\n";
std::cout << "\tType & Input Vectors & \\multicolumn{" << steps.size() - 2
<< "}{|c|}{Intermediate Vectors} & Result Vectors & Result\\\\\n\t\\hline\\hline\n";
std::vector<std::string> input_lines;
std::vector<std::string> output_lines;
input_lines.resize(inputs.size());
output_lines.resize(outputs.size());
for (auto [i, is] : blt::enumerate(input_lines))
(is += "Input ") += std::to_string(i + 1);
for (auto [i, os] : blt::enumerate(output_lines))
(os += "Output ") += std::to_string(i + 1);
for (const auto& step : steps)
{
for (auto [idx, pong] : blt::enumerate(step))
{
auto& is = input_lines[idx];
auto& os = output_lines[idx];
is += " & ";
os += " & ";
std::stringstream stream;
print_vec_square(stream, pong.get_input().vec_from_column_row());
is += stream.str();
stream = {};
print_vec_square(stream, pong.get_output().vec_from_column_row());
os += stream.str();
}
}
auto result = steps.back();
for (auto [idx, ping] : blt::zip(result, inputs, outputs).enumerate())
{
auto [pong, input, output] = ping;
auto& is = input_lines[idx];
auto& os = output_lines[idx];
is += " & ";
os += " & ";
if (pong.get_input() == input)
is += "Correct";
else
is += "Incorrect";
if (pong.get_output() == output)
os += "Correct";
else
os += "Incorrect";
}
for (auto [is, os] : blt::in_pairs(input_lines, output_lines))
{
std::cout << '\t' << is << " \\\\\n\t\\hline\n";
std::cout << '\t' << os << " \\\\\n\t\\hline\n";
}
std::cout << "\t\\caption{}\n";
std::cout << "\t\\label{tbl:}\n";
std::cout << "\\end{longtable}\n";
}
void print_execution_results()
{
using namespace blt::logging;
@ -417,9 +542,23 @@ void part_a()
blt::log_box_t box(BLT_TRACE_STREAM, "Part A", 8);
executor cute(part_a_inputs, part_a_outputs);
cute.execute();
cute.print_weights();
std::cout << "\n";
BLT_TRACE("Running from inputs:");
cute.execute_input();
cute.print_execution_results();
cute.print_correctness();
if (print_latex)
cute.print_execution_results_latex();
std::cout << "\n";
BLT_TRACE("Running from outputs:");
cute.execute_output();
cute.print_execution_results();
cute.print_correctness();
if (print_latex)
cute.print_execution_results_latex();
}
void part_b()
@ -434,14 +573,20 @@ void part_c()
{
blt::log_box_t box(BLT_TRACE_STREAM, "Part C", 8);
executor cute(part_c_1_inputs, part_c_1_outputs);
cute.execute();
cute.execute_input();
cute.print_execution_results();
cute.print_correctness();
cute.print_crosstalk();
if (print_latex)
cute.print_execution_results_latex_no_intermediates();
BLT_TRACE("--- { Part C with 3 extra pairs } ---");
executor cute2(part_c_2_inputs, part_c_2_outputs);
cute2.execute();
cute2.execute_input();
cute2.print_execution_results();
cute2.print_correctness();
cute2.print_crosstalk();
if (print_latex)
cute2.print_execution_results_latex_no_intermediates();
}
blt::size_t hdist(const input_t& a, const input_t& b)