⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fann_cpp.h

📁 python 神经网络 数据挖掘 python实现的神经网络算法
💻 H
📖 第 1 页 / 共 5 页
字号:

public:
        /*********************************************************************/

        /* Method: create_train_from_callback
           Creates the training data struct from a user supplied function.
           As the training data are numerable (data 1, data 2...), the user must write
           a function that receives the number of the training data set (input,output)
           and returns the set.

           Parameters:
             num_data      - The number of training data
             num_input     - The number of inputs per training data
             num_output    - The number of ouputs per training data
             user_function - The user suplied function

           Parameters for the user function:
             num        - The number of the training data set
             num_input  - The number of inputs per training data
             num_output - The number of ouputs per training data
             input      - The set of inputs
             output     - The set of desired outputs
          
           See also:
             <training_data::read_train_from_file>, <neural_net::train_on_data>,
             <fann_create_train_from_callback>

            This function appears in FANN >= 2.1.0
        */ 
        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 * ))
        {
            destroy_train();
            train_data = fann_create_train_from_callback(num_data, num_input, num_output, user_function);
        }

        /* Method: scale_input_train_data
           
           Scales the inputs in the training data to the specified range.

           See also:
   	        <scale_output_train_data>, <scale_train_data>, <fann_scale_input_train_data>

           This function appears in FANN >= 2.0.0.
         */ 
        void scale_input_train_data(fann_type new_min, fann_type new_max)
        {
            if (train_data != NULL)
            {
                fann_scale_input_train_data(train_data, new_min, new_max);
            }
        }

        /* Method: scale_output_train_data
           
           Scales the outputs in the training data to the specified range.

           See also:
   	        <scale_input_train_data>, <scale_train_data>, <fann_scale_output_train_data>

           This function appears in FANN >= 2.0.0.
         */ 
        void scale_output_train_data(fann_type new_min, fann_type new_max)
        {
            if (train_data != NULL)
            {
                fann_scale_output_train_data(train_data, new_min, new_max);
            }
        }

        /* Method: scale_train_data
           
           Scales the inputs and outputs in the training data to the specified range.
           
           See also:
   	        <scale_output_train_data>, <scale_input_train_data>, <fann_scale_train_data>

           This function appears in FANN >= 2.0.0.
         */ 
        void scale_train_data(fann_type new_min, fann_type new_max)
        {
            if (train_data != NULL)
            {
                fann_scale_train_data(train_data, new_min, new_max);
            }
        }

        /* Method: subset_train_data
           
           Changes the training data to a subset, starting at position *pos* 
           and *length* elements forward. Use the copy constructor to work
           on a new copy of the training data.
           
            >FANN::training_data full_data_set;
            >full_data_set.read_train_from_file("somefile.train");
            >FANN::training_data *small_data_set = new FANN::training_data(full_data_set);
            >small_data_set->subset_train_data(0, 2); // Only use first two
            >// Use small_data_set ...
            >delete small_data_set;

           See also:
   	        <fann_subset_train_data>

           This function appears in FANN >= 2.0.0.
         */
        void subset_train_data(unsigned int pos, unsigned int length)
        {
            if (train_data != NULL)
            {
                struct fann_train_data *temp = fann_subset_train_data(train_data, pos, length);
                destroy_train();
                train_data = temp;
            }
        }

        /*********************************************************************/

    protected:
        /* The neural_net class has direct access to the training data */
        friend class neural_net;

        /* Pointer to the encapsulated training data */
        struct fann_train_data* train_data;
    };

    /*************************************************************************/

    /* Class: neural_net

        Encapsulation of a neural network <struct fann> and
        associated C API functions.
    */
    class neural_net
    {
    public:
        /* Constructor: neural_net
        
            Default constructor creates an empty neural net.
            Use one of the create functions to create the neural network.

            See also:
		        <create_standard>, <create_sparse>, <create_shortcut>,
		        <create_standard_array>, <create_sparse_array>, <create_shortcut_array>
        */
        neural_net() : ann(NULL)
        {
        }

        /* Destructor: ~neural_net

            Provides automatic cleanup of data.
            Define USE_VIRTUAL_DESTRUCTOR if you need the destructor to be virtual.

            See also:
                <destroy>
        */
#ifdef USE_VIRTUAL_DESTRUCTOR
        virtual
#endif
        ~neural_net()
        {
            destroy();
        }

        /* Method: destroy
        
            Destructs the entire network. Called automatically by the destructor.

            See also:
                <~neural_net>
        */
        void destroy()
        {
            if (ann != NULL)
            {
                user_context *user_data = static_cast<user_context *>(fann_get_user_data(ann));
                if (user_data != NULL)
                    delete user_data;

                fann_destroy(ann);
                ann = NULL;
            }
        }

        /* Method: create_standard
        	
	        Creates a standard fully connected backpropagation neural network.

	        There will be a bias neuron in each layer (except the output layer),
	        and this bias neuron will be connected to all neurons in the next layer.
	        When running the network, the bias nodes always emits 1.
        	
	        Parameters:
		        num_layers - The total number of layers including the input and the output layer.
		        ... - Integer values determining the number of neurons in each layer starting with the 
			        input layer and ending with the output layer.
        			
	        Returns:
		        Boolean true if the network was created, false otherwise.

            Example:
                >const unsigned int num_layers = 3;
                >const unsigned int num_input = 2;
                >const unsigned int num_hidden = 3;
                >const unsigned int num_output = 1;
                >
                >FANN::neural_net net;
                >net.create_standard(num_layers, num_input, num_hidden, num_output);

	        See also:
		        <create_standard_array>, <create_sparse>, <create_shortcut>,
		        <fann_create_standard_array>

	        This function appears in FANN >= 2.0.0.
        */ 
        bool create_standard(unsigned int num_layers, ...)
        {
            va_list layers;
            va_start(layers, num_layers);
            bool status = create_standard_array(num_layers,
                reinterpret_cast<const unsigned int *>(layers));
            va_end(layers);
            return status;
        }

        /* Method: create_standard_array

           Just like <create_standard>, but with an array of layer sizes
           instead of individual parameters.

	        See also:
		        <create_standard>, <create_sparse>, <create_shortcut>,
		        <fann_create_standard>

	        This function appears in FANN >= 2.0.0.
        */ 
        bool create_standard_array(unsigned int num_layers, const unsigned int * layers)
        {
            destroy();
            ann = fann_create_standard_array(num_layers, layers);
            return (ann != NULL);
        }

        /* Method: create_sparse

	        Creates a standard backpropagation neural network, which is not fully connected.

	        Parameters:
		        connection_rate - The connection rate controls how many connections there will be in the
   			        network. If the connection rate is set to 1, the network will be fully
   			        connected, but if it is set to 0.5 only half of the connections will be set.
			        A connection rate of 1 will yield the same result as <fann_create_standard>
		        num_layers - The total number of layers including the input and the output layer.
		        ... - Integer values determining the number of neurons in each layer starting with the 
			        input layer and ending with the output layer.
        			
	        Returns:
		        Boolean true if the network was created, false otherwise.

	        See also:
		        <create_standard>, <create_sparse_array>, <create_shortcut>,
		        <fann_create_sparse>

	        This function appears in FANN >= 2.0.0.
        */
        bool create_sparse(float connection_rate, unsigned int num_layers, ...)
        {
            va_list layers;
            va_start(layers, num_layers);
            bool status = create_sparse_array(connection_rate, num_layers,
                reinterpret_cast<const unsigned int *>(layers));
            va_end(layers);
            return status;
        }

        /* Method: create_sparse_array
           Just like <create_sparse>, but with an array of layer sizes
           instead of individual parameters.

           See <create_sparse> for a description of the parameters.

	        See also:
		        <create_standard>, <create_sparse>, <create_shortcut>,
		        <fann_create_sparse_array>

	        This function appears in FANN >= 2.0.0.
        */
        bool create_sparse_array(float connection_rate,
            unsigned int num_layers, const unsigned int * layers)
        {
            destroy();
            ann = fann_create_sparse_array(connection_rate, num_layers, layers);
            return (ann != NULL);
        }

        /* Method: create_shortcut

	        Creates a standard backpropagation neural network, which is not fully connected and which
	        also has shortcut connections.

 	        Shortcut connections are connections that skip layers. A fully connected network with shortcut 
	        connections, is a network where all neurons are connected to all neurons in later layers. 
	        Including direct connections from the input layer to the output layer.

	        See <create_standard> for a description of the parameters.

	        See also:
		        <create_standard>, <create_sparse>, <create_shortcut_array>,
		        <fann_create_shortcut>

	        This function appears in FANN >= 2.0.0.
        */ 
        bool create_shortcut(unsigned int num_layers, ...)
        {
            va_list layers;
            va_start(layers, num_layers);
            bool status = create_shortcut_array(num_layers,
                reinterpret_cast<const unsigned int *>(layers));
            va_end(layers);
            return status;
        }

        /* Method: create_shortcut_array

           Just like <create_shortcut>, but with an array of layer sizes
           instead of individual parameters.

	        See <create_standard_array> for a description of the parameters.

	        See also:
		        <create_standard>, <create_sparse>, <create_shortcut>,
		        <fann_create_shortcut_array>

	        This function appears in FANN >= 2.0.0.
        */
        bool create_shortcut_array(unsigned int num_layers,
            const unsigned int * layers)
        {
            destroy();
            ann = fann_create_shortcut_array(num_layers, layers);
            return (ann != NULL);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -