| pktools 2.6.7 Processing Kernel for geospatial data

Public Member Functions | Protected Attributes | Friends | List of all members
FANN::training_data Class Reference

## Public Member Functions
| training_data (const training_data &data)
void | destroy_train ()
bool | read_train_from_file (const std::string &filename)
bool | save_train (const std::string &filename)
bool | save_train_to_fixed (const std::string &filename, unsigned int decimal_point)
void | shuffle_train_data ()
void | merge_train_data (const training_data &data)
unsigned int | length_train_data ()
unsigned int | num_input_train_data ()
unsigned int | num_output_train_data ()
fann_type ** | get_input ()
fann_type ** | get_output ()
void | set_train_data (unsigned int num_data, unsigned int num_input, fann_type **input, unsigned int num_output, fann_type **output)
void | set_train_data (const std::vector< std::vector< fann_type > > &input, const std::vector< std::vector< fann_type > > &output)
void | set_train_data (const std::vector< std::vector< std::vector< fann_type > > > &input, unsigned int num_data)
void | set_train_data (const std::vector< Vector2d< fann_type > > &input, unsigned int num_data)
void | create_train_from_callback (unsigned int num_data, unsigned int num_input, unsigned int num_output, void(FANN_API *user_function)(unsigned int, unsigned int, unsigned int, fann_type *, fann_type *))
void | scale_input_train_data (fann_type new_min, fann_type new_max)
void | scale_output_train_data (fann_type new_min, fann_type new_max)
void | scale_train_data (fann_type new_min, fann_type new_max)
void | subset_train_data (unsigned int pos, unsigned int length)

## Protected Attributes
struct fann_train_data * | train_data

## Friends
class | neural_net

## Detailed Description

Definition at line 362 of file myfann_cpp.h.

## Constructor & Destructor Documentation

## ◆ training_data() [1/2]

FANN::training_data::training_data | ( |  | ) |
| inline

Definition at line 370 of file myfann_cpp.h.

370 : train_data(NULL)
371 {
372 }

## ◆ training_data() [2/2]

FANN::training_data::training_data | ( | const training_data & | data | ) |
| inline

Definition at line 379 of file myfann_cpp.h.

380 {
381 destroy_train();
382 if (data.train_data != NULL)
383 {
384 train_data = fann_duplicate_train_data(data.train_data);
385 }
386 }

## ◆ ~training_data()

FANN::training_data::~training_data | ( |  | ) |
| inline

Definition at line 399 of file myfann_cpp.h.

400 {
401 destroy_train();
402 }

## Member Function Documentation

## ◆ create_train_from_callback()

void FANN::training_data::create_train_from_callback | ( | unsigned int | num_data,
|  | unsigned int | num_input,
|  | unsigned int | num_output,
|  | void(FANN_API *user_function)(unsigned int, unsigned int, unsigned int, fann_type *, fann_type *) |
| ) |  |
| inline

Definition at line 869 of file myfann_cpp.h.

877 {
878 destroy_train();
879 train_data = fann_create_train_from_callback(num_data, num_input, num_output, user_function);
880 }

## ◆ destroy_train()

void FANN::training_data::destroy_train | ( |  | ) |
| inline

Definition at line 411 of file myfann_cpp.h.

412 {
413 if (train_data != NULL)
414 {
415 fann_destroy_train(train_data);
416 train_data = NULL;
417 }
418 }

## ◆ get_input()

fann_type ** FANN::training_data::get_input | ( |  | ) |
| inline

Definition at line 605 of file myfann_cpp.h.

606 {
607 if (train_data == NULL)
608 {
609 return NULL;
610 }
611 else
612 {
613 return train_data->input;
614 }
615 }

## ◆ get_output()

fann_type ** FANN::training_data::get_output | ( |  | ) |
| inline

Definition at line 625 of file myfann_cpp.h.

626 {
627 if (train_data == NULL)
628 {
629 return NULL;
630 }
631 else
632 {
633 return train_data->output;
634 }
635 }

## ◆ length_train_data()

unsigned int FANN::training_data::length_train_data | ( |  | ) |
| inline

Definition at line 539 of file myfann_cpp.h.

540 {
541 if (train_data == NULL)
542 {
543 return 0;
544 }
545 else
546 {
547 return fann_length_train_data(train_data);
548 }
549 }

## ◆ merge_train_data()

void FANN::training_data::merge_train_data | ( | const training_data & | data | ) |
| inline

Definition at line 520 of file myfann_cpp.h.

521 {
522 fann_train_data *new_data = fann_merge_train_data(train_data, data.train_data);
523 if (new_data != NULL)
524 {
525 destroy_train();
526 train_data = new_data;
527 }
528 }

## ◆ num_input_train_data()

unsigned int FANN::training_data::num_input_train_data | ( |  | ) |
| inline

Definition at line 560 of file myfann_cpp.h.

561 {
562 if (train_data == NULL)
563 {
564 return 0;
565 }
566 else
567 {
568 return fann_num_input_train_data(train_data);
569 }
570 }

## ◆ num_output_train_data()

unsigned int FANN::training_data::num_output_train_data | ( |  | ) |
| inline

Definition at line 581 of file myfann_cpp.h.

582 {
583 if (train_data == NULL)
584 {
585 return 0;
586 }
587 else
588 {
589 return fann_num_output_train_data(train_data);
590 }
591 }

## ◆ read_train_from_file()

bool FANN::training_data::read_train_from_file | ( | const std::string & | filename | ) |
| inline

Definition at line 440 of file myfann_cpp.h.

441 {
442 destroy_train();
443 train_data = fann_read_train_from_file(filename.c_str());
444 return (train_data != NULL);
445 }

## ◆ save_train()

bool FANN::training_data::save_train | ( | const std::string & | filename | ) |
| inline

Definition at line 459 of file myfann_cpp.h.

460 {
461 if (train_data == NULL)
462 {
463 return false;
464 }
465 if (fann_save_train(train_data, filename.c_str()) == -1)
466 {
467 return false;
468 }
469 return true;
470 }

## ◆ save_train_to_fixed()

bool FANN::training_data::save_train_to_fixed | ( | const std::string & | filename,
|  | unsigned int | decimal_point
| ) |  |
| inline

Definition at line 486 of file myfann_cpp.h.

487 {
488 if (train_data == NULL)
489 {
490 return false;
491 }
492 if (fann_save_train_to_fixed(train_data, filename.c_str(), decimal_point) == -1)
493 {
494 return false;
495 }
496 return true;
497 }

## ◆ scale_input_train_data()

void FANN::training_data::scale_input_train_data | ( | fann_type | new_min,
|  | fann_type | new_max
| ) |  |
| inline

Definition at line 891 of file myfann_cpp.h.

892 {
893 if (train_data != NULL)
894 {
895 fann_scale_input_train_data(train_data, new_min, new_max);
896 }
897 }

## ◆ scale_output_train_data()

void FANN::training_data::scale_output_train_data | ( | fann_type | new_min,
|  | fann_type | new_max
| ) |  |
| inline

Definition at line 908 of file myfann_cpp.h.

909 {
910 if (train_data != NULL)
911 {
912 fann_scale_output_train_data(train_data, new_min, new_max);
913 }
914 }

## ◆ scale_train_data()

void FANN::training_data::scale_train_data | ( | fann_type | new_min,
|  | fann_type | new_max
| ) |  |
| inline

Definition at line 925 of file myfann_cpp.h.

926 {
927 if (train_data != NULL)
928 {
929 fann_scale_train_data(train_data, new_min, new_max);
930 }
931 }

## ◆ set_train_data() [1/4]

void FANN::training_data::set_train_data | ( | const std::vector< std::vector< fann_type > > & | input,
|  | const std::vector< std::vector< fann_type > > & | output
| ) |  |
| inline

Definition at line 692 of file myfann_cpp.h.

694 {
695 unsigned int num_data=input.size();
696 assert(num_data);
697 assert(input.size()==output.size());
698 unsigned int num_input=input[0].size();
699 unsigned int num_output=output[0].size();
700
701 // Uses the allocation method used in fann
702 struct fann_train_data *data =
703 (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
704 data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
705 data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
706
707 data->num_data = num_data;
708 data->num_input = num_input;
709 data->num_output = num_output;
710
711 fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
712 fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
713
714 for (unsigned int i = 0; i < num_data; ++i)
715 {
716 data->input[i] = data_input;
717 data_input += num_input;
718 for (unsigned int j = 0; j < num_input; ++j)
719 {
720 data->input[i][j] = input[i][j];
721 }
722 data->output[i] = data_output;
723 data_output += num_output;
724 for (unsigned int j = 0; j < num_output; ++j)
725 {
726 data->output[i][j] = output[i][j];
727 }
728 }
729 set_train_data(data);
730 }

## ◆ set_train_data() [2/4]

void FANN::training_data::set_train_data | ( | const std::vector< std::vector< std::vector< fann_type > > > & | input,
|  | unsigned int | num_data
| ) |  |
| inline

Definition at line 732 of file myfann_cpp.h.

733 {
734 assert(num_data);
735 assert(input.size());
736 unsigned int num_class=input.size();
737 assert(input[0].size());
738 unsigned int num_input=input[0][0].size();
739 unsigned int num_output=num_class;
740 //test
741// unsigned int num_output=1;
742
743 // Uses the allocation method used in fann
744 struct fann_train_data *data =
745 (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
746 data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
747 data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
748
749 data->num_data = num_data;
750 data->num_input = num_input;
751 data->num_output = num_output;
752
753 fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
754 fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
755
756 unsigned int isample=0;
757 for(int iclass=0;iclass<num_class;++iclass){
758 for(int csample=0;csample<input[iclass].size();++csample){
759 data->input[isample] = data_input;
760 data_input += num_input;
761 for(int iband=0;iband<input[iclass][csample].size();++iband){
762 assert(input[iclass][csample].size()==num_input);
763 data->input[isample][iband] = input[iclass][csample][iband];
764 }
765 data->output[isample] = data_output;
766 data_output += num_output;
767 for(int ic=0;ic<num_output;++ic){
768 //for single neuron output:
769// data->output[isample][ic]=2.0/(num_class-1)*(iclass-(num_class-1)/2.0);
770 if(ic==iclass)
771 data->output[isample][ic] = 1;
772 else
773 data->output[isample][ic] = -1;
774 }
775 ++isample;
776 }
777 }
778 set_train_data(data);
779 }

## ◆ set_train_data() [3/4]

void FANN::training_data::set_train_data | ( | const std::vector< Vector2d< fann_type > > & | input,
|  | unsigned int | num_data
| ) |  |
| inline

Definition at line 781 of file myfann_cpp.h.

782 {
783 assert(num_data);
784 assert(input.size());
785 unsigned int num_class=input.size();
786 assert(input[0].size());
787 unsigned int num_input=input[0][0].size();
788 unsigned int num_output=num_class;
789 //test
790// unsigned int num_output=1;
791
792 // Uses the allocation method used in fann
793 struct fann_train_data *data =
794 (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
795 data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
796 data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
797
798 data->num_data = num_data;
799 data->num_input = num_input;
800 data->num_output = num_output;
801
802 fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
803 fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
804
805 unsigned int isample=0;
806 for(int iclass=0;iclass<num_class;++iclass){
807 for(int csample=0;csample<input[iclass].size();++csample){
808 data->input[isample] = data_input;
809 data_input += num_input;
810 for(int iband=0;iband<input[iclass][csample].size();++iband){
811 assert(input[iclass][csample].size()==num_input);
812 data->input[isample][iband] = input[iclass][csample][iband];
813 }
814 data->output[isample] = data_output;
815 data_output += num_output;
816 for(int ic=0;ic<num_output;++ic){
817 //for single neuron output:
818// data->output[isample][ic]=2.0/(num_class-1)*(iclass-(num_class-1)/2.0);
819 if(ic==iclass)
820 data->output[isample][ic] = 1;
821 else
822 data->output[isample][ic] = -1;
823 }
824 ++isample;
825 }
826 }
827 set_train_data(data);
828 }

## ◆ set_train_data() [4/4]

void FANN::training_data::set_train_data | ( | unsigned int | num_data,
|  | unsigned int | num_input,
|  | fann_type ** | input,
|  | unsigned int | num_output,
|  | fann_type ** | output
| ) |  |
| inline

Definition at line 655 of file myfann_cpp.h.

658 {
659 // Uses the allocation method used in fann
660 struct fann_train_data *data =
661 (struct fann_train_data *)malloc(sizeof(struct fann_train_data));
662 data->input = (fann_type **)calloc(num_data, sizeof(fann_type *));
663 data->output = (fann_type **)calloc(num_data, sizeof(fann_type *));
664
665 data->num_data = num_data;
666 data->num_input = num_input;
667 data->num_output = num_output;
668
669 fann_type *data_input = (fann_type *)calloc(num_input*num_data, sizeof(fann_type));
670 fann_type *data_output = (fann_type *)calloc(num_output*num_data, sizeof(fann_type));
671
672 for (unsigned int i = 0; i < num_data; ++i)
673 {
674 data->input[i] = data_input;
675 data_input += num_input;
676 for (unsigned int j = 0; j < num_input; ++j)
677 {
678 data->input[i][j] = input[i][j];
679 }
680 data->output[i] = data_output;
681 data_output += num_output;
682 for (unsigned int j = 0; j < num_output; ++j)
683 {
684 data->output[i][j] = output[i][j];
685 }
686 }
687 set_train_data(data);
688 }

## ◆ shuffle_train_data()

void FANN::training_data::shuffle_train_data | ( |  | ) |
| inline

Definition at line 506 of file myfann_cpp.h.

507 {
508 if (train_data != NULL)
509 {
510 fann_shuffle_train_data(train_data);
511 }
512 }

## ◆ subset_train_data()

void FANN::training_data::subset_train_data | ( | unsigned int | pos,
|  | unsigned int | length
| ) |  |
| inline

Definition at line 951 of file myfann_cpp.h.

952 {
953 if (train_data != NULL)
954 {
955 struct fann_train_data *temp = fann_subset_train_data(train_data, pos, length);
956 destroy_train();
957 train_data = temp;
958 }
959 }

## Friends And Related Function Documentation

## ◆ neural_net

friend class neural_net
| friend

Definition at line 965 of file myfann_cpp.h.

## Member Data Documentation

## ◆ train_data

struct fann_train_data* FANN::training_data::train_data
| protected

Definition at line 968 of file myfann_cpp.h.

The documentation for this class was generated from the following file:

- /tmp/slackdce/slackrepo.NvCr9x/build_pktools/PKTOOLS-2.6.7.6/src/algorithms/myfann_cpp.h