| 
    Algorithms_in_C
    1.0.0
    
   Set of algorithms implemented in C. 
   | 
 
 
 
 
◆ adaline_activation()
      
        
          | int adaline_activation  | 
          ( | 
          double  | 
          x | ) | 
           | 
        
      
 
Heaviside activation function 
 
- Parameters
 - 
  
    | x | activation function input  | 
  
   
- Returns
 - \(f(x)= \begin{cases}1 & \forall\; x > 0\\ -1 & \forall\; x \le0 \end{cases}\) 
 
  105 { 
return x > 0 ? 1 : -1; }
 
 
 
 
◆ adaline_fit()
      
        
          | void adaline_fit  | 
          ( | 
          struct adaline *  | 
          ada,  | 
        
        
           | 
           | 
          double **  | 
          X,  | 
        
        
           | 
           | 
          const int *  | 
          y,  | 
        
        
           | 
           | 
          const int  | 
          N  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Update the weights of the model using supervised learning for an array of vectors. 
- Parameters
 - 
  
    | [in] | ada | adaline model to train  | 
    | [in] | X | array of feature vector  | 
    | [in] | y | known output value for each feature vector  | 
    | [in] | N | number of training samples  | 
  
   
  186     double avg_pred_error = 1.f;
 
  193         avg_pred_error = 0.f;
 
  196         for (
int i = 0; i < N; i++)
 
  199             avg_pred_error += fabs(err);
 
  205         printf(
"\tIter %3d: Training weights: %s\tAvg error: %.4f\n", iter,
 
  210         printf(
"Converged after %d iterations.\n", iter);
 
  212         printf(
"Did not converged after %d iterations.\n", iter);
 
 
 
 
◆ adaline_fit_sample()
      
        
          | double adaline_fit_sample  | 
          ( | 
          struct adaline *  | 
          ada,  | 
        
        
           | 
           | 
          const double *  | 
          x,  | 
        
        
           | 
           | 
          const int  | 
          y  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Update the weights of the model using supervised learning for one feature vector. 
- Parameters
 - 
  
    | [in] | ada | adaline model to fit  | 
    | [in] | x | feature vector  | 
    | [in] | y | known output value  | 
  
   
- Returns
 - correction factor 
 
  162     int prediction_error = y - p;  
 
  163     double correction_factor = ada->
eta * prediction_error;
 
  168         ada->
weights[i] += correction_factor * x[i];
 
  172     return correction_factor;
 
 
 
 
◆ adaline_get_weights_str()
      
        
          | char* adaline_get_weights_str  | 
          ( | 
          const struct adaline *  | 
          ada | ) | 
           | 
        
      
 
Operator to print the weights of the model. 
- Parameters
 - 
  
    | ada | model for which the values to print  | 
  
   
- Returns
 - pointer to a NULL terminated string of formatted weights 
 
  114     static char out[100];  
 
  119         sprintf(out, 
"%s%.4g", out, ada->
weights[i]);
 
  120         if (i < ada->num_weights - 1)
 
  121             sprintf(out, 
"%s, ", out);
 
  123     sprintf(out, 
"%s>", out);
 
 
 
 
◆ adaline_predict()
      
        
          | int adaline_predict  | 
          ( | 
          struct adaline *  | 
          ada,  | 
        
        
           | 
           | 
          const double *  | 
          x,  | 
        
        
           | 
           | 
          double *  | 
          out  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
predict the output of the model for given set of features 
- Parameters
 - 
  
    | [in] | ada | adaline model to predict  | 
    | [in] | x | input vector  | 
    | [out] | out | optional argument to return neuron output before applying activation function (NULL to ignore)  | 
  
   
- Returns
 - model prediction output 
 
 
 
◆ delete_adaline()
      
        
          | void delete_adaline  | 
          ( | 
          struct adaline *  | 
          ada | ) | 
           | 
        
      
 
delete dynamically allocated memory 
- Parameters
 - 
  
    | [in] | ada | model from which the memory is to be freed.  | 
  
   
 
 
◆ new_adaline()
      
        
          | struct adaline new_adaline  | 
          ( | 
          const int  | 
          num_features,  | 
        
        
           | 
           | 
          const double  | 
          eta  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Default constructor. 
- Parameters
 - 
  
    | [in] | num_features | number of features present  | 
    | [in] | eta | learning rate (optional, default=0.1)  | 
  
   
- Returns
 - new adaline model 
 
   61     if (eta <= 0.f || eta >= 1.f)
 
   63         fprintf(stderr, 
"learning rate should be > 0 and < 1\n");
 
   68     int num_weights = num_features + 1;
 
   72     ada.weights = (
double *)malloc(
num_weights * 
sizeof(
double));
 
   75         perror(
"Unable to allocate error for weights!");
 
   80     for (
int i = 0; i < 
num_weights; i++) ada.weights[i] = 1.f;
 
 
 
 
 
 
double * weights
weights of the neural network
Definition: adaline_learning.c:46
 
int adaline_activation(double x)
Heaviside activation function
Definition: adaline_learning.c:105
 
#define ADALINE_ACCURACY
convergence accuracy
Definition: adaline_learning.c:51
 
double adaline_fit_sample(struct adaline *ada, const double *x, const int y)
Update the weights of the model using supervised learning for one feature vector.
Definition: adaline_learning.c:158
 
double eta
learning rate of the algorithm
Definition: adaline_learning.c:45
 
#define MAX_ADALINE_ITER
Maximum number of iterations to learn.
Definition: adaline_learning.c:40
 
int adaline_predict(struct adaline *ada, const double *x, double *out)
predict the output of the model for given set of features
Definition: adaline_learning.c:136
 
structure to hold adaline model parameters
Definition: adaline_learning.c:44
 
char * adaline_get_weights_str(const struct adaline *ada)
Operator to print the weights of the model.
Definition: adaline_learning.c:112
 
int num_weights
number of weights of the neural network
Definition: adaline_learning.c:47