// -*- C++ -*- // Copyright 2006 Deutsches Forschungszentrum fuer Kuenstliche Intelligenz // or its licensors, as applicable. // // You may not use this file except under the terms of the accompanying license. // // Licensed under the Apache License, Version 2.0 (the "License"); you // may not use this file except in compliance with the License. You may // obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // Project: bpnet -- Neural Network Classifier // File: bpnet.h // Purpose: Neural network classifier // Responsible: Hagen Kaprykowsky (kapry@iupr.net) // Reviewer: Yves Rangoni (rangoni@iupr.org) // Primary Repository: // Web Sites: www.iupr.org, www.dfki.de /// \file bpnet.h /// \brief Neural network classifier #ifndef h_bpnet_ #define h_bpnet_ #include "colib.h" #include "confusion-matrix.h" using namespace colib; using namespace ocropus; using namespace iupr_bpnet; namespace iupr_bpnet { class BpnetClassifier : public IClassifier { public: objlist vectors; narray classes; narray input; narray hidden; narray output; narray hidden_deltas; narray output_deltas; narray weights_hidden_input; narray hidden_offsets; narray weights_output_hidden; narray output_offsets; narray error; narray stdev; narray m_x; bool init; bool sigmoid_inited; bool training; bool norm; bool shuffle; int ninput; int nhidden; int noutput; int epochs; float learningrate; float testportion; autodel confusion_train; autodel confusion_test; autodel best_confusion_train; autodel best_confusion_test; bool filedump; stdio fp; strbuf buf; narray weights_hidden_input_best; narray hidden_offsets_best; narray weights_output_hidden_best; narray output_offsets_best; float eta_plus,eta_minus,eta_tol; bool vlr; void common_presets(); BpnetClassifier(); BpnetClassifier(const char* path_tmp_mlp); void set(const char *name,double value); void add(floatarray &v,int c); void startTraining(); void finishTraining(); void get_confusion_matrix( intarray &confusion_matrix_train_out, intarray &confusion_matrix_test_out); void seal(); void discriminant(floatarray &result,floatarray &v); void save(FILE *stream); void load(FILE *stream); void create(); void forward_one_input(int sample_index, int &target, int &predicted); void test_on_db(int n1, int n2, float &_error, float &cls_error, ConfusionMatrix& cm); void train(); void init_backprop(float range); void dealloc_train(); void forward(); void compute_error(int cls); void backward(); void update(); }; } namespace ocropus { /// Create a bpnet (standard backpropagation MLP) classifier. colib::IClassifier *make_BpnetClassifier(); /// Create a bpnet (standard backpropagation MLP) classifier /// After each epoch the current state of the MLP is saved /// into the file path_mlp_dump_into_file colib::IClassifier *make_BpnetClassifierDumpIntoFile( const char *path_mlp_dump_into_file); }; #endif