This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <termios.h> | |
| #include <time.h> | |
| #include <stdbool.h> | |
| const char BOMB = 'X'; | |
| const char EMPTY = 'E'; | |
| const char DISCOVERED = '0'; | |
| const char FLAG = 'F'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.models import Sequential | |
| from keras.layers.core import Dense | |
| from keras.optimizers import SGD | |
| import numpy as np | |
| def main(): | |
| X = np.array([[0,0],[0,1],[1,0],[1,1]]) | |
| Y = np.array([[0],[1],[1],[0]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef DEF_MATRIX | |
| #define DEF_MATRIX | |
| #include <vector> | |
| #include <iostream> | |
| /** | |
| Every method ends with "const" keyword which means that the object on which the method is called is never modified. | |
| Instead it will return a new Matrix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Matrix.h" | |
| #include <assert.h> | |
| #include <sstream> | |
| Matrix::Matrix(){} | |
| Matrix::Matrix(int height, int width) | |
| { | |
| this->height = height; | |
| this->width = width; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <fstream> | |
| void loadTraining(const char *filename, vector<vector<double> > &input, vector<vector<double> > &output) | |
| { | |
| int trainingSize = 946; | |
| input.resize(trainingSize); | |
| output.resize(trainingSize); | |
| ifstream file(filename); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Matrix.h" | |
| Matrix X, W1, H, W2, Y, B1, B2, Y2, dJdB1, dJdB2, dJdW1, dJdW2; | |
| double learningRate; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void init(int inputNeuron, int hiddenNeuron, int outputNeuron, double rate) | |
| { | |
| learningRate = rate; | |
| W1 = Matrix(inputNeuron, hiddenNeuron); | |
| W2 = Matrix(hiddenNeuron, outputNeuron); | |
| B1 = Matrix(1, hiddenNeuron); | |
| B2 = Matrix(1, outputNeuron); | |
| W1 = W1.applyFunction(random); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <time.h> | |
| double random(double x) | |
| { | |
| return (double)(rand() % 10000 + 1)/10000-0.5; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Matrix computeOutput(vector<double> input) | |
| { | |
| X = Matrix({input}); // row matrix | |
| H = X.dot(W1).add(B1).applyFunction(sigmoid); | |
| Y = H.dot(W2).add(B2).applyFunction(sigmoid); | |
| return Y; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cmath> | |
| double sigmoid(double x) | |
| { | |
| return 1/(1+exp(-x)); | |
| } |