neuron_serialization_example.cpp 3.05 KB
Newer Older
1 2 3 4 5
//
// Created by martin on 7/15/18.
//

/**
6
 * Test of the neuron binary serialization
7 8 9 10 11 12 13 14
 */


#include <iostream>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

15
#include "../include/4neuro.h"
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

int main() {
    NeuronLinear n(2, 3);

    std::cout << n.get_potential() << " "
              << n.get_state() << " "
              << n.activation_function_get_parameter(0) << " "
              << n.activation_function_get_parameter(1) << std::endl;

    std::ofstream ofs("stored_neuron.4n");
    {
        boost::archive::text_oarchive oa(ofs);
        oa << n;
        ofs.close();
    }

    NeuronLinear n2;
    {
        std::ifstream ifs("stored_neuron.4n");
        boost::archive::text_iarchive ia(ifs);
        ia >> n2;
        ifs.close();
    }

    std::cout << n2.get_potential() << " "
              << n2.get_state() << " "
              << n2.activation_function_get_parameter(0) << " "
              << n2.activation_function_get_parameter(1) << std::endl;

    NeuronLinear n3(0.62, 0.4);

    std::cout << n3.get_potential() << " "
              << n3.get_state() << " "
              << n3.activation_function_get_parameter(0) << " "
              << n3.activation_function_get_parameter(1) << std::endl;

    std::ofstream ofs2("stored_neuron2.4n");
    {
        boost::archive::text_oarchive oa(ofs2);
        oa << n3;
        ofs2.close();
    }

    NeuronLogistic n4;
    {
        std::ifstream ifs("stored_neuron2.4n");
        boost::archive::text_iarchive ia(ifs);
        ia >> n4;
        ifs.close();
    }

    std::cout << n4.get_potential() << " "
              << n4.get_state() << " "
              << n4.activation_function_get_parameter(0) << " "
              << n4.activation_function_get_parameter(1) << std::endl;

    NeuronTanh n5(0.5);

    std::cout << n5.get_potential() << " "
              << n5.get_state() << " "
              << n5.activation_function_get_parameter(0) << std::endl;

    std::ofstream ofs3("stored_neuron3.4n");
    {
        boost::archive::text_oarchive oa(ofs3);
        oa << n5;
        ofs3.close();
    }

    NeuronTanh n6;
    {
        std::ifstream ifs("stored_neuron3.4n");
        boost::archive::text_iarchive ia(ifs);
        ia >> n6;
        ifs.close();
    }

    std::cout << n6.get_potential() << " "
              << n6.get_state() << " "
              << n6.activation_function_get_parameter(0) << std::endl;

    NeuronBinary n7(0.71);

    std::cout << n7.get_potential() << " "
              << n7.get_state() << " "
              << n7.activation_function_get_parameter(0) << std::endl;

    std::ofstream ofs4("stored_neuron4.4n");
    {
        boost::archive::text_oarchive oa(ofs4);
        oa << n7;
        ofs4.close();
    }

    NeuronBinary n8;
    {
        std::ifstream ifs("stored_neuron4.4n");
        boost::archive::text_iarchive ia(ifs);
        ia >> n8;
        ifs.close();
    }

    std::cout << n8.get_potential() << " "
              << n8.get_state() << " "
              << n8.activation_function_get_parameter(0) << std::endl;

    return 0;
}