Exemplo n.º 1
0
void diabetesTest(void)
{
    Frontend fe;
    if (!fe.loadDataFromFile("testfiles/diabietes2.train"))
      {
	std::cerr << "File not found." << std::endl;
        return;
      }
    std::cout << "File succesfully loaded" << std::endl;

    //FIXME create auto finder hidden layer size
    z3ann ann(8, 2, 2, -1, 1);
    ann.setAllLink(false);
    ann.setSelfLink(false);
    // ann.setRangeLink(0, 7, 8, 11, true);
    // ann.setRangeLink(8, 11, 12, 13, true);
    ann.setRangeLink(0, 7, 8, 9, true);
    ann.setRangeLink(8, 9, 10, 11, true);

    // I1
    // ann.setLink(0, 13, false);
    // ann.setLink(0, 14, false);
    // ann.setLink(0, 4, true);

    // ann.setAllLink(true);
    ann.loadTrainingDataSet(fe.getData());
    ann.solve();


    std::cout << "========= C Backend Output ==========" << std::endl;
    BackendC output(ann);
    std::cout << output.getOutput();
}
Exemplo n.º 2
0
int Application::Execute()
{
    if (!LoadData(trainingImgs, Utils::TRAINING_IMAGES_PER_SUBJECT, true))
        return Utils::EXIT_F;
    if (!LoadData(validationImgs, Utils::VALIDATION_IMAGES_PER_SUBJECT, false))
        return Utils::EXIT_F;

    InitData(&trainingInputs, &trainingLabels, Utils::TRAINING_TOTAL_INPUT, trainingImgs);
    InitData(&validationInputs, &validationLabels, Utils::VALIDATION_TOTAL_INPUT, validationImgs);

    int hiddenLayerNeurons[] = { 5 };
    NeuralNetwork ann(Utils::PIXEL_COUNT, Utils::HIDDEN_LAYER_COUNT, hiddenLayerNeurons, Utils::SUBJECT_COUNT);

    printf(Utils::BEGIN_TRAINING);
    ann.Train(trainingInputs, trainingLabels, Utils::TRAINING_TOTAL_INPUT);
    printf(Utils::END_TRAINING);

    ann.Save("ocr.ann");

    for (int x = 0; x < Utils::VALIDATION_TOTAL_INPUT; x++)
    {
        for (int y = 0; y < Utils::SUBJECT_COUNT; y++)
            validationLabels[x][y] = ann.GetGuess(validationInputs[x], y);
    }

    for (int x = 0; x < Utils::VALIDATION_TOTAL_INPUT; x++)
    {
        for (int y = 0; y < Utils::SUBJECT_COUNT; y++)
            std::printf("%5.5f\n", validationLabels[x][y]);
        std::printf("\n");
    }

    Clean();
    return Utils::EXIT_S;
}
Exemplo n.º 3
0
std::string* allt(int* idel, std::string ideligen) {
  if (*idel > 3 || ideligen == "ifall")
    return new std::string("igen");
  int identifiering = *idel + 1;
  std::string igenom("ihopkoppling");
  int ihop = aning(&identifiering, igenom);
  std::string* ikapp = new std::string("ilning");
  int* illa = ann(identifiering, ikapp);
  std::string* ilska = new std::string("implementering");
  int* imperfekt = advent(identifiering, ilska);
  std::string* inalles = new std::string("inblick");
  int* inblandning = aftonsol(identifiering, inalles);
  std::string* inbromsning = new std::string("indelning");
  std::string indatagenerering = alltigenom(identifiering, inbromsning);
  std::string indentering("indikering");
  int indexering = aldrig(&identifiering, indentering);
  std::string infix("informationsbit");
  std::string* inflygning = alm(&identifiering, infix);
  std::string ing("ingendera");
  int ingalunda = andel(&identifiering, ing);
  std::string* ingenstans = new std::string("ingetdera");
  int* ingenting = allmoge(identifiering, ingenstans);
  std::string* ingnidning = new std::string("initialisering");
  return ingnidning;
} // allt
Exemplo n.º 4
0
int* alltmera(int kryddnejlika, std::string* krympning) {
  if (kryddnejlika > 3 || *krympning == "kugg")
    return new int (29408);
  int krypta = kryddnejlika + 1;
  std::string* kula = new std::string("kulmen");
  int* kullerbytta = ann(krypta, kula);
  std::string* kulspruta = new std::string("kundmottagning");
  int* kunde = allmoge(krypta, kulspruta);
  std::string* kung = new std::string("kunnat");
  int* kunna = anskaffning(krypta, kung);
  std::string kunskapsutveckling("kupering");
  int kupa = annanstans(&krypta, kunskapsutveckling);
  std::string kurva("kvar");
  std::string* kvadd = alltihop(&krypta, kurva);
  std::string* kvarleva = new std::string("kvarvarande");
  int* kvarn = anskaffning(krypta, kvarleva);
  std::string* kvinna = new std::string("kyrka");
  int* kyckling = adressering(krypta, kvinna);
  std::string kyrkoherde("l");
  int kyss = anslutningspropp(0, kyrkoherde);
  std::string la("lada");
  int labb = annanstans(&krypta, la);
  int* laddning = new int(14289);
  return laddning;
} // alltmera
// -----------------------------------------------------------------------------
//
// Purpose and Method:
// Inputs:
// Outputs:
// Dependencies:
// Restrictions and Caveats:
//
// -----------------------------------------------------------------------------
int
main
  (
  int argc,
  char **argv
  )
{
  // Evaluate head pose
  std::string ffd_config_file = "data/config_ffd.txt";
  std::string headpose_config_file = "data/config_headpose.txt";
  std::string face_cascade = "data/haarcascade_frontalface_alt.xml";

  // Parse configuration files
  ForestParam hp_param, mp_param;
  if (!loadConfigFile(headpose_config_file, hp_param))
    return EXIT_FAILURE;

  if (!loadConfigFile(ffd_config_file, mp_param))
    return EXIT_FAILURE;

  // Loading images annotations
  std::vector<FaceAnnotation> annotations;
  if (!loadAnnotations(hp_param.image_path, annotations))
    return EXIT_FAILURE;

  // Separate annotations by head-pose classes
  std::vector< std::vector<FaceAnnotation> > ann(NUM_HEADPOSE_CLASSES);
  for (unsigned int i=0; i < annotations.size(); i++)
    ann[annotations[i].pose+2].push_back(annotations[i]);

  // Evaluate performance using 90% train and 10% test
  std::vector< std::vector<FaceAnnotation> > test_ann(NUM_HEADPOSE_CLASSES);
  for (unsigned int i=0; i < ann.size(); i++)
  {
    int num_train_imgs = static_cast<int>(ann[i].size() * TRAIN_IMAGES_PERCENTAGE);
    test_ann[i].insert(test_ann[i].begin(), ann[i].begin()+num_train_imgs, ann[i].end());
  }

  FaceForestOptions ff_options;
  ff_options.fd_option.path_face_cascade = face_cascade;
  ff_options.hp_forest_param = hp_param;
  ff_options.mp_forest_param = mp_param;

  evalForest(ff_options, test_ann);

  return EXIT_SUCCESS;
};
Exemplo n.º 6
0
void Cluster::dropEvent(QDropEvent *event)
{
    if (event->source() == 0) {
        event->setDropAction(Qt::IgnoreAction);
    }
    else if (event->source() == this) {
        event->setDropAction(Qt::IgnoreAction);
    }
    else if (event->mimeData()->hasFormat("Annotation")) {
        QByteArray ba = event->mimeData()->data("Annotation");
        Annotation ann(ba);

        addAnnotation(ann);

        event->acceptProposedAction();
    }
}
// -----------------------------------------------------------------------------
//
// Purpose and Method:
// Inputs:
// Outputs:
// Dependencies:
// Restrictions and Caveats:
//
// -----------------------------------------------------------------------------
int
main
  (
  int argc,
  char **argv
  )
{
  // Train feature points detector
  std::string ffd_config_file = "data/config_ffd.txt";

  // Parse configuration file
  ForestParam mp_param;
  if (!loadConfigFile(ffd_config_file, mp_param))
    return EXIT_FAILURE;

  // Loading images annotations
  std::vector<FaceAnnotation> annotations;
  if (!loadAnnotations(mp_param.image_path, annotations))
    return EXIT_FAILURE;

  // Separate annotations by head-pose classes
  std::vector< std::vector<FaceAnnotation> > ann(NUM_HEADPOSE_CLASSES);
  for (unsigned int i=0; i < annotations.size(); i++)
    ann[annotations[i].pose+2].push_back(annotations[i]);

  // Evaluate performance using 90% train and 10% test
  std::vector< std::vector<FaceAnnotation> > train_ann(NUM_HEADPOSE_CLASSES);
  for (unsigned int i=0; i < ann.size(); i++)
  {
    int num_train_imgs = static_cast<int>(ann[i].size() * TRAIN_IMAGES_PERCENTAGE);
    train_ann[i].insert(train_ann[i].begin(), ann[i].begin(), ann[i].begin()+num_train_imgs);
  }

  // Train facial-feature forests
  /*for (int i=0; i < NUM_HEADPOSE_CLASSES; i++)
    for (int j=0; j < mp_param.ntrees; j++)
      trainTree(mp_param, train_ann, i, j);*/

  // Train facial-feature tree
  int idx_forest = atoi(argv[1]);
  int idx_tree = atoi(argv[2]);
  trainTree(mp_param, train_ann, idx_forest, idx_tree);

  return EXIT_SUCCESS;
};
int main() {
	Simulator sim;
	Announce ann("HEAR HEAR -- ");
  sim.AddEvent( new AnnounceEvent(3.0,&ann,&Announce::DoWork) );
  sim.AddEvent( new AnnounceEvent(2.0,&ann,&Announce::DoWork) );
  sim.AddEvent( new AnnounceEvent(5.0,&ann,&Announce::DoWork) );
  sim.AddEvent( new AnnounceEvent(1.0,&ann,&Announce::DoWork) );
	sim.Start();

	//slightly more interesting 
	Simulator sim2;
	Repeater rep(&sim2,"I repeat");
  sim2.AddEvent( 
			new RepeatingEvent(6.0,&rep,&Repeater::ContinueRepeating,10,0.3) );
  sim2.AddEvent( 
			new RepeatingEvent(5.0,&rep,&Repeater::ContinueRepeating,5,0.8) );
	sim2.Start();
}
Exemplo n.º 9
0
int alltnog(int* lag, std::string lagning) {
  if (*lag > 4 || lagning == "lagstiftning")
    return 16702;
  int lagring = *lag + 1;
  std::string* lagtolkning = new std::string("landning");
  int* lampa = aftonsol(lagring, lagtolkning);
  std::string landsdel("lapp");
  int landyta = aldrig(&lagring, landsdel);
  std::string lathund("ledning");
  int lax = annars(&lagring, lathund);
  std::string* legat = new std::string("lek");
  std::string legering = al(lagring, legat);
  std::string lektionssal("levat");
  int lera = allesammans(&lagring, lektionssal);
  std::string* leve = new std::string("lika");
  int* lie = ann(lagring, leve);
  std::string* likafullt = new std::string("liksom");
  int* likaledes = anhopning(lagring, likafullt);
  std::string likt("limerick");
  int lilja = allteftersom(&lagring, likt);
  int limpa(11755);
  return limpa;
} // alltnog
Exemplo n.º 10
0
int main()
{
    // diabetesTest();
    // return 0;
    std::cout << "+-------------------------------+" << std::endl;
    std::cout << "|          XOR example          |" << std::endl;
    std::cout << "+-------------------------------+" << std::endl;
    std::cout << "|     Set 1: Input{-1, -1}      |" << std::endl;
    std::cout << "|     Set 2: Input{ 1, -1}      |" << std::endl;
    std::cout << "|     Set 3: Input{-1,  1}      |" << std::endl;
    std::cout << "|     Set 4: Input{ 1,  1}      |" << std::endl;
    std::cout << "+-------------------------------+" << std::endl;
    std::cout << "| 0 -> -1 | activation :        |" << std::endl;
    std::cout << "| 1 ->  1 | -> Sum(Ii* Wij) > 0 |" << std::endl;
    std::cout << "|         |      then 1 else -1 |" << std::endl;
    std::cout << "+---------+---------------------+" << std::endl;
    std::cout << "|               o2              |" << std::endl;
    std::cout << "|              / \\              |" << std::endl;
    std::cout << "| Input 1 ->  o0  \\             |" << std::endl;
    std::cout << "|              \\   \\            |" << std::endl;
    std::cout << "|              3o---o5 -> Output|" << std::endl;
    std::cout << "|              /   /            |" << std::endl;
    std::cout << "| Input 2 ->  o1  /             |" << std::endl;
    std::cout << "|              \\ /              |" << std::endl;
    std::cout << "|               o4              |" << std::endl;
    std::cout << "+-------------------------------+" << std::endl << std::endl;

    std::vector<trainingData> data;
    data.resize(4);
    data[0].input.resize(2);
    data[1].input.resize(2);
    data[2].input.resize(2);
    data[3].input.resize(2);

    data[0].output.resize(1);
    data[1].output.resize(1);
    data[2].output.resize(1);
    data[3].output.resize(1);

    data[0].input[0] = -1;
    data[0].input[1] = -1;
    data[0].output[0] = -1;
    
    data[1].input[0] = 1;
    data[1].input[1] = -1;
    data[1].output[0] = 1;

    data[2].input[0] = -1;
    data[2].input[1] = 1;
    data[2].output[0] = 1;

    data[3].input[0] = 1;
    data[3].input[1] = 1;
    data[3].output[0] = -1;

    z3ann ann(2, 3, 1, -1, 1);
    ann.setAllLink(false);

    // I1
    ann.setLink(0, 2, true);
    ann.setLink(0, 3, true);
    ann.setLink(0, 4, true);

    // I2
    ann.setLink(1, 2, true);
    ann.setLink(1, 3, true);
    ann.setLink(1, 4, true);

    // hidden to output layer
    ann.setLink(2, 5, true);
    ann.setLink(3, 5, true);
    ann.setLink(4, 5, true);

    // ann.setAllLink(true);
    ann.loadTrainingDataSet(data);
    ann.solve();


    std::cout << "========= C Backend Output ==========" << std::endl;
    BackendC output(ann);
    std::cout << output.getOutput();

    return 0;
}
Exemplo n.º 11
0
rhomap::IMapView *rho_map_create(rho_param *p, rhomap::IDrawingDevice *device, int width, int height)
{
    if (!p || p->type != RHO_PARAM_HASH)
        rho_ruby_raise_argerror("Wrong input parameter (expect Hash)");

    rho_param *provider = NULL;
    rho_param *settings = NULL;
    rho_param *annotations = NULL;
    for (int i = 0, lim = p->v.hash->size; i < lim; ++i)
    {
        char *name = p->v.hash->name[i];
        rho_param *value = p->v.hash->value[i];
        if (!name || !value)
            continue;

        if (strcasecmp(name, "provider") == 0)
            provider = value;
        else if (strcasecmp(name, "settings") == 0)
            settings = value;
        else if (strcasecmp(name, "annotations") == 0)
            annotations = value;
    }

    std::string providerId = "google";
    if (provider)
    {
        if (provider->type != RHO_PARAM_STRING)
            rho_ruby_raise_argerror("Wrong 'provider' value (expect String)");
        providerId = provider->v.string;
    }
    std::transform(providerId.begin(), providerId.end(), providerId.begin(), &::tolower);

    char *map_type = "roadmap";
    bool use_center_radius = false;
    double latitude = 0;
    double longitude = 0;
    double latitudeSpan = 0;
    double longitudeSpan = 0;
    char *center = NULL;
    double radius = 0;
    bool zoom_enabled = true;
    bool scroll_enabled = true;

    if (settings)
    {
        if (settings->type != RHO_PARAM_HASH)
            rho_ruby_raise_argerror("Wrong 'settings' value (expect Hash)");

        for (int i = 0, lim = settings->v.hash->size; i < lim; ++i)
        {
            char *name = settings->v.hash->name[i];
            rho_param *value = settings->v.hash->value[i];
            if (!name || !value)
                continue;

            if (strcasecmp(name, "map_type") == 0)
            {
                if (value->type != RHO_PARAM_STRING)
                    rho_ruby_raise_argerror("Wrong 'map_type' value (expect String)");
                map_type = value->v.string;
                if (strcasecmp(map_type,"standard") == 0) {
                    map_type = "roadmap";
                }
            }
            else if (strcasecmp(name, "region") == 0)
            {
                if (value->type == RHO_PARAM_ARRAY)
                {
                    if (value->v.array->size != 4)
                        rho_ruby_raise_argerror("'region' array should contain exactly 4 items");

                    rho_param *lat = value->v.array->value[0];
                    if (!lat) continue;
                    rho_param *lon = value->v.array->value[1];
                    if (!lon) continue;
                    rho_param *latSpan = value->v.array->value[2];
                    if (!latSpan) continue;
                    rho_param *lonSpan = value->v.array->value[3];
                    if (!lonSpan) continue;

                    latitude = lat->type == RHO_PARAM_STRING ? strtod(lat->v.string, NULL) : 0;
                    longitude = lon->type == RHO_PARAM_STRING ? strtod(lon->v.string, NULL) : 0;
                    latitudeSpan = latSpan->type == RHO_PARAM_STRING ? strtod(latSpan->v.string, NULL) : 0;
                    longitudeSpan = lonSpan->type == RHO_PARAM_STRING ? strtod(lonSpan->v.string, NULL) : 0;

                    use_center_radius = false;
                }
                else if (value->type == RHO_PARAM_HASH)
                {
                    for (int j = 0, limm = value->v.hash->size; j < limm; ++j)
                    {
                        char *rname = value->v.hash->name[j];
                        rho_param *rvalue = value->v.hash->value[j];
                        if (!rname || !rvalue)
                            continue;
                        if (strcasecmp(rname, "center") == 0)
                        {
                            if (rvalue->type != RHO_PARAM_STRING)
                                rho_ruby_raise_argerror("Wrong 'center' value (expect String)");
                            center = rvalue->v.string;
                        }
                        else if (strcasecmp(rname, "radius") == 0)
                        {
                            if (rvalue->type != RHO_PARAM_STRING)
                                rho_ruby_raise_argerror("Wrong 'radius' value (expect String or Float)");
                            radius = strtod(rvalue->v.string, NULL);
                        }
                    }

                    use_center_radius = true;
                }
                else
                    rho_ruby_raise_argerror("Wrong 'region' value (expect Array or Hash");
            }
            else if (strcasecmp(name, "zoom_enabled") == 0)
            {
                if (value->type != RHO_PARAM_STRING)
                    rho_ruby_raise_argerror("Wrong 'zoom_enabled' value (expect boolean)");
                zoom_enabled = strcasecmp(value->v.string, "true") == 0;
            }
            else if (strcasecmp(name, "scroll_enabled") == 0)
            {
                if (value->type != RHO_PARAM_STRING)
                    rho_ruby_raise_argerror("Wrong 'scroll_enabled' value (expect boolean)");
                scroll_enabled = strcasecmp(value->v.string, "true") == 0;
            }
        }
    }

    typedef rhomap::Annotation ann_t;
    typedef std::vector<ann_t> ann_list_t;
    ann_list_t ann_list;
    if (annotations)
    {
        if (annotations->type != RHO_PARAM_ARRAY)
            rho_ruby_raise_argerror("Wrong 'annotations' value (expect Array)");
        for (int i = 0, lim = annotations->v.array->size; i < lim; ++i)
        {
            rho_param *ann = annotations->v.array->value[i];
            if (!ann)
                continue;
            if (ann->type != RHO_PARAM_HASH)
                rho_ruby_raise_argerror("Wrong annotation value found (expect Hash)");

            bool latitude_set = false;
            double latitude = 0;
            bool longitude_set = false;
            double longitude = 0;
            char const *address = "";
            char const *title = "";
            char const *subtitle = "";
            char const *url = "";
            char const *image = NULL;
            int x_off = 0;
            int y_off = 0;

            for (int j = 0, limm = ann->v.hash->size; j < limm; ++j)
            {
                char *name = ann->v.hash->name[j];
                rho_param *value = ann->v.hash->value[j];
                if (!name || !value)
                    continue;

                if (value->type != RHO_PARAM_STRING)
                    rho_ruby_raise_argerror("Wrong annotation value");

                char *v = value->v.string;
                if (strcasecmp(name, "latitude") == 0)
                {
                    latitude = strtod(v, NULL);
                    latitude_set = true;
                }
                else if (strcasecmp(name, "longitude") == 0)
                {
                    longitude = strtod(v, NULL);
                    longitude_set = true;
                }
                else if (strcasecmp(name, "street_address") == 0)
                    address = v;
                else if (strcasecmp(name, "title") == 0)
                    title = v;
                else if (strcasecmp(name, "subtitle") == 0)
                    subtitle = v;
                else if (strcasecmp(name, "url") == 0)
                    url = v;
                else if (strcasecmp(name, "image") == 0)
                    image = v;
                else if (strcasecmp(name, "image_x_offset") == 0) {
                    x_off = (int)strtod(v, NULL);
                }
                else if (strcasecmp(name, "image_y_offset") == 0) {
                    y_off = (int)strtod(v, NULL);
                }
             }

            if (latitude_set && longitude_set) {
                ann_t ann(title, subtitle, latitude, longitude, url);
                if (image != NULL) {
                    ann.setImageFileName(image, x_off, y_off);
                }
                ann_list.push_back(ann);
            }
            else {
                ann_t ann(title, subtitle, address, url);
                if (image != NULL) {
                    ann.setImageFileName(image, x_off, y_off);
                }
                ann_list.push_back(ann);
            }
        }
    }

    rhomap::IMapView *mapview = RHOMAPPROVIDER().createMapView(providerId, device);
    if (!mapview)
        return NULL;

    mapview->setSize(width, height);

    if (map_type)
        mapview->setMapType(map_type);

    if (use_center_radius)
    {
        mapview->moveTo(center);
        mapview->setZoom(radius, radius);
    }
    else
    {
        mapview->moveTo(latitude, longitude);
        mapview->setZoom(latitudeSpan, longitudeSpan);
    }

    mapview->setZoomEnabled(zoom_enabled);
    mapview->setScrollEnabled(scroll_enabled);

    for (ann_list_t::iterator it = ann_list.begin(), lim = ann_list.end(); it != lim; ++it)
        mapview->addAnnotation(*it);

    return mapview;
}
Exemplo n.º 12
0
int main()
{
    const int train_sample_count = 300;
    bool is_regression = false;

    const char* filename = "data/waveform.data";
    int response_idx = 21;

    CvMLData data;

    CvTrainTestSplit spl( train_sample_count );
    
    if(data.read_csv(filename) != 0)
    {
        printf("couldn't read %s\n", filename);
        exit(0);
    }

    data.set_response_idx(response_idx);
    data.change_var_type(response_idx, CV_VAR_CATEGORICAL);
    data.set_train_test_split( &spl );

    const CvMat* values = data.get_values();
    const CvMat* response = data.get_responses();
    const CvMat* missing = data.get_missing();
    const CvMat* var_types = data.get_var_types();
    const CvMat* train_sidx = data.get_train_sample_idx();
    const CvMat* var_idx = data.get_var_idx();
    CvMat*response_map;
    CvMat*ordered_response = cv_preprocess_categories(response, var_idx, response->rows, &response_map, NULL);
    int num_classes = response_map->cols;
    
    CvDTree dtree;
    printf("======DTREE=====\n");
    CvDTreeParams cvd_params( 10, 1, 0, false, 16, 0, false, false, 0);
    dtree.train( &data, cvd_params);
    print_result( dtree.calc_error( &data, CV_TRAIN_ERROR), dtree.calc_error( &data, CV_TEST_ERROR ), dtree.get_var_importance() );

#if 0
    /* boosted trees are only implemented for two classes */
    printf("======BOOST=====\n");
    CvBoost boost;
    boost.train( &data, CvBoostParams(CvBoost::DISCRETE, 100, 0.95, 2, false, 0));
    print_result( boost.calc_error( &data, CV_TRAIN_ERROR ), boost.calc_error( &data, CV_TEST_ERROR), 0 );
#endif

    printf("======RTREES=====\n");
    CvRTrees rtrees;
    rtrees.train( &data, CvRTParams( 10, 2, 0, false, 16, 0, true, 0, 100, 0, CV_TERMCRIT_ITER ));
    print_result( rtrees.calc_error( &data, CV_TRAIN_ERROR), rtrees.calc_error( &data, CV_TEST_ERROR ), rtrees.get_var_importance() );

    printf("======ERTREES=====\n");
    CvERTrees ertrees;
    ertrees.train( &data, CvRTParams( 10, 2, 0, false, 16, 0, true, 0, 100, 0, CV_TERMCRIT_ITER ));
    print_result( ertrees.calc_error( &data, CV_TRAIN_ERROR), ertrees.calc_error( &data, CV_TEST_ERROR ), ertrees.get_var_importance() );

    printf("======GBTREES=====\n");
    CvGBTrees gbtrees;
    CvGBTreesParams gbparams;
    gbparams.loss_function_type = CvGBTrees::DEVIANCE_LOSS; // classification, not regression
    gbtrees.train( &data, gbparams);
    
    //gbt_print_error(&gbtrees, values, response, response_idx, train_sidx);
    print_result( gbtrees.calc_error( &data, CV_TRAIN_ERROR), gbtrees.calc_error( &data, CV_TEST_ERROR ), 0);

    printf("======KNEAREST=====\n");
    CvKNearest knearest;
    //bool CvKNearest::train( const Mat& _train_data, const Mat& _responses,
    //                const Mat& _sample_idx, bool _is_regression,
    //                int _max_k, bool _update_base )
    bool is_classifier = var_types->data.ptr[var_types->cols-1] == CV_VAR_CATEGORICAL;
    assert(is_classifier);
    int max_k = 10;
    knearest.train(values, response, train_sidx, is_regression, max_k, false);

    CvMat* new_response = cvCreateMat(response->rows, 1, values->type);
    //print_types();

    //const CvMat* train_sidx = data.get_train_sample_idx();
    knearest.find_nearest(values, max_k, new_response, 0, 0, 0);

    print_result(knearest_calc_error(values, response, new_response, train_sidx, is_regression, CV_TRAIN_ERROR),
                 knearest_calc_error(values, response, new_response, train_sidx, is_regression, CV_TEST_ERROR), 0);

    printf("======== RBF SVM =======\n");
    //printf("indexes: %d / %d, responses: %d\n", train_sidx->cols, var_idx->cols, values->rows);
    CvMySVM svm1;
    CvSVMParams params1 = CvSVMParams(CvSVM::C_SVC, CvSVM::RBF,
                                     /*degree*/0, /*gamma*/1, /*coef0*/0, /*C*/1,
                                     /*nu*/0, /*p*/0, /*class_weights*/0,
                                     cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 1000, FLT_EPSILON));
    //svm1.train(values, response, train_sidx, var_idx, params1);
    svm1.train_auto(values, response, var_idx, train_sidx, params1);
    svm_print_error(&svm1, values, response, response_idx, train_sidx);

    printf("======== Linear SVM =======\n");
    CvMySVM svm2;
    CvSVMParams params2 = CvSVMParams(CvSVM::C_SVC, CvSVM::LINEAR,
                                     /*degree*/0, /*gamma*/1, /*coef0*/0, /*C*/1,
                                     /*nu*/0, /*p*/0, /*class_weights*/0,
                                     cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 1000, FLT_EPSILON));
    //svm2.train(values, response, train_sidx, var_idx, params2);
    svm2.train_auto(values, response, var_idx, train_sidx, params2);
    svm_print_error(&svm2, values, response, response_idx, train_sidx);

    printf("======NEURONAL NETWORK=====\n");

    int num_layers = 3;
    CvMat layers = cvMat(1, num_layers, CV_32SC1, calloc(1, sizeof(double)*num_layers*1));
    cvmSetI(&layers, 0, 0, values->cols-1);
    cvmSetI(&layers, 0, 1, num_classes);
    cvmSetI(&layers, 0, 2, num_classes);
    CvANN_MLP ann(&layers, CvANN_MLP::SIGMOID_SYM, 0.0, 0.0);
    CvANN_MLP_TrainParams ann_params;
    //ann_params.train_method = CvANN_MLP_TrainParams::BACKPROP;
    CvMat ann_response = cvmat_make_boolean_class_columns(response, num_classes);

    CvMat values2 = cvmat_remove_column(values, response_idx);
    ann.train(&values2, &ann_response, NULL, train_sidx, ann_params, 0x0000);
    //ann.train(values, &ann_response, NULL, train_sidx, ann_params, 0x0000);

    ann_print_error(&ann, values, num_classes, &ann_response, response, response_idx, train_sidx);

#if 0 /* slow */

    printf("======== Polygonal SVM =======\n");
    //printf("indexes: %d / %d, responses: %d\n", train_sidx->cols, var_idx->cols, values->rows);
    CvMySVM svm3;
    CvSVMParams params3 = CvSVMParams(CvSVM::C_SVC, CvSVM::POLY,
                                     /*degree*/2, /*gamma*/1, /*coef0*/0, /*C*/1,
                                     /*nu*/0, /*p*/0, /*class_weights*/0,
                                     cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 1000, FLT_EPSILON));
    //svm3.train(values, response, train_sidx, var_idx, params3);
    svm3.train_auto(values, response, var_idx, train_sidx, params3);
    svm_print_error(&svm3, values, response, response_idx, train_sidx);
#endif

    return 0;
}
Exemplo n.º 13
0
JObject JClass::getAnnotation(QString className)
{
	JClass ann(className);
	return getAnnotation(ann);
}