<commit_before>#include "nn.h"

#define SIG(x) 1/(1+exp(-x))
#define SIGD(x) SIG(x)*(1-SIG(x))

using namespace std;

bool NeuralNet::load(string infile){
    ifstream filein;
    filein.open(infile);
    string instring;

    // read in network parameters
    filein >> instring;
    N_i = stoi(instring);
    filein >> instring;
    N_h = stoi(instring);
    filein >> instring;
    N_o = stoi(instring);
    cout << N_i << N_h << N_o << endl;

    weights.resize(2);
    weights[0].resize(N_i);
    for(int i = 0; i < weights[0].size(); i++){
        weights[0][i].resize(N_h);
    }
    weights[1].resize(N_h);
    for(int h = 0; h < weights[1].size(); h++){
        weights[1][h].resize(N_o);
    }

    // load weights from file
    for (int i = 0;i < N_i; i++){
        for (int h = 0; h < N_h; h++){
            filein >> instring;
            weights[0][i][h] = stod(instring);
            cout << weights[0][i][h] << ' ';
        }
        cout << endl;
    }
    for (int h = 0; h < N_h; h++){
        for (int o = 0; o < N_o; o++){
            filein >> instring;
            weights[1][h][o] = stod(instring);
            cout << weights[1][h][o]<< ' ';
        }
        cout << endl;
    }

}

bool NeuralNet::save(string outfile){

}

int main(){
    NeuralNet a;
    a.load(string("test.txt"));
    return 0;
}<commit_msg>save functionality<commit_after>#include "nn.h"

#define SIG(x) 1/(1+exp(-x))
#define SIGD(x) SIG(x)*(1-SIG(x))

using namespace std;

bool NeuralNet::load(string infile){
    ifstream filein;
    filein.open(infile);
    string instring;

    // read in network parameters
    filein >> instring;
    N_i = stoi(instring);
    filein >> instring;
    N_h = stoi(instring);
    filein >> instring;
    N_o = stoi(instring);
    cout << N_i << N_h << N_o << endl;

    //resize weights array accounting for bias
    weights.resize(2);
    weights[0].resize(N_i+1);
    for(int i = 0; i < weights[0].size(); i++){
        weights[0][i].resize(N_h);
    }
    weights[1].resize(N_h+1);
    for(int h = 0; h < weights[1].size(); h++){
        weights[1][h].resize(N_o);
    }

    // load weights from file
    for (int h = 0; h < N_h; h++){
        for (int i = 0;i < N_i+1; i++){
            filein >> instring;
            weights[0][i][h] = stod(instring);
            cout << weights[0][i][h] << ' ';
        }
        cout << endl;
    }
    for (int o = 0; o < N_o; o++){
        for (int h = 0; h < N_h+1; h++){
            filein >> instring;
            weights[1][h][o] = stod(instring);
            cout << weights[1][h][o]<< ' ';
        }
        cout << endl;
    }

}

bool NeuralNet::save(string outfile){
    ofstream fileout;
    fileout.open(outfile);

    fileout.setf(ios::fixed,ios::floatfield);
    fileout.precision(3);

    fileout << N_i << ' ' << N_h << ' ' << N_o << endl;

    for(int h = 0; h < N_h; h++){
        for (int i = 0; i < N_i+1; i++){
            fileout << weights[0][i][h] << ' ';
        }
        fileout << endl;
    }

    for(int o = 0; o < N_o; o++){
        for(int h = 0; h < N_h+1; h++){
            fileout << weights[1][h][o] << ' ';
        }
        fileout << endl;
    }

}

int main(){
    NeuralNet a;
    a.load(string("test.txt"));
    a.save(string("save.txt"));
    return 0;
}
{'fraction_non_alphanumeric': 0.19402074435631483, 'fraction_numerical': 0.016778523489932886, 'mean_word_length': 2.0788732394366196, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5534466', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1247, 'n_words': 279}