Exemple #1
0
int main(int argc, char* argv[])
{
    /* Start the timer */
    uglyTime(NULL);
    printf("\nQUBIC %.1f: greedy biclustering (compiled "__DATE__" "__TIME__")\n\n", VER);
    rows = cols = 0;

    /* get the program options defined in get_options.c */
    get_options(argc, argv);

    /*get the size of input expression matrix*/
    get_matrix_size(po->FP);
    progress("File %s contains %d genes by %d conditions", po -> FN, rows, cols);
    if (rows < 3 || cols < 3)
    {
        /*neither rows number nor cols number can be too small*/
        errAbort("Not enough genes or conditions to make inference");
    }
    genes = alloc2c(rows, LABEL_LEN);
    conds = alloc2c(cols, LABEL_LEN);

    /* Read in the gene names and condition names */
    read_labels(po -> FP);

    /* Read in the expression data */
    if (po->IS_DISCRETE)
        read_discrete(po -> FP);
    else
    {
        read_continuous(po -> FP);

        /* formatting rules */
        discretize(addSuffix(po->FN, ".rules"));
    }
    fclose(po->FP);

    /*we can do expansion by activate po->IS_SWITCH*/
    if (po->IS_SWITCH)
    {
        read_and_solve_blocks(po->FB, addSuffix(po->BN, ".expansion"));
    }
    else
    {
        /* formatted file */
        write_imported(addSuffix(po->FN, ".chars"));

        /* the file that stores all blocks */
        make_graph(addSuffix(po->FN, ".blocks"));
    }/* end of main else */
    free(po);
    return 0;
}
Exemple #2
0
/*** MAIN FUNCTION ***/
int main (int argc, char **argv) {

  // process the command line
  process_args (argc, argv);

  determine_limits();

  // check if there is something wrong in the command
  if (n_nodes <= 0 || n_edges <= 0) {
    fprintf (stderr, "Incorrect or missing node numbers\n");
    exit (1);
  }

  fprintf (stderr, "allocating edges..\n");
  edges = (edge_t *) malloc(n_edges * sizeof(edge_t));
  read_edges();

  fprintf (stderr, "allocating nodes..\n");
  nodes = (node_t *) malloc(n_nodes * sizeof(node_t));
  memset (nodes, 0, n_nodes * sizeof(node_t));
  for (unsigned int i=0; i < n_nodes; i++) {
    nodes[i].old_values = (float *) malloc (n_classes * sizeof(float));
    nodes[i].new_values = (float *) malloc (n_classes * sizeof(float));
  }

  read_labels();

  for (unsigned int i=0; i < n_nodes; i++) {
    for (short j=0; j < n_classes; j++) {
      if (!nodes[i].labeled)
         nodes[i].old_values[j] = 1.0 / n_classes;
      nodes[i].new_values[j] = 0;
    }
  }

  // compute the influx (weighted degree) of each node
  for (unsigned int i=0; i < n_edges; i++) {
    nodes[edges[i].ids[0]].influx += edges[i].weight;
    nodes[edges[i].ids[1]].influx += edges[i].weight;
  }

  float max_error;

  do {
    max_error = propagate_labels();
    fprintf (stderr, "error: %f\n", max_error);
  } while (max_error > 0.0002);

  output_labels();

  return 0;
}
Exemple #3
0
void execute(DBN& dbn, task& task, const std::vector<std::string>& actions) {
    print_title("Network");
    dbn.display();

    using dbn_t = std::decay_t<DBN>;

    //Execute all the actions sequentially
    for (auto& action : actions) {
        if (action == "pretrain") {
            print_title("Pretraining");

            if (task.pretraining.samples.empty()) {
                std::cout << "dllp: error: pretrain is not possible without a pretraining input" << std::endl;
                return;
            }

            std::vector<Container> pt_samples;

            //Try to read the samples
            if (!read_samples<Three>(task.pretraining.samples, pt_samples)) {
                std::cout << "dllp: error: failed to read the pretraining samples" << std::endl;
                return;
            }

            if (task.pt_desc.denoising) {
                std::vector<Container> clean_samples;

                //Try to read the samples
                if (!read_samples<Three>(task.pretraining_clean.samples, clean_samples)) {
                    std::cout << "dllp: error: failed to read the clean samples" << std::endl;
                    return;
                }

                //Pretrain the network
                cpp::static_if<dbn_t::layers_t::is_denoising>([&](auto f) {
                    f(dbn).pretrain_denoising(pt_samples.begin(), pt_samples.end(), clean_samples.begin(), clean_samples.end(), task.pt_desc.epochs);
                });
            } else {
                //Pretrain the network
                dbn.pretrain(pt_samples.begin(), pt_samples.end(), task.pt_desc.epochs);
            }
        } else if (action == "train") {
            print_title("Training");

            if (task.training.samples.empty() || task.training.labels.empty()) {
                std::cout << "dllp: error: train is not possible without samples and labels" << std::endl;
                return;
            }

            std::vector<Container> ft_samples;
            std::vector<std::size_t> ft_labels;

            //Try to read the samples
            if (!read_samples<Three>(task.training.samples, ft_samples)) {
                std::cout << "dllp: error: failed to read the training samples" << std::endl;
                return;
            }

            //Try to read the labels
            if (!read_labels(task.training.labels, ft_labels)) {
                std::cout << "dllp: error: failed to read the training labels" << std::endl;
                return;
            }

            using last_layer = typename dbn_t::template layer_type<dbn_t::layers - 1>;

            //Train the network
            cpp::static_if<sgd_possible<last_layer>::value>([&](auto f) {
                auto ft_error = f(dbn).fine_tune(ft_samples, ft_labels, task.ft_desc.epochs);
                std::cout << "Train Classification Error:" << ft_error << std::endl;
            });

        } else if (action == "test") {
            print_title("Testing");

            if (task.testing.samples.empty() || task.testing.labels.empty()) {
                std::cout << "dllp: error: test is not possible without samples and labels" << std::endl;
                return;
            }

            std::vector<Container> test_samples;
            std::vector<std::size_t> test_labels;

            //Try to read the samples
            if (!read_samples<Three>(task.testing.samples, test_samples)) {
                std::cout << "dllp: error: failed to read the test samples" << std::endl;
                return;
            }

            //Try to read the labels
            if (!read_labels(task.testing.labels, test_labels)) {
                std::cout << "dllp: error: failed to read the test labels" << std::endl;
                return;
            }

            auto classes = dbn_t::output_size();

            etl::dyn_matrix<std::size_t, 2> conf(classes, classes, 0.0);

            std::size_t n  = test_samples.size();
            std::size_t tp = 0;

            for (std::size_t i = 0; i < test_samples.size(); ++i) {
                auto sample = test_samples[i];
                auto label  = test_labels[i];

                auto predicted = dbn.predict(sample);

                if (predicted == label) {
                    ++tp;
                }

                ++conf(label, predicted);
            }

            double test_error = (n - tp) / double(n);

            std::cout << "Error rate: " << test_error << std::endl;
            std::cout << "Accuracy: " << (1.0 - test_error) << std::endl
                      << std::endl;

            std::cout << "Results per class" << std::endl;

            double overall = 0.0;

            std::cout << "   | Accuracy | Error rate |" << std::endl;

            for (std::size_t l = 0; l < classes; ++l) {
                std::size_t total = etl::sum(conf(l));
                double acc = (total - conf(l, l)) / double(total);
                std::cout << std::setw(3) << l;
                std::cout << "|" << std::setw(10) << (1.0 - acc) << "|" << std::setw(12) << acc << "|" << std::endl;
                overall += acc;
            }

            std::cout << std::endl;

            std::cout << "Overall Error rate: " << overall / classes << std::endl;
            std::cout << "Overall Accuracy: " << 1.0 - (overall / classes) << std::endl
                      << std::endl;

            std::cout << "Confusion Matrix (%)" << std::endl
                      << std::endl;

            std::cout << "    ";
            for (std::size_t l = 0; l < classes; ++l) {
                std::cout << std::setw(5) << l << " ";
            }
            std::cout << std::endl;

            for (std::size_t l = 0; l < classes; ++l) {
                std::size_t total = etl::sum(conf(l));
                std::cout << std::setw(3) << l << "|";
                for (std::size_t p = 0; p < classes; ++p) {
                    std::cout << std::setw(5) << std::setprecision(2) << 100.0 * (conf(l, p) / double(total)) << "|";
                }
                std::cout << std::endl;
            }
            std::cout << std::endl;
        } else if (action == "save") {
            print_title("Save Weights");

            dbn.store(task.w_desc.file);
            std::cout << "Weights saved" << std::endl;
        } else if (action == "load") {
            print_title("Load Weights");

            dbn.load(task.w_desc.file);
            std::cout << "Weights loaded" << std::endl;
        } else {
            std::cout << "dllp: error: Invalid action: " << action << std::endl;
        }
    }

    //TODO
}
Exemple #4
0
mnist_labels_t load_labels(uint32_t train)
{
    return read_labels(train);
}