Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <string>
- #include <vector>
- #include <cstdlib>
- using namespace std;
- vector<vector<float>> transpose(vector<vector<float>> input){
- float input_rows = input.size();
- float input_cols = input[0].size();
- vector<vector<float>> output (input_cols, vector<float>(input_rows));
- for(short i = 0; i < input_rows;){
- for(short k = 0; k < input_cols;){
- output[k][i] = input[i][k];
- ++k;
- }
- ++i;
- }
- return output;
- }
- vector<vector<float>> dotProduct (vector<vector<float>> inputs, vector<vector<float>> weights, vector<float> biases) {
- short col_count = inputs.size();
- vector<vector<float>> output (col_count);
- for(short i = 0; i < col_count; ++i){
- short row_count = inputs[i].size();
- output[i].resize(row_count);
- for(short k = 0; k < row_count; ++k){
- output[i][k] = inputs[i][k] * weights[i][k] + biases[i];
- }
- }
- return output;
- }
- vector<vector<float>> full_dot(vector<vector<float>> inputs, vector<vector<float>> weights, vector<float> biases) {
- return dotProduct(inputs, transpose(weights), biases);
- }
- int main() {
- vector<vector<float>> inputs {
- {1.2, 3.5, 0.6, 0.91},
- {4.3, 2.1, 1.9, 0.13},
- {1.9, 1.2, 4.0, 0.20}
- };
- vector<vector<float>> weights {
- {2, 4, 6.8, 1.3},
- {3.4, 1.2, 3., 2.1},
- {4.1, 5.3, 0.9, .12}
- };
- vector<float> biases {
- 1.2, 3, 0.1, 2.1
- };
- vector<vector<float>> output = full_dot(inputs, weights, biases);
- for(char j; j < output.size(); ++j) {
- for(char k; k < output[j].size(); ++k){
- cout << output[j][k] << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement