Advertisement
Guest User

Untitled

a guest
Jul 7th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.71 KB | None | 0 0
  1. package body Generic_Network is
  2.    procedure Compute_Output (Input : Input_Vector_T; Network : in out Network_T) is
  3.    begin
  4.       for Neuron_Num in Network.Input_Layer'Range loop
  5.          Network.Input_Layer(Neuron_Num).Output := Input(Neuron_Num)*
  6.            Network.Input_Layer(Neuron_Num).Weight + Network.Input_Layer(Neuron_Num).Bias;
  7.       end loop;
  8.  
  9.       for Neuron_Num in Network.Hidden_Layer'Range loop
  10.          Network.Hidden_Layer(Neuron_Num).Output := 0.0;
  11.          for Weight_Num in Network.Hidden_Layer(Neuron_Num).Weights'Range loop
  12.             Network.Hidden_Layer(Neuron_Num).Output := Network.Hidden_Layer(Neuron_Num).Output +
  13.               Network.Hidden_Layer(Neuron_Num).Weights(Weight_Num) *
  14.               Network.Input_Layer(Weight_Num).Output;
  15.          end loop;
  16.          Network.Hidden_Layer(Neuron_Num).Output := Network.Hidden_Layer(Neuron_Num).Output +
  17.            Network.Hidden_Layer(Neuron_Num).Bias;
  18.       end loop;
  19.  
  20.      for Neuron_Num in Network.Output_Layer'Range loop
  21.         null;
  22.      end loop;
  23.    end Compute_Output;
  24. end Generic_Network;
  25. generic
  26.    Input_Len : Positive;
  27.    Hidden_Layer_Len : Positive;
  28.    Output_Layer_Len : Positive;
  29. package Generic_Network is
  30.    type Weight_T is delta 0.0000001 range -100.0..100.0;
  31.    type Input_Vector_T is array (1..Input_Len) of Weight_T;
  32.  
  33.    type Hidden_Weights_T is array (1..Input_Len) of Weight_T;
  34.    type Output_Weights_T is array (1..Hidden_Layer_Len) of Weight_T;
  35.  
  36.    type Input_Neuron_T is record
  37.       Weight : Weight_T;
  38.       D : Weight_T;
  39.       Bias : Weight_T;
  40.       Output : Weight_T;
  41.    end record;
  42.  
  43.    type Hidden_Neuron_T is record
  44.       Weights : Hidden_Weights_T;
  45.       D : Weight_T;
  46.       Bias : Weight_T;
  47.       Output : Weight_T;
  48.    end record;
  49.  
  50.    type Output_Neuron_T is record
  51.       Weights : Output_Weights_T;
  52.       D : Weight_T;
  53.       Bias : Weight_T;
  54.       Output : Weight_T;
  55.    end record;
  56.  
  57.    type Input_Layer_T is array (1..Input_Len) of Input_Neuron_T;
  58.    type Hidden_Layer_T is array (1..Hidden_Layer_Len) of Hidden_Neuron_T;
  59.    type Output_Layer_T is array (1..Output_Layer_Len) of Output_Neuron_T;
  60.  
  61.    type Network_T is record
  62.       Input_Layer : Input_Layer_T;
  63.       Hidden_Layer : Hidden_Layer_T;
  64.       Output_Layer : Output_Layer_T;
  65.    end record;
  66.  
  67.    procedure Compute_Output (Input : Input_Vector_T; Network : in out Network_T)
  68.      with Global => null,
  69.      Depends => (Network =>+ Input);
  70. end Generic_Network;
  71.  
  72. with Generic_Network;
  73. procedure Main with SPARK_Mode => On is
  74.    package MLP is new Generic_Network(Input_Len => 2,
  75.                                      Hidden_Layer_Len => 2,
  76.                                      Output_Layer_Len => 1);
  77. begin
  78.    null;
  79. end Main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement