Esempio n. 1
0
    // do all the work on 'np' partitions, 'nx' data points each, for 'nt'
    // time steps
    space do_work(std::size_t np, std::size_t nx, std::size_t nt)
    {
        // U[t][i] is the state of position i at time t.
        std::vector<space> U(2);
        for (space& s: U)
            s.resize(np);

        // Initial conditions: f(0, i) = i
        # pragma omp parallel
        {
        // Visual Studio requires OMP loop variables to be signed :/
        # pragma omp for schedule(static)
        for (boost::int64_t i = 0; i < (boost::int64_t)np; ++i)
            U[0][i] = partition_data(nx, double(i));

        // Actual time step loop
        for (std::size_t t = 0; t != nt; ++t)
        {
            space const& current = U[t % 2];
            space& next = U[(t + 1) % 2];

            // Visual Studio requires OMP loop variables to be signed :/
            # pragma omp for schedule(static)
            for (boost::int64_t i = 0; i < (boost::int64_t)np; ++i)
                next[i] = heat_part(current[idx(i-1, np)], current[i], current[idx(i+1, np)]);
        }
        }
        // Return the solution at time-step 'nt'.
        return U[nt % 2];
    }
Esempio n. 2
0
File: main.c Progetto: Mikushi/NNet
int
main (int argc, const char* argv[])
{
    err_t err;

    printf ("Loading images and labels...\n");
    data_t data;
    err = read_all_data (&data, images_file, labels_file);
    EXIT_MAIN_ON_ERR(err);

    printf ("Setting up network...\n");
    network_t network;
    uint32_t layers = sizeof(nodes) / sizeof(nodes[0]);

    printf ("Node structure: ");
    for (uint32_t i = 0; i < layers - 1; ++i) {
        printf ("%i x ", nodes[i]);
    }
    printf ("%i.\n", nodes[layers - 1]);

    network.nodes.size = layers;
    network.nodes.data = nodes;
    network.epochs = EPOCHS;
    network.mini_batch_size = MINI_BATCH_SIZE;
    network.eta = ETA;

    err = network_allocate (&network);
    EXIT_MAIN_ON_ERR(err);

    printf ("Initialising network...\n");
    network_random_init (&network, RANDOM_VARIANCE);

    // Split off a chunk of data for testing
    data_t test_data;
    partition_data(&data, &test_data, VALIDATION_DATA_CHUNK_SIZE);

    printf ("Stochastic gradient descent...\n");
    network_sgd (&network, &data, &test_data);

    network_free (&network);
    images_free (&data.images);
    labels_free (&data.labels);

    return EXIT_SUCCESS;
}
Esempio n. 3
0
    // do all the work on 'np' partitions, 'nx' data points each, for 'nt'
    // time steps
    space do_work(std::size_t np, std::size_t nx, std::size_t nt)
    {
        // U[t][i] is the state of position i at time t.
        std::vector<space> U(2);
        for (space& s: U)
            s.resize(np);

        // Initial conditions: f(0, i) = i
        for (std::size_t i = 0; i != np; ++i)
            U[0][i] = partition_data(nx, double(i));

        // Actual time step loop
        for (std::size_t t = 0; t != nt; ++t)
        {
            space const& current = U[t % 2];
            space& next = U[(t + 1) % 2];

            for (std::size_t i = 0; i != np; ++i)
                next[i] = heat_part(current[idx(i, -1, np)], current[i], current[idx(i, +1, np)]);
        }

        // Return the solution at time-step 'nt'.
        return U[nt % 2];
    }