Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
891 connectés 

  FORUM HardWare.fr
  Programmation
  Ada

  Plantage de taches.

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Plantage de taches.

n°1974759
Profil sup​primé
Posté le 17-03-2010 à 22:54:53  answer
 

bonsoir,
 
j'ai un petit propblème avec mes taches... Je viens faire le point.
 
Attention, pavé !
 

Code :
  1. with PragmARC.REM_NN_Wrapper;
  2. use PragmARC.REM_NN_Wrapper;
  3.  
  4. with PragmARC.Math.Functions;
  5.  
  6. with Generic_Extended_Binary_Code;
  7.  
  8. with Direct_Io;
  9.  
  10. with Time_To_Date, Ada.Strings.Fixed, Split_Heure, Text_Io;
  11. use Time_To_Date, Ada.Strings, Split_Heure, Text_Io;
  12.  
  13. with Ada.Characters.Handling;
  14. use Ada.Characters.Handling;
  15.  
  16. with Ada.Strings.Unbounded;
  17. use Ada.Strings.Unbounded;
  18.  
  19. with Ada.Directories;
  20. use Ada.Directories;
  21.  
  22. with PragmARC.Wrapping;
  23.  
  24. package body Ai is
  25.  
  26.   task body T_Console is
  27.  
  28.  
  29.  
  30.  
  31.      Status : Unbounded_String;
  32.      Date   : String(1..80) := (others => Character'Val(32));
  33.      Title  : String(1..80) := (others => Character'Val(32));
  34.      End_Of_Task : Boolean := False;
  35.      Word        : String(1..64) := (others => Character'Val(32));
  36.      Word_Last   : Natural := 0;
  37.      Response,
  38.      Line        : T_Lang_Array(1..Sentence_lenght) := (others => 0);
  39.      Line_Last   : Natural := 0;
  40.      Length      : Natural := 0;
  41.      Count_Line  : Integer := 0;
  42.      Available   : Boolean := False;
  43.      Input_Message  : T_Message_Box := (new String ' (Logname.all),
  44.                                         (others => 0));
  45.      Output_Message : T_Message_Box := (null,
  46.                                         (others => 0));
  47.      Data_Entry : Boolean := False;
  48.      Data : T_Lang_Array(1..Sentence_Lenght) := (others => Keyword("" ));
  49.   begin
  50.  
  51.      Fixed.Move("Prophet Server",
  52.                 Title, Error, Center, Space);
  53.  
  54.      while not End_Of_Task loop
  55.         select
  56.            Message_Io.Look(Logname.all, available);
  57.            if Available then
  58.               Message_Io.Send(Logname.all, Output_message);
  59.               Response := Output_Message.Message;
  60.            end if;
  61.         or
  62.            delay 0.05;
  63.         end select;
  64.  
  65.         select
  66.            accept Receive(Char : in Character) do
  67.               begin
  68.                  if Is_Special(Char) then
  69.                     case Char is
  70.                        when Character'Val(32) =>
  71.                           if Line_Last < Line'Length and
  72.                             Word_Last /= 0 then
  73.                              begin
  74.                                 Line(Line_Last + 1) :=
  75.                                   Keyword(Word(1..Word_Last));
  76.                                 Line_Last := Line_Last + 1;
  77.                                 Word := (others => Character'Val(32));
  78.                                 Word_Last := 0;
  79.                              exception
  80.                                 when others => -- Specification_Error =>
  81.                                    null;
  82.                              end;
  83.                           end if;
  84.                        when others =>
  85.                           if Word_Last < Word'Length then
  86.                              Word(Word_Last + 1) := Char;
  87.                              Word_Last := Word_Last + 1;
  88.                           end if;
  89.                     end case;
  90.                  else
  91.                     case Char is
  92.                        when Character'Val(10) =>
  93.                           if Line_Last < Line'Length and
  94.                             Word_Last /= 0 then
  95.                              begin
  96.                                 Line(Line_Last + 1) :=
  97.                                   Keyword(Word(1..Word_Last));
  98.                                 Line_Last := Line_Last + 1;
  99.                                 Input_Message.Message := Line;
  100.                                 Message_Io.Receive(Program_Logname, Input_Message);
  101.                                 Line := (others => 0);
  102.                                 Line_Last := 0;
  103.                                 Word := (others => Character'Val(32));
  104.                                 Word_Last := 0;
  105.                              exception
  106.                                 when others => -- Specification_Error =>
  107.                                    null;
  108.                              end;
  109.                           end if;
  110.  
  111.                        when Character'Val(127) =>
  112.                           if Word_Last > 0 then
  113.                              Word(Word_Last) := Character'Val(32);
  114.                              Word_Last := Word_Last - 1;
  115.                           elsif Line_Last /= 0 then
  116.                              Line(Line_Last) := 0;
  117.                              Line_Last := Line_Last - 1;
  118.                           end if;
  119.                        when others =>
  120.                           if Word_Last < Word'Length then
  121.                              Word(Word_Last + 1) := Char;
  122.                              Word_Last := Word_Last + 1;
  123.                           end if;
  124.                     end case;
  125.                  end if;
  126.               exception
  127.                  when others =>
  128.                     null;
  129.               end;
  130.               Put(Clear_Screen);
  131.  
  132.               Fixed.Move(Full_Datify_String(Clock),
  133.                          Date, Error, center, Space);
  134.  
  135.               Put_Line(Bold_Mode & Title & Normal);
  136.               Put_Line(Yellow & Date & Normal);
  137.               New_Line;
  138.               Put_Line(Green & To_String(Status) & Normal);
  139.               New_Line;
  140.               Put('#' & Blue);
  141.               Length := 0;
  142.               for Key in 1..Response'length loop
  143.                  begin
  144.                     Put(Image(Response(Key)) & ' ');
  145.                     Length := Length + Image(Response(Key))'Length + 1;
  146.                  exception
  147.                     when others => -- Specification_Error =>
  148.                        null;
  149.                  end;
  150.               end loop;
  151.               Count_Line := 10;
  152.               Count_Line := Count_line - (Length/80+1);
  153.               if Count_Line > 0 then
  154.                  New_Line(Text_Io.Count(Count_Line));
  155.               else
  156.                  New_Line;
  157.               end if;
  158.               Length := 0;
  159.               Put(normal & '#' & Blue);
  160.               for Key in 1..Line_Last loop
  161.                  Put(Image(Line(Key)) & ' ');
  162.                  Length := Length + Image(Line(Key))'Length+1;
  163.               end loop;
  164.               Put(Red & Word(1..Word_Last) & Normal);
  165.            end Receive;
  166.         or
  167.            accept Halt do
  168.               End_Of_Task := True;
  169.            end Halt;
  170.         or
  171.            delay 0.25;
  172.  
  173.  
  174.  
  175.            Fixed.Move(Full_Datify_String(Clock),
  176.                       Date, Error, Center, Space);
  177.  
  178.  
  179.            select
  180.               Life_Cycle.Status(Status, Data_Entry, data);
  181.  
  182.            or
  183.               delay 0.0;
  184.            end select;
  185.            Put(Clear_Screen);
  186.            Put_Line(Bold_mode & Title & normal);
  187.            Put_Line(Yellow & Date & Normal);
  188.            New_Line;
  189.            Put_line(Green & To_String(Status) & Normal);
  190.            New_Line;
  191.            if Data_Entry then
  192.               for Key in 1..data'length loop
  193.                  begin
  194.                     Put(Image(data(Key)) & ' ');
  195.                     Length := Length + Image(data(Key))'Length + 1;
  196.                  exception
  197.                     when others => -- Specification_Error =>
  198.                        null;
  199.                  end;
  200.               end loop;
  201.            end if;
  202.            New_Line;
  203.            Put('#' & blue);
  204.            Length := 0;
  205.            Count_Line := 10;
  206.            for Key in 1..Response'length loop
  207.               begin
  208.                  Put(Image(Response(Key)) & ' ');
  209.                  Length := Length + Image(Response(Key))'Length + 1;
  210.               exception
  211.                  when others => -- Specification_Error =>
  212.                     null;
  213.               end;
  214.            end loop;
  215.            Count_Line := Count_line - (Length/80+1);
  216.                if Count_Line > 0 then
  217.                   New_Line(Text_Io.Count(Count_Line));
  218.                else
  219.                   New_Line;
  220.                end if;
  221.                Length := 0;
  222.                Put(Normal & '#' & Blue);
  223.                for Key in 1..Line_Last loop
  224.                   Put(Image(Line(Key)) & ' ');
  225.                   Length := Length + Image(Line(Key))'Length + 1;
  226.                end loop;
  227.                Put(Red & Word(1..Word_Last) & Normal);
  228.         end select;
  229.      end loop;
  230.   end T_Console;
  231.  
  232.   --package Real_Io is new Text_Io.Float_Io(Real);
  233.   package Real_Math is new PragmARC.Math.Functions (Supplied_Real => Real);
  234.   package Coded_Word is new Generic_Extended_Binary_Code(T_Language);
  235.   use Coded_Word;
  236.   subtype T_Register is Node_Set(1..Sentence_Lenght*T_Code'length);
  237.   package Register_Io is new Direct_Io(T_Register);
  238.   use Register_Io;
  239.  
  240.  
  241.   procedure Table2register(Table : in T_Lang_Array;
  242.                            Register : out T_Register) is
  243.      Code : T_Code;
  244.   begin
  245.      for I in 0..Table'Length-1 loop
  246.         Code := Code_Of(Table(I+1));
  247.         for J in T_Code'Range loop
  248.            Register(I*T_Code'Length+J) := Code(J);
  249.         end loop;
  250.      end loop;
  251.   end Table2register;
  252.  
  253.   procedure Register2table(Register : in T_Register;
  254.                            Table    : out  T_Lang_Array) is
  255.      Code : T_Code;
  256.   begin
  257.      for I in 0..Table'Length-1 loop
  258.         begin
  259.            Code := Register(I*T_Code'Length+1..I*T_Code'Length+T_Code'Length);
  260.            Table(I+1) := Item_Of(Code);
  261.         exception
  262.            when others =>
  263.               null;
  264.         end;
  265.      end loop;
  266.   end Register2table;
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   -- Gadget --
  273.   type T_Cross is ('-', '\', '|', '/');
  274.   package Cross_Wrapping is new PragmARC.Wrapping(T_Cross);
  275.   use Cross_Wrapping;
  276.  
  277.  
  278.  
  279.  
  280.  
  281.   task Network_Manager is
  282.      entry Start(Train_Length : in Positive;
  283.                  Train_Filename : in String;
  284.                  Network_Filename : in String;
  285.                  Reuse_Network : in boolean);
  286.      entry Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  287.                   Available : out Boolean; Sentence : out T_Lang_array);
  288.      entry Respond(Network : in String;
  289.                    Register : in out T_Register);
  290.      entry Stop;
  291.      entry Halt;
  292.   end Network_Manager;
  293.  
  294.  
  295.  
  296.   task body Network_Manager is
  297.  
  298.  
  299.      Train_File,
  300.      Prob_File : Register_Io.File_Type;
  301.      Prob_Filename   : constant String := "data/registers/prob.bin";
  302.      Network : Unbounded_String;
  303.      Length : Positive;
  304.      Reuse : Boolean;
  305.      End_Of_Task, Suspended : Boolean := False;
  306.   begin
  307.  
  308.  
  309.      while not End_Of_Task loop
  310.  
  311.         Suspended := false;
  312.         select
  313.  
  314.  
  315.            accept Start(Train_Length : in Positive;
  316.                         Train_Filename : in String;
  317.                         Network_Filename : in String;
  318.                         Reuse_Network : in boolean) do
  319.               Length := Train_Length;
  320.               Network := To_Unbounded_String(Network_Filename);
  321.               Reuse := Reuse_Network;
  322.               Register_Io.Open(Train_File,
  323.                                Register_Io.In_File,
  324.                                Train_Filename);
  325.               Text_Io.Put_Line("TOTO 6" );
  326.            end Start;
  327.  
  328.         or
  329.  
  330.  
  331.            accept Respond(Network : in String;
  332.                           Register : in out T_Register) do
  333.               Register_Io.create(Prob_File,
  334.                                  Register_Io.Out_File,
  335.                                  Prob_Filename);
  336.               Register_Io.Write(Prob_File, Register);
  337.               Register_Io.Close(Prob_File);
  338.  
  339.               declare
  340.  
  341.                  procedure Get_Expl(Pattern : in Positive;
  342.                                     Input : out Node_Set;
  343.                                          Desired : out Node_Set) is
  344.                  Register : T_Register := (others => 0.0);
  345.               begin
  346.                  Register_Io.Open(Prob_File,
  347.                                   Register_Io.In_File,
  348.                                   Prob_Filename);
  349.                  Read(Prob_File,
  350.                       Register,
  351.                       1);
  352.                  Input := Node_Set(Register);
  353.  
  354.                  Desired := (others => 0.0);
  355.                  Register_Io.Close(Prob_File);
  356.               end Get_Expl;
  357.  
  358.               package REM_NN_Expl is new REM_NN
  359.                         (
  360.                          Num_Input_Nodes => T_Register'length,
  361.                          Num_Hidden_Nodes => T_Register'Length/T_Code'Length,
  362.                          Num_Output_Nodes => T_Register'length,
  363.                          Num_Patterns => 1,
  364.                          New_Random_Weights => False,
  365.                          Input_To_Output_Connections => False,
  366.                          Weight_File_Name => Network,
  367.                          Get_Input => Get_Expl
  368.                          );
  369.  
  370.               use REM_NN_Expl;
  371.  
  372.  
  373.               begin
  374.  
  375.                  Respond(1, Register);
  376.  
  377.               end;
  378.  
  379.  
  380.  
  381.  
  382.               Register_Io.open(Prob_File,
  383.                                Register_Io.Out_File,
  384.                                Prob_Filename);
  385.               Register_Io.Delete(Prob_File);
  386.  
  387.  
  388.               Suspended := True;
  389.  
  390.            end Respond;
  391.  
  392.         or
  393.  
  394.            accept Halt do
  395.               Suspended := True;
  396.               End_Of_Task := True;
  397.            end Halt;
  398.  
  399.  
  400.         end select;
  401.  
  402.  
  403.         Text_Io.Put_Line("TOTO 7" );
  404.  
  405.         declare
  406.  
  407.            procedure Get_Train(Pattern : in Positive;
  408.                                Input : out Node_Set;
  409.                                Desired : out Node_Set) is
  410.               Register : T_Register := (others => 0.0);
  411.            begin
  412.  
  413.               Read(Train_File,
  414.                    Register,
  415.                    Register_Io.Count(Pattern*2-1));
  416.               Input := Node_Set(Register);
  417.  
  418.               Read(Train_File,
  419.                    Register,
  420.                    Register_Io.Count(Pattern*2));
  421.               Desired := Node_Set(Register);
  422.            end Get_Train;
  423.  
  424.            package REM_NN_Train is new REM_NN
  425.              (
  426.               Num_Input_Nodes => T_Register'length,
  427.               Num_Hidden_Nodes => T_Register'Length/T_Code'Length,
  428.               Num_Output_Nodes => T_Register'length,
  429.               Num_Patterns => Length,
  430.               New_Random_Weights => not Reuse,
  431.               Input_To_Output_Connections => False,
  432.               Weight_File_Name => To_String(Network),
  433.               Get_Input => Get_Train
  434.               );
  435.  
  436.            use REM_NN_Train;
  437.            Register : T_Register := (others => 0.0);
  438.            Response : REM_NN_Train.Output_Set := (others => 0.0);
  439.            Desired_Output : array (1..Length) of
  440.              REM_NN_Train.Output_Set;
  441.            RMS_Error : Real := 0.5;
  442.            Error     : Real := 0.0;
  443.            Converged  : constant real := 0.05;
  444.            Max_Epochs : constant Positive := Length*500;
  445.            Epoch : Natural := 0;
  446.  
  447.            Cross : T_Cross := T_Cross'Val(0);
  448.  
  449.            -- Time indication
  450.  
  451.            Date : Time := Clock;
  452.            Heure, Minute, Seconde, Reste : Natural := 0;
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.         begin
  460.            Text_Io.Put_Line("TOTO 8" );
  461.  
  462.            for I in 1..Desired_Output'Length loop
  463.               Register_Io.Read(train_File,
  464.                                Register,
  465.                                Register_Io.Count(i*2));
  466.  
  467.               Desired_Output(I) := REM_NN_Train.Output_Set(Register);
  468.            end loop;
  469.            Date := Clock;
  470.  
  471.            while not Suspended loop
  472.  
  473.  
  474.               select
  475.                  accept Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  476.                                Available : out Boolean; Sentence : out T_Lang_array) do
  477.                     Split(Clock - Date, Heure, Minute, Seconde, reste);
  478.  
  479.                     Info :=
  480.                       To_Unbounded_String
  481.                       (" Trainning Expe file of length :" &
  482.                        Integer'Image(Length) &
  483.                        Character'Val(10) &
  484.                        " Epoch : " &
  485.                        Integer'Image(Epoch) &
  486.                        " ; " &
  487.                        "RMS_Error : " &
  488.                        Real'Image(RMS_Error) &
  489.                        " " &
  490.                        (Character'value
  491.                         (T_Cross'image(Cross)))
  492.                        & "    " &
  493.                        Integer'Image(Integer((Converged/RMS_error)*100.0)) &
  494.                        '%' &
  495.                        Integer'Image(Heure) &
  496.                        ':' &
  497.                        Integer'Image(Minute) &
  498.                        ':' &
  499.                        Integer'Image(Seconde) &
  500.                        ':' &
  501.                        Integer'Image(Reste) & Latin_1.Lf &
  502.                        Reverse_Video &
  503.                        Fixed."*"(Integer((((80.0/RMS_Error)/(20.0))))+1,' ') & Normal);
  504.  
  505.                     Available := True;
  506.  
  507.  
  508.                     for I in Register'Range loop
  509.                        if Register(I) > 0.5 then
  510.                           Register(I) := 1.0;
  511.                        else
  512.                           Register(I) := 0.0;
  513.                        end if;
  514.                     end loop;
  515.  
  516.                     Register2Table(Response, Sentence);
  517.  
  518.  
  519.                     Cross  := Wrap_Succ(Cross);
  520.                  end Status;
  521.               or
  522.  
  523.                  when RMS_Error < Converged or Epoch > Max_Epochs =>
  524.                     accept Stop do
  525.                        Suspended := True;
  526.                     end Stop;
  527.  
  528.               or
  529.  
  530.                  delay 0.01;
  531.  
  532.                  if (Epoch <= Max_Epochs ) and
  533.                    (RMS_Error > Converged) then
  534.                     for Pattern in 1..Length loop
  535.                        REM_NN_Train.Train;
  536.                        REM_NN_Train.Respond (Pattern, Response);
  537.                        for I in Response'Range loop
  538.                           Error := Error + (Desired_Output(Pattern)(i) -   Response(i) );
  539.                        end loop;
  540.                        RMS_Error := RMS_Error + ((Error/Real(Response'Length)) ** 2);
  541.                        Error := 0.0;
  542.                        Response := (others => 0.0);
  543.                     end loop;
  544.                     RMS_Error := Real_Math.Sqrt(RMS_Error/Real(Length));
  545.                     Epoch := Epoch + 1;
  546.                  end if;
  547.  
  548.  
  549.               end select;
  550.            end loop;
  551.            REM_NN_Train.Save_Weights;
  552.         end;
  553.         Register_Io.Close(Train_File);
  554.      end loop;
  555.   end Network_Manager;
  556.  
  557.  
  558.   task body Life_Cycle is
  559.      Source_File     : Text_Io.File_Type;
  560.      Source_Filename : Unbounded_String;
  561.      Word            : String(1..64) := (others => Character'Val(32));
  562.      Word_Last       : Natural := 0;
  563.      Char            : Character;
  564.      Sentence        : T_Lang_Array(1..Sentence_Lenght) := (others => 0);
  565.      Sentence_Index  : Natural := 0;
  566.      Train_File,
  567.      Prob_File       : Register_Io.File_Type;
  568.      Train_Filename  : Unbounded_String;
  569.  
  570.      Register, Feed_back : T_Register := (others => 0.0);
  571.      Train_Length : Natural := 0;
  572.  
  573.      End_Of_Task : Boolean := False;
  574.  
  575.      Input  : T_Message_Box := (null, (others => 0));
  576.      Output : T_Message_Box := (new String ' (Program_Logname), (others => 0));
  577.      Available : Boolean := False;
  578.  
  579.  
  580.      Cross : T_Cross := T_Cross'Val(0);
  581.  
  582.      -- Time indication
  583.      Date_string   : String(1..80) := (others => Character'Val(32));
  584.      Banner : String(1..80) := (others => Character'Val(32));
  585.  
  586.  
  587.      -- Experience set
  588.      Expe_Filename : constant String := "data/registers/expe.bin";
  589.      Expe_File     : Register_Io.File_Type;
  590.      Expe_Length   : Natural := 0;
  591.      Free : Boolean := False;
  592.      Info : Unbounded_String;
  593.   begin
  594.  
  595.  
  596.      accept Start(Date : out Time) do
  597.         Date := Clock;
  598.  
  599.  
  600.  
  601.         Put_Line("TOTO -1" );
  602.  
  603.  
  604.  
  605.  
  606.         Register_Io.Create(Prob_File,
  607.                            Register_Io.Out_File,
  608.                            Expe_filename);
  609.         Register_Io.Write(Prob_File, Register);
  610.         Register_Io.Close(Prob_File);
  611.  
  612.         if not Exists("data/networks/Expe.wgt" ) then
  613.  
  614.  
  615.  
  616.            Put_Line("TOTO 0" );
  617.            Register_Io.Create(Expe_File,
  618.                               Register_Io.Out_File,
  619.                               Expe_filename);
  620.            Register_Io.Write(Expe_File,
  621.                           Feed_Back,
  622.                              Register_Io.Size(Expe_File)+1);
  623.            Register_Io.Write(Expe_File,
  624.                              register,
  625.                              Register_Io.Size(Expe_File)+1);
  626.  
  627.            Register_Io.Close(Expe_File);
  628.            Put_Line("TOTO 1" );
  629.  
  630.  
  631.            Expe_Length := 1;
  632.  
  633.  
  634.  
  635.  
  636.  
  637.            Put_Line("TOTO 2" );
  638.            Network_Manager.Start(
  639.                                  Expe_Length,
  640.                                  Expe_Filename,
  641.                                  "data/networks/Expe.wgt",
  642.                                  False
  643.                                  );
  644.  
  645.            Put_Line("TOTO 3" );
  646.  
  647.  
  648.  
  649.  
  650.  
  651.            while not Free loop
  652.               select
  653.                  Network_Manager.Stop;
  654.                  Free := True;
  655.               or
  656.                  delay 0.05;
  657.  
  658.                  Put(Clear_Screen);
  659.                  Text_Io.New_Line(2);
  660.  
  661.                  Fixed.Move(Fixed."*"(80,Character'Val(32)), Date_string, Ada.Strings.Error, Center, space);
  662.                  Fixed.Move(Full_Datify_String(Clock), Date_string, Ada.Strings.Error, Center);
  663.                  Put (Clear_Screen);
  664.                  Fixed.Move("Prophet Server" , Banner, Ada.Strings.Error, Center);
  665.                  Put_line(Normal & Bold_mode & Banner & Normal);
  666.                  Put_Line(Yellow & Date_String  & normal);
  667.                  select
  668.                     Network_Manager.Status(Info, Available, Sentence);
  669.                     Put(To_String(Green & Info & normal));
  670.                  or
  671.                     delay 0.1;
  672.                  end select;
  673.  
  674.  
  675.               end select;
  676.            end loop;
  677.            Free := False;
  678.  
  679.         end if;
  680.      end Start;
  681.  
  682.      Put_Line("TOTO 5" );
  683.      while not End_Of_Task loop
  684.  
  685.         select
  686.  
  687.            accept Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  688.                          Available : out Boolean; Sentence : out T_Lang_array) do
  689.               Info := To_Unbounded_String(" I'm free... Enjoy !" &
  690.                                           " " &
  691.                                           (Character'value
  692.                                            (T_Cross'image
  693.                                             (Cross))) & "    " );
  694.               Available := False;
  695.               Cross  := Wrap_Succ(Cross);
  696.            end Status;
  697.         or
  698.            accept Halt do
  699.               Network_Manager.Halt;
  700.               End_Of_Task := True;
  701.            end Halt;
  702.         or
  703.            accept Read_File(Filename : in String;
  704.                             Reuse_network : in boolean) do
  705.               if Exists("data/sources/" & Filename) then
  706.  
  707.                  Put_Line("Reading source file data/sources/" &
  708.                           Filename);
  709.  
  710.                  Source_Filename :=
  711.                    To_Unbounded_String("data/sources/" &
  712.                                        Filename);
  713.                  Train_Filename :=
  714.                    To_Unbounded_String("data/registers/" &
  715.                                        Base_Name(Filename) & ".bin" );
  716.                  Put_Line("Creating train file..." );
  717.                  Register_Io.Create(Train_File,
  718.                                     Register_Io.Out_File,
  719.                                     To_String(Train_Filename));
  720.                  Put_Line("opening source file..." );
  721.                  Text_Io.Open(Source_File,
  722.                               Text_Io.In_File,
  723.                               To_String(Source_Filename));
  724.                  Text_Io.Put_Line("Reading file for train... Please wait ! " );
  725.                  while not Text_Io.End_Of_File(Source_File) loop
  726.                     begin
  727.                        Text_Io.Get_Immediate(Source_File, Char);
  728.                        case Char is
  729.                           when Character'Val(10) | -- 'Enter' ;
  730.                             Character'Val(33) | -- '!' ;
  731.                             Character'Val(46) |    -- '.' ; Point.
  732.                             Character'Val(59) |   -- ';' ; .
  733.                             Character'Val(63) =>    -- '?' ; .
  734.                              if Word_Last /= 0 then
  735.                              Sentence(Sentence_Index + 1) :=
  736.                                Keyword(To_Lower(Word(1..Word_Last)));
  737.                              Word_Last := 0;
  738.                              Sentence_Index := Sentence_Index + 1;
  739.                              Table2register(Sentence, Register);
  740.                              Register_Io.Write(Train_File,
  741.                                                Register,
  742.                                                Register_Io.Size(Train_File)+1);
  743.                              Register := (others => 0.0);
  744.                              Sentence := (others => 0);
  745.                              Sentence_Index := 0;
  746.                              Put('.');
  747.                              end if;
  748.  
  749.                           when Character'Val(32) |
  750.                             Character'Val(44) =>
  751.                              if Word_Last /= 0 then
  752.                                 Sentence(Sentence_Index + 1) :=
  753.                                   Keyword(To_Lower(Word(1..Word_Last)));
  754.                                 Word_Last := 0;
  755.                                 Sentence_Index := Sentence_Index + 1;
  756.                              end if;
  757.                           when others =>
  758.                              Word(Word_Last + 1) := Char;
  759.                              Word_Last := Word_Last + 1;
  760.                        end case;
  761.                     exception
  762.                        when others =>
  763.                           Text_Io.Put_Line(Word(1..Word_Last));
  764.                           Word_Last := 0;
  765.                     end;
  766.                  end loop;
  767.                  if Word_Last /= 0 then
  768.                     Sentence(Sentence_Index + 1) :=
  769.                       Keyword(To_Lower(Word(1..Word_Last)));
  770.                     Word_Last := 0;
  771.                     Sentence_Index := Sentence_Index + 1;
  772.                     Table2register(Sentence, Register);
  773.                     Register_Io.Write(Train_File,
  774.                                       Register,
  775.                                       Register_Io.Size(Train_File)+1);
  776.                     Register := (others => 0.0);
  777.                     Sentence := (others => 0);
  778.                     Sentence_Index := 0;
  779.                     Put('.');
  780.                  end if;
  781.  
  782.                  New_Line;
  783.  
  784.                  Text_Io.Close(Source_File);
  785.  
  786.  
  787.                  Text_Io.Put_Line("Done." );
  788.                  Train_Length := Natural(Size(Train_File)/2);
  789.                  Register_Io.Close(Train_File);
  790.  
  791.                  Network_Manager.Start(
  792.                                        Train_Length,
  793.                                        To_String(Train_Filename),
  794.                                        "data/networks/network.wgt",
  795.                                        Reuse_network);
  796.  
  797.                  Put_Line("Initialize network..." );
  798.  
  799.  
  800.  
  801.  
  802.                  while not Free loop
  803.                     select
  804.                        Network_Manager.Stop;
  805.                        Free := True;
  806.                     or
  807.                        delay 0.05;
  808.                        Put(Clear_Screen);
  809.                        Text_Io.New_Line(2);
  810.  
  811.                        Fixed.Move(Fixed."*"(80,Character'Val(32)), Date_string, Ada.Strings.Error, Center, space);
  812.                        Fixed.Move(Full_Datify_String(Clock), Date_string, Ada.Strings.Error, Center);
  813.                        Put (Clear_Screen);
  814.                        Fixed.Move("Prophet Server" , Banner, Ada.Strings.Error, Center);
  815.                        Put_line(Normal & Bold_mode & Banner & Normal);
  816.                        Put_Line(Yellow & Date_String  & normal);
  817.                        select
  818.                           Network_Manager.Status(Info, Available, Sentence);
  819.                           Put(To_String(Green & Info & normal));
  820.                        or
  821.                           delay 0.1;
  822.                        end select;
  823.  
  824.                     end select;
  825.                  end loop;
  826.                  Free := False;
  827.               end if;
  828.            end Read_File;
  829.         or
  830.            delay 1.0;
  831.  
  832.            Message_IO.Look(Program_Logname, Available);
  833.  
  834.            if Available then
  835.               Message_Io.Send(Program_Logname, Input);
  836.               Table2register(Input.Message, Register);
  837.               Feed_Back := Register;
  838.  
  839.               Network_Manager.Respond("network.wgt", Register);
  840.  
  841.  
  842.               for I in Register'Range loop
  843.                  if Register(I) > 0.5 then
  844.                     Register(I) := 1.0;
  845.                  else
  846.                     Register(I) := 0.0;
  847.                  end if;
  848.               end loop;
  849.  
  850.  
  851.  
  852.               Register_Io.Open(Expe_File,
  853.                                Register_Io.Out_File,
  854.                                Expe_filename);
  855.  
  856.               Register_Io.Write(Expe_File,
  857.                                 Feed_Back,
  858.                                 Register_Io.Size(Expe_File)+1);
  859.               Register_Io.Write(Expe_File,
  860.                                 register,
  861.                                 Register_Io.Size(Expe_File)+1);
  862.  
  863.               Register_Io.Close(Expe_File);
  864.  
  865.  
  866.  
  867.  
  868.  
  869.               Network_Manager.respond("Expe.wgt", Feed_back);
  870.  
  871.  
  872.               for I in Register'Range loop
  873.                  if Register(I) > 0.5 then
  874.                     Register(I) := 1.0;
  875.                  else
  876.                     Register(I) := 0.0;
  877.                  end if;
  878.               end loop;
  879.  
  880.               Feed_Back := Register;
  881.  
  882.               Register2table(Register, Output.Message);
  883.  
  884.               Output.Logname := new String ' (Program_Logname);
  885.               Message_IO.Receive(Input.Logname.all, Output);
  886.  
  887.  
  888.               Register_Io.Open(Expe_File,
  889.                                Register_Io.In_File,
  890.                                Expe_Filename);
  891.  
  892.  
  893.  
  894.               Expe_Length := Natural(Size(Expe_File)/2);
  895.  
  896.               Register_Io.Close(Expe_File);
  897.  
  898.  
  899.               Network_Manager.Start(
  900.                                     Expe_Length,
  901.                                     Expe_Filename,
  902.                                     "data/networks/Expe.wgt",
  903.                                     true);
  904.  
  905.               while not Free loop
  906.                  select
  907.                     Network_Manager.Stop;
  908.                     Free := True;
  909.                  or
  910.                     delay 0.05;
  911.  
  912.  
  913.                     select
  914.                        Network_Manager.Status(Info, Available, Sentence);
  915.  
  916.                        accept Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  917.                                      Available : out Boolean; Sentence : out T_Lang_array) do
  918.  
  919.                           Info := Life_Cycle.Info;
  920.                           Available := False;
  921.  
  922.  
  923.                        end Status;
  924.  
  925.                     or
  926.                        delay 0.1;
  927.                     end select;
  928.                  end select;
  929.               end loop;
  930.               Free := False;
  931.               Network_Manager.Stop;
  932.            end if;
  933.         end select;
  934.      end loop;
  935.   end Life_Cycle;

mood
Publicité
Posté le 17-03-2010 à 22:54:53  profilanswer
 

n°1974766
breizhbugs
Posté le 17-03-2010 à 23:57:56  profilanswer
 

Bonsoir,
Description du problème?  commentaires dans le code?

n°1974768
Profil sup​primé
Posté le 18-03-2010 à 00:25:17  answer
 

breizhbugs a écrit :

Bonsoir,
Description du problème?  commentaires dans le code?


 
 
Problème, c'est plantage non identifié.
Description du code, déjà que le code est une description, je vais pas faire une description de description.. ou alors, c'est une description d'un bout d'agent de dialogue.
 
 
Quoi qu'il en soit, voici la correction :
 
Attention pavé :
 

Code :
  1. with PragmARC.REM_NN_Wrapper;
  2. use PragmARC.REM_NN_Wrapper;
  3.  
  4. with PragmARC.Math.Functions;
  5.  
  6. with Generic_Extended_Binary_Code;
  7.  
  8. with Direct_Io;
  9.  
  10. with Time_To_Date, Ada.Strings.Fixed, Split_Heure, Text_Io;
  11. use Time_To_Date, Ada.Strings, Split_Heure, Text_Io;
  12.  
  13. with Ada.Characters.Handling;
  14. use Ada.Characters.Handling;
  15.  
  16. with Ada.Strings.Unbounded;
  17. use Ada.Strings.Unbounded;
  18.  
  19. with Ada.Directories;
  20. use Ada.Directories;
  21.  
  22. with PragmARC.Wrapping;
  23.  
  24. package body Ai is
  25.  
  26.   task body T_Console is
  27.  
  28.  
  29.  
  30.  
  31.      Status : Unbounded_String;
  32.      Date   : String(1..80) := (others => Character'Val(32));
  33.      Title  : String(1..80) := (others => Character'Val(32));
  34.      End_Of_Task : Boolean := False;
  35.      Word        : String(1..64) := (others => Character'Val(32));
  36.      Word_Last   : Natural := 0;
  37.      Response,
  38.      Line        : T_Lang_Array(1..Sentence_lenght) := (others => 0);
  39.      Line_Last   : Natural := 0;
  40.      Length      : Natural := 0;
  41.      Count_Line  : Integer := 0;
  42.      Available   : Boolean := False;
  43.      Input_Message  : T_Message_Box := (new String ' (Logname.all),
  44.                                         (others => 0));
  45.      Output_Message : T_Message_Box := (null,
  46.                                         (others => 0));
  47.      Data_Entry : Boolean := False;
  48.      Data : T_Lang_Array(1..Sentence_Lenght) := (others => Keyword("" ));
  49.   begin
  50.  
  51.      Fixed.Move("Prophet Server",
  52.                 Title, Error, Center, Space);
  53.  
  54.      while not End_Of_Task loop
  55.         select
  56.            Message_Io.Look(Logname.all, available);
  57.            if Available then
  58.               Message_Io.Send(Logname.all, Output_message);
  59.               Response := Output_Message.Message;
  60.            end if;
  61.         or
  62.            delay 0.05;
  63.         end select;
  64.  
  65.         select
  66.            accept Receive(Char : in Character) do
  67.               begin
  68.                  if Is_Special(Char) then
  69.                     case Char is
  70.                        when Character'Val(32) =>
  71.                           if Line_Last < Line'Length and
  72.                             Word_Last /= 0 then
  73.                              begin
  74.                                 Line(Line_Last + 1) :=
  75.                                   Keyword(Word(1..Word_Last));
  76.                                 Line_Last := Line_Last + 1;
  77.                                 Word := (others => Character'Val(32));
  78.                                 Word_Last := 0;
  79.                              exception
  80.                                 when others => -- Specification_Error =>
  81.                                    null;
  82.                              end;
  83.                           end if;
  84.                        when others =>
  85.                           if Word_Last < Word'Length then
  86.                              Word(Word_Last + 1) := Char;
  87.                              Word_Last := Word_Last + 1;
  88.                           end if;
  89.                     end case;
  90.                  else
  91.                     case Char is
  92.                        when Character'Val(10) =>
  93.                           if Line_Last < Line'Length and
  94.                             Word_Last /= 0 then
  95.                              begin
  96.                                 Line(Line_Last + 1) :=
  97.                                   Keyword(Word(1..Word_Last));
  98.                                 Line_Last := Line_Last + 1;
  99.                                 Input_Message.Message := Line;
  100.                                 Message_Io.Receive(Program_Logname, Input_Message);
  101.                                 Line := (others => 0);
  102.                                 Line_Last := 0;
  103.                                 Word := (others => Character'Val(32));
  104.                                 Word_Last := 0;
  105.                              exception
  106.                                 when others => -- Specification_Error =>
  107.                                    null;
  108.                              end;
  109.                           end if;
  110.  
  111.                        when Character'Val(127) =>
  112.                           if Word_Last > 0 then
  113.                              Word(Word_Last) := Character'Val(32);
  114.                              Word_Last := Word_Last - 1;
  115.                           elsif Line_Last /= 0 then
  116.                              Line(Line_Last) := 0;
  117.                              Line_Last := Line_Last - 1;
  118.                           end if;
  119.                        when others =>
  120.                           if Word_Last < Word'Length then
  121.                              Word(Word_Last + 1) := Char;
  122.                              Word_Last := Word_Last + 1;
  123.                           end if;
  124.                     end case;
  125.                  end if;
  126.               exception
  127.                  when others =>
  128.                     null;
  129.               end;
  130.               Put(Clear_Screen);
  131.  
  132.               Fixed.Move(Full_Datify_String(Clock),
  133.                          Date, Error, center, Space);
  134.  
  135.               Put_Line(Bold_Mode & Title & Normal);
  136.               Put_Line(Yellow & Date & Normal);
  137.               New_Line;
  138.               Put_Line(Green & To_String(Status) & Normal);
  139.               New_Line;
  140.               Put('#' & Blue);
  141.               Length := 0;
  142.               for Key in 1..Response'length loop
  143.                  begin
  144.                     Put(Image(Response(Key)) & ' ');
  145.                     Length := Length + Image(Response(Key))'Length + 1;
  146.                  exception
  147.                     when others => -- Specification_Error =>
  148.                        null;
  149.                  end;
  150.               end loop;
  151.               Count_Line := 10;
  152.               Count_Line := Count_line - (Length/80+1);
  153.               if Count_Line > 0 then
  154.                  New_Line(Text_Io.Count(Count_Line));
  155.               else
  156.                  New_Line;
  157.               end if;
  158.               Length := 0;
  159.               Put(normal & '#' & Blue);
  160.               for Key in 1..Line_Last loop
  161.                  Put(Image(Line(Key)) & ' ');
  162.                  Length := Length + Image(Line(Key))'Length+1;
  163.               end loop;
  164.               Put(Red & Word(1..Word_Last) & Normal);
  165.            end Receive;
  166.         or
  167.            accept Halt do
  168.               End_Of_Task := True;
  169.            end Halt;
  170.         or
  171.            delay 0.25;
  172.  
  173.            select
  174.               Life_Cycle.Status(Status, Data_Entry, data);
  175.  
  176.            or
  177.               delay 0.1;
  178.            end select;
  179.            Put(Clear_Screen);
  180.  
  181.            Put_Line(Bold_mode & Title & normal);
  182.            Fixed.Move(Full_Datify_String(Clock),
  183.                       Date, Error, Center, Space);
  184.  
  185.            Put_Line(Yellow & Date & Normal);
  186.            New_Line;
  187.            Put_line(Green & To_String(Status) & Normal);
  188.            New_Line;
  189.            if Data_Entry then
  190.               for Key in 1..data'length loop
  191.                  begin
  192.                     Put(Image(data(Key)) & ' ');
  193.                     Length := Length + Image(data(Key))'Length + 1;
  194.                  exception
  195.                     when others => -- Specification_Error =>
  196.                        null;
  197.                  end;
  198.               end loop;
  199.            end if;
  200.            New_Line;
  201.            Put('#' & blue);
  202.            Length := 0;
  203.            Count_Line := 10;
  204.            for Key in 1..Response'length loop
  205.               begin
  206.                  Put(Image(Response(Key)) & ' ');
  207.                  Length := Length + Image(Response(Key))'Length + 1;
  208.               exception
  209.                  when others => -- Specification_Error =>
  210.                     null;
  211.               end;
  212.            end loop;
  213.            Count_Line := Count_line - (Length/80+1);
  214.                if Count_Line > 0 then
  215.                   New_Line(Text_Io.Count(Count_Line));
  216.                else
  217.                   New_Line;
  218.                end if;
  219.                Length := 0;
  220.                Put(Normal & '#' & Blue);
  221.                for Key in 1..Line_Last loop
  222.                   Put(Image(Line(Key)) & ' ');
  223.                   Length := Length + Image(Line(Key))'Length + 1;
  224.                end loop;
  225.                Put(Red & Word(1..Word_Last) & Normal);
  226.         end select;
  227.      end loop;
  228.   end T_Console;
  229.  
  230.   --package Real_Io is new Text_Io.Float_Io(Real);
  231.   package Real_Math is new PragmARC.Math.Functions (Supplied_Real => Real);
  232.   package Coded_Word is new Generic_Extended_Binary_Code(T_Language);
  233.   use Coded_Word;
  234.   subtype T_Register is Node_Set(1..Sentence_Lenght*T_Code'length);
  235.   package Register_Io is new Direct_Io(T_Register);
  236.   use Register_Io;
  237.  
  238.  
  239.   procedure Table2register(Table : in T_Lang_Array;
  240.                            Register : out T_Register) is
  241.      Code : T_Code;
  242.   begin
  243.      for I in 0..Table'Length-1 loop
  244.         Code := Code_Of(Table(I+1));
  245.         for J in T_Code'Range loop
  246.            Register(I*T_Code'Length+J) := Code(J);
  247.         end loop;
  248.      end loop;
  249.   end Table2register;
  250.  
  251.   procedure Register2table(Register : in T_Register;
  252.                            Table    : out  T_Lang_Array) is
  253.      Code : T_Code;
  254.   begin
  255.      for I in 0..Table'Length-1 loop
  256.         begin
  257.            Code := Register(I*T_Code'Length+1..I*T_Code'Length+T_Code'Length);
  258.            Table(I+1) := Item_Of(Code);
  259.         exception
  260.            when others =>
  261.               null;
  262.         end;
  263.      end loop;
  264.   end Register2table;
  265.  
  266.  
  267.  
  268.  
  269.  
  270.   -- Gadget --
  271.   type T_Cross is ('-', '\', '|', '/');
  272.   package Cross_Wrapping is new PragmARC.Wrapping(T_Cross);
  273.   use Cross_Wrapping;
  274.  
  275.  
  276.  
  277.  
  278.  
  279.   task Network_Manager is
  280.      entry Start(Train_Length : in Positive;
  281.                  Train_Filename : in String;
  282.                  Network_Filename : in String;
  283.                  Reuse_Network : in boolean);
  284.      entry Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  285.                   Available : out Boolean; Sentence : out T_Lang_array);
  286.      entry Respond(Network : in String;
  287.                    Register : in out T_Register);
  288.      entry Stop;
  289.      entry Halt;
  290.   end Network_Manager;
  291.  
  292.  
  293.  
  294.   task body Network_Manager is
  295.  
  296.  
  297.      Train_File,
  298.      Prob_File : Register_Io.File_Type;
  299.      Prob_Filename   : constant String := "data/registers/prob.bin";
  300.      Filename, Network : Unbounded_String;
  301.      Length : Positive;
  302.      Reuse : Boolean;
  303.      End_Of_Task, Suspended : Boolean := False;
  304.      Opened : Boolean := False;
  305.   begin
  306.  
  307.  
  308.      while not End_Of_Task loop
  309.  
  310.         Suspended := false;
  311.         select
  312.  
  313.  
  314.            accept Start(Train_Length : in Positive;
  315.                         Train_Filename : in String;
  316.                         Network_Filename : in String;
  317.                         Reuse_Network : in boolean) do
  318.               Length := Train_Length;
  319.               Network := To_Unbounded_String(Network_Filename);
  320.               Reuse := Reuse_Network;
  321.               Filename := To_Unbounded_String(Train_Filename);
  322.               Text_Io.Put_Line("TOTO 6" );
  323.            end Start;
  324.  
  325.         or
  326.  
  327.  
  328.            accept Respond(Network : in String;
  329.                           Register : in out T_Register) do
  330.               Register_Io.create(Prob_File,
  331.                                  Register_Io.Out_File,
  332.                                  Prob_Filename);
  333.               Register_Io.Write(Prob_File, Register);
  334.               Register_Io.Close(Prob_File);
  335.  
  336.               declare
  337.  
  338.                  procedure Get_Expl(Pattern : in Positive;
  339.                                     Input : out Node_Set;
  340.                                          Desired : out Node_Set) is
  341.                  Register : T_Register := (others => 0.0);
  342.               begin
  343.                  Register_Io.Open(Prob_File,
  344.                                   Register_Io.In_File,
  345.                                   Prob_Filename);
  346.                  Read(Prob_File,
  347.                       Register,
  348.                       1);
  349.                  Input := Node_Set(Register);
  350.  
  351.                  Desired := (others => 0.0);
  352.                  Register_Io.Close(Prob_File);
  353.               end Get_Expl;
  354.  
  355.               package REM_NN_Expl is new REM_NN
  356.                         (
  357.                          Num_Input_Nodes => T_Register'length,
  358.                          Num_Hidden_Nodes => T_Register'Length/T_Code'Length,
  359.                          Num_Output_Nodes => T_Register'length,
  360.                          Num_Patterns => 1,
  361.                          New_Random_Weights => False,
  362.                          Input_To_Output_Connections => False,
  363.                          Weight_File_Name => Network,
  364.                          Get_Input => Get_Expl
  365.                          );
  366.  
  367.               use REM_NN_Expl;
  368.  
  369.  
  370.               begin
  371.  
  372.                  Respond(1, Register);
  373.  
  374.               end;
  375.  
  376.  
  377.  
  378.  
  379.               Register_Io.open(Prob_File,
  380.                                Register_Io.Out_File,
  381.                                Prob_Filename);
  382.               Register_Io.Delete(Prob_File);
  383.  
  384.  
  385.               Suspended := True;
  386.  
  387.            end Respond;
  388.  
  389.         or
  390.  
  391.            accept Halt do
  392.               Suspended := True;
  393.               End_Of_Task := True;
  394.            end Halt;
  395.  
  396.  
  397.         end select;
  398.  
  399.         if not Suspended then
  400.  
  401.            Text_Io.Put_Line("TOTO 7" );
  402.  
  403.            Register_Io.Open(Train_File,
  404.                             Register_Io.In_File,
  405.                             To_String(Filename));
  406.  
  407.  
  408.            declare
  409.  
  410.               procedure Get_Train(Pattern : in Positive;
  411.                                   Input : out Node_Set;
  412.                                   Desired : out Node_Set) is
  413.                  Register : T_Register := (others => 0.0);
  414.               begin
  415.  
  416.                  Read(Train_File,
  417.                       Register,
  418.                       Register_Io.Count(Pattern*2-1));
  419.                  Input := Node_Set(Register);
  420.  
  421.                  Read(Train_File,
  422.                       Register,
  423.                       Register_Io.Count(Pattern*2));
  424.                  Desired := Node_Set(Register);
  425.               end Get_Train;
  426.  
  427.               package REM_NN_Train is new REM_NN
  428.                 (
  429.                  Num_Input_Nodes => T_Register'length,
  430.                  Num_Hidden_Nodes => T_Register'Length/T_Code'Length,
  431.                  Num_Output_Nodes => T_Register'length,
  432.                  Num_Patterns => Length,
  433.                  New_Random_Weights => not Reuse,
  434.                  Input_To_Output_Connections => False,
  435.                  Weight_File_Name => To_String(Network),
  436.                  Get_Input => Get_Train
  437.                  );
  438.  
  439.               use REM_NN_Train;
  440.               Register : T_Register := (others => 0.0);
  441.               Response : REM_NN_Train.Output_Set := (others => 0.0);
  442.               Desired_Output : array (1..Length) of
  443.                 REM_NN_Train.Output_Set;
  444.               RMS_Error : Real := 0.5;
  445.               Error     : Real := 0.0;
  446.               Converged  : constant real := 0.05;
  447.               Max_Epochs : constant Positive := Length*500;
  448.               Epoch : Natural := 0;
  449.  
  450.               Cross : T_Cross := T_Cross'Val(0);
  451.  
  452.               -- Time indication
  453.  
  454.               Date : Time := Clock;
  455.               Heure, Minute, Seconde, Reste : Natural := 0;
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.            begin
  463.               Text_Io.Put_Line("TOTO 8" );
  464.  
  465.               for I in 1..Desired_Output'Length loop
  466.                  Register_Io.Read(train_File,
  467.                                   Register,
  468.                                   Register_Io.Count(i*2));
  469.  
  470.                  Desired_Output(I) := REM_NN_Train.Output_Set(Register);
  471.               end loop;
  472.               Date := Clock;
  473.  
  474.               while not Suspended loop
  475.  
  476.  
  477.                  select
  478.  
  479.  
  480.                     accept Respond(Network : in String;
  481.                                    Register : in out T_Register) do
  482.                        Register_Io.create(Prob_File,
  483.                                           Register_Io.Out_File,
  484.                                           Prob_Filename);
  485.                        Register_Io.Write(Prob_File, Register);
  486.                        Register_Io.Close(Prob_File);
  487.  
  488.  
  489.                        if Register_Io.Is_Open(Train_File) then
  490.                           Opened := True;
  491.                           Register_Io.Close(Train_File);
  492.                        end if;
  493.  
  494.  
  495.                        declare
  496.  
  497.                           procedure Get_Expl(Pattern : in Positive;
  498.                                              Input : out Node_Set;
  499.                                              Desired : out Node_Set) is
  500.                              Register : T_Register := (others => 0.0);
  501.                           begin
  502.                              Register_Io.Open(Prob_File,
  503.                                               Register_Io.In_File,
  504.                                               Prob_Filename);
  505.                              Read(Prob_File,
  506.                                   Register,
  507.                                   1);
  508.                              Input := Node_Set(Register);
  509.  
  510.                              Desired := (others => 0.0);
  511.                              Register_Io.Close(Prob_File);
  512.                           end Get_Expl;
  513.  
  514.                           package REM_NN_Expl is new REM_NN
  515.                             (
  516.                              Num_Input_Nodes => T_Register'length,
  517.                              Num_Hidden_Nodes => T_Register'Length/T_Code'Length,
  518.                              Num_Output_Nodes => T_Register'length,
  519.                              Num_Patterns => 1,
  520.                              New_Random_Weights => False,
  521.                              Input_To_Output_Connections => False,
  522.                              Weight_File_Name => Network,
  523.                              Get_Input => Get_Expl
  524.                              );
  525.  
  526.                           use REM_NN_Expl;
  527.  
  528.  
  529.                        begin
  530.  
  531.                           REM_NN_Expl.Respond(1, Register);
  532.  
  533.                        end;
  534.  
  535.  
  536.                        if Opened then
  537.  
  538.                           Register_Io.Open(Train_File,
  539.                                            Register_Io.In_File,
  540.                                            To_String(Filename));
  541.                           Opened := False;
  542.                        end if;
  543.  
  544.  
  545.  
  546.  
  547.                     end Respond;
  548.  
  549.  
  550.  
  551.                  or
  552.  
  553.  
  554.  
  555.  
  556.  
  557.                     accept Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  558.                                   Available : out Boolean; Sentence : out T_Lang_array) do
  559.                        Split(Clock - Date, Heure, Minute, Seconde, reste);
  560.  
  561.                        Info :=
  562.                          To_Unbounded_String
  563.                          (" Trainning Expe file of length :" &
  564.                           Integer'Image(Length) &
  565.                           Character'Val(10) &
  566.                           " Epoch : " &
  567.                           Integer'Image(Epoch) &
  568.                           " ; " &
  569.                           "RMS_Error : " &
  570.                           Real'Image(RMS_Error) &
  571.                           " " &
  572.                           (Character'value
  573.                            (T_Cross'image(Cross)))
  574.                           & "    " &
  575.                           Integer'Image(Integer((Converged/RMS_error)*100.0)) &
  576.                           '%' &
  577.                           Integer'Image(Heure) &
  578.                           ':' &
  579.                           Integer'Image(Minute) &
  580.                           ':' &
  581.                           Integer'Image(Seconde) &
  582.                           ':' &
  583.                           Integer'Image(Reste) & Latin_1.Lf &
  584.                           Reverse_Video &
  585.                           Fixed."*"(Integer((((80.0/RMS_Error)/(20.0))))+1,' ') & Normal);
  586.  
  587.                        Available := True;
  588.  
  589.  
  590.                        for I in Register'Range loop
  591.                           if Register(I) > 0.5 then
  592.                              Register(I) := 1.0;
  593.                           else
  594.                              Register(I) := 0.0;
  595.                           end if;
  596.                        end loop;
  597.  
  598.                        Register2Table(Response, Sentence);
  599.  
  600.  
  601.                        Cross  := Wrap_Succ(Cross);
  602.                     end Status;
  603.                  or
  604.  
  605.                     when RMS_Error < Converged or Epoch > Max_Epochs =>
  606.                        accept Stop do
  607.                           Suspended := True;
  608.                        end Stop;
  609.  
  610.                  or
  611.  
  612.                     delay 0.01;
  613.  
  614.                     if ((Epoch <= Max_Epochs ) and
  615.                         (RMS_Error > Converged)) or
  616.                       Epoch < 50 then
  617.                        for Pattern in 1..Length loop
  618.                           REM_NN_Train.Train;
  619.                           REM_NN_Train.Respond (Pattern, Response);
  620.                           for I in Response'Range loop
  621.                              Error := Error + (Desired_Output(Pattern)(i) -   Response(i) );
  622.                           end loop;
  623.                           RMS_Error := RMS_Error + ((Error/Real(Response'Length)) ** 2);
  624.                           Error := 0.0;
  625.                           Response := (others => 0.0);
  626.                        end loop;
  627.                        RMS_Error := Real_Math.Sqrt(RMS_Error/Real(Length));
  628.                        Epoch := Epoch + 1;
  629.                     end if;
  630.  
  631.  
  632.                  end select;
  633.               end loop;
  634.               REM_NN_Train.Save_Weights;
  635.            end;
  636.            Register_Io.Close(Train_File);
  637.         end if;
  638.      end loop;
  639.   end Network_Manager;
  640.  
  641.  
  642.   task body Life_Cycle is
  643.      Source_File     : Text_Io.File_Type;
  644.      Source_Filename : Unbounded_String;
  645.      Word            : String(1..64) := (others => Character'Val(32));
  646.      Word_Last       : Natural := 0;
  647.      Char            : Character;
  648.      Sentence        : T_Lang_Array(1..Sentence_Lenght) := (others => 0);
  649.      Sentence_Index  : Natural := 0;
  650.      Train_File,
  651.      Prob_File       : Register_Io.File_Type;
  652.      Train_Filename  : Unbounded_String;
  653.  
  654.      Register, Feed_back : T_Register := (others => 0.0);
  655.      Train_Length : Natural := 0;
  656.  
  657.      End_Of_Task : Boolean := False;
  658.  
  659.      Input  : T_Message_Box := (null, (others => 0));
  660.      Output : T_Message_Box := (new String ' (Program_Logname), (others => 0));
  661.      Available : Boolean := False;
  662.  
  663.  
  664.      Cross : T_Cross := T_Cross'Val(0);
  665.  
  666.      -- Time indication
  667.      Date_string   : String(1..80) := (others => Character'Val(32));
  668.      Banner : String(1..80) := (others => Character'Val(32));
  669.  
  670.  
  671.      -- Experience set
  672.      Expe_Filename : constant String := "data/registers/expe.bin";
  673.      Expe_File     : Register_Io.File_Type;
  674.      Expe_Length   : Natural := 0;
  675.      Free : Boolean := True;
  676.      Info : Unbounded_String;
  677.   begin
  678.  
  679.  
  680.      accept Start(Date : out Time) do
  681.         Date := Clock;
  682.  
  683.  
  684.  
  685.         Put_Line("TOTO -1" );
  686.  
  687.  
  688.  
  689.  
  690.         Register_Io.Create(Prob_File,
  691.                            Register_Io.Out_File,
  692.                            Expe_filename);
  693.         Register_Io.Write(Prob_File, Register);
  694.         Register_Io.Close(Prob_File);
  695.  
  696.         if not Exists("data/networks/Expe.wgt" ) then
  697.  
  698.  
  699.  
  700.            Put_Line("TOTO 0" );
  701.            Register_Io.Create(Expe_File,
  702.                               Register_Io.Out_File,
  703.                               Expe_filename);
  704.            Register_Io.Write(Expe_File,
  705.                              Feed_Back,
  706.                              Register_Io.Size(Expe_File)+1);
  707.            Register_Io.Write(Expe_File,
  708.                              register,
  709.                              Register_Io.Size(Expe_File)+1);
  710.  
  711.            Register_Io.Close(Expe_File);
  712.            Put_Line("TOTO 1" );
  713.  
  714.  
  715.            Expe_Length := 1;
  716.  
  717.  
  718.  
  719.  
  720.  
  721.            Put_Line("TOTO 2" );
  722.            Network_Manager.Start(
  723.                                  Expe_Length,
  724.                                  Expe_Filename,
  725.                                  "data/networks/Expe.wgt",
  726.                                  False
  727.                                  );
  728.  
  729.            Put_Line("TOTO 3" );
  730.  
  731.  
  732.  
  733.  
  734.  
  735.            while not Free loop
  736.               select
  737.                  Network_Manager.Stop;
  738.                  Free := True;
  739.               or
  740.                  delay 0.05;
  741.  
  742.                  Put(Clear_Screen);
  743.                  Text_Io.New_Line(2);
  744.  
  745.                  Fixed.Move(Fixed."*"(80,Character'Val(32)), Date_string, Ada.Strings.Error, Center, space);
  746.                  Fixed.Move(Full_Datify_String(Clock), Date_string, Ada.Strings.Error, Center);
  747.                  Put (Clear_Screen);
  748.                  Fixed.Move("Prophet Server" , Banner, Ada.Strings.Error, Center);
  749.                  Put_line(Normal & Bold_mode & Banner & Normal);
  750.                  Put_Line(Yellow & Date_String  & normal);
  751.                  select
  752.                     Network_Manager.Status(Info, Available, Sentence);
  753.                     Put(To_String(Green & Info & normal));
  754.                  or
  755.                     delay 0.1;
  756.                  end select;
  757.  
  758.  
  759.               end select;
  760.            end loop;
  761.            Free := False;
  762.  
  763.         end if;
  764.      end Start;
  765.  
  766.      Put_Line("TOTO 5" );
  767.      while not End_Of_Task loop
  768.  
  769.         select
  770.  
  771.  
  772.  
  773.            accept Halt do
  774.               Network_Manager.Halt;
  775.               End_Of_Task := True;
  776.            end Halt;
  777.         or
  778.            accept Read_File(Filename : in String;
  779.                             Reuse_network : in boolean) do
  780.               if Exists("data/sources/" & Filename) then
  781.  
  782.                  Put_Line("Reading source file data/sources/" &
  783.                           Filename);
  784.  
  785.                  Source_Filename :=
  786.                    To_Unbounded_String("data/sources/" &
  787.                                        Filename);
  788.                  Train_Filename :=
  789.                    To_Unbounded_String("data/registers/" &
  790.                                        Base_Name(Filename) & ".bin" );
  791.                  Put_Line("Creating train file..." );
  792.                  Register_Io.Create(Train_File,
  793.                                     Register_Io.Out_File,
  794.                                     To_String(Train_Filename));
  795.                  Put_Line("opening source file..." );
  796.                  Text_Io.Open(Source_File,
  797.                               Text_Io.In_File,
  798.                               To_String(Source_Filename));
  799.                  Text_Io.Put_Line("Reading file for train... Please wait ! " );
  800.                  while not Text_Io.End_Of_File(Source_File) loop
  801.                     begin
  802.                        Text_Io.Get_Immediate(Source_File, Char);
  803.                        case Char is
  804.                           when Character'Val(10) | -- 'Enter' ;
  805.                             Character'Val(33) | -- '!' ;
  806.                             Character'Val(46) |    -- '.' ; Point.
  807.                             Character'Val(59) |   -- ';' ; .
  808.                             Character'Val(63) =>    -- '?' ; .
  809.                              if Word_Last /= 0 then
  810.                              Sentence(Sentence_Index + 1) :=
  811.                                Keyword(To_Lower(Word(1..Word_Last)));
  812.                              Word_Last := 0;
  813.                              Sentence_Index := Sentence_Index + 1;
  814.                              Table2register(Sentence, Register);
  815.                              Register_Io.Write(Train_File,
  816.                                                Register,
  817.                                                Register_Io.Size(Train_File)+1);
  818.                              Register := (others => 0.0);
  819.                              Sentence := (others => 0);
  820.                              Sentence_Index := 0;
  821.                              Put('.');
  822.                              end if;
  823.  
  824.                           when Character'Val(32) |
  825.                             Character'Val(44) =>
  826.                              if Word_Last /= 0 then
  827.                                 Sentence(Sentence_Index + 1) :=
  828.                                   Keyword(To_Lower(Word(1..Word_Last)));
  829.                                 Word_Last := 0;
  830.                                 Sentence_Index := Sentence_Index + 1;
  831.                              end if;
  832.                           when others =>
  833.                              Word(Word_Last + 1) := Char;
  834.                              Word_Last := Word_Last + 1;
  835.                        end case;
  836.                     exception
  837.                        when others =>
  838.                           Text_Io.Put_Line(Word(1..Word_Last));
  839.                           Word_Last := 0;
  840.                     end;
  841.                  end loop;
  842.                  if Word_Last /= 0 then
  843.                     Sentence(Sentence_Index + 1) :=
  844.                       Keyword(To_Lower(Word(1..Word_Last)));
  845.                     Word_Last := 0;
  846.                     Sentence_Index := Sentence_Index + 1;
  847.                     Table2register(Sentence, Register);
  848.                     Register_Io.Write(Train_File,
  849.                                       Register,
  850.                                       Register_Io.Size(Train_File)+1);
  851.                     Register := (others => 0.0);
  852.                     Sentence := (others => 0);
  853.                     Sentence_Index := 0;
  854.                     Put('.');
  855.                  end if;
  856.  
  857.                  New_Line;
  858.  
  859.                  Text_Io.Close(Source_File);
  860.  
  861.  
  862.                  Text_Io.Put_Line("Done." );
  863.                  Train_Length := Natural(Size(Train_File)/2);
  864.                  Register_Io.Close(Train_File);
  865.  
  866.                  Network_Manager.Start(
  867.                                        Train_Length,
  868.                                        To_String(Train_Filename),
  869.                                        "data/networks/network.wgt",
  870.                                        Reuse_network);
  871.  
  872.                  Put_Line("Initialize network..." );
  873.  
  874.  
  875.  
  876.  
  877.                  while not Free loop
  878.                     select
  879.                        Network_Manager.Stop;
  880.                        Free := True;
  881.                     or
  882.                        delay 0.05;
  883.                        Put(Clear_Screen);
  884.                        Text_Io.New_Line(2);
  885.  
  886.                        Fixed.Move(Fixed."*"(80,Character'Val(32)), Date_string, Ada.Strings.Error, Center, space);
  887.                        Fixed.Move(Full_Datify_String(Clock), Date_string, Ada.Strings.Error, Center);
  888.                        Put (Clear_Screen);
  889.                        Fixed.Move("Prophet Server" , Banner, Ada.Strings.Error, Center);
  890.                        Put_line(Normal & Bold_mode & Banner & Normal);
  891.                        Put_Line(Yellow & Date_String  & normal);
  892.                        select
  893.                           Network_Manager.Status(Info, Available, Sentence);
  894.                           Put(To_String(Green & Info & normal));
  895.                        or
  896.                           delay 0.1;
  897.                        end select;
  898.  
  899.                     end select;
  900.                  end loop;
  901.                  Free := False;
  902.               end if;
  903.            end Read_File;
  904.         or
  905.            delay 1.0;
  906.  
  907.            Message_IO.Look(Program_Logname, Available);
  908.  
  909.            if Available then
  910.               Text_Io.Put("Message available" );
  911.               Message_Io.Send(Program_Logname, Input);
  912.               Table2register(Input.Message, Register);
  913.               Feed_Back := Register;
  914.               Text_Io.Put("respond train" );
  915.               Network_Manager.Respond("data/networks/network.wgt", Register);
  916.  
  917.  
  918.               for I in Register'Range loop
  919.                  if Register(I) > 0.5 then
  920.                     Register(I) := 1.0;
  921.                  else
  922.                     Register(I) := 0.0;
  923.                  end if;
  924.               end loop;
  925.  
  926.  
  927.  
  928.               Register_Io.Open(Expe_File,
  929.                                Register_Io.Out_File,
  930.                                Expe_filename);
  931.  
  932.               Register_Io.Write(Expe_File,
  933.                                 register,
  934.                                 Register_Io.Size(Expe_File)+1);
  935.               Register_Io.Write(Expe_File,
  936.                                 Feed_back,
  937.                                 Register_Io.Size(Expe_File)+1);
  938.  
  939.               Expe_Length := Natural(Size(Expe_File)/2);
  940.               Register_Io.Close(Expe_File);
  941.  
  942.  
  943.  
  944.  
  945.               Text_Io.Put("respond expe" );
  946.               Network_Manager.respond("data/networks/Expe.wgt", Feed_back);
  947.  
  948.  
  949.               for I in Feed_Back'Range loop
  950.                  if Feed_Back(I) > 0.5 then
  951.                     Feed_Back(I) := 1.0;
  952.                  else
  953.                     Feed_Back(I) := 0.0;
  954.                  end if;
  955.               end loop;
  956.  
  957.  
  958.  
  959.               Register2table(Feed_Back, Output.Message);
  960.  
  961.               Output.Logname := new String ' (Program_Logname);
  962.               Message_IO.Receive(Input.Logname.all, Output);
  963.  
  964.  
  965.               Text_Io.Put("train expe" );
  966.               Network_Manager.Start(
  967.                                     Expe_Length,
  968.                                     Expe_Filename,
  969.                                     "data/networks/Expe.wgt",
  970.                                     false);
  971.               Text_Io.Put("plantage 0" );
  972.  
  973.               Free := false;
  974.            else
  975.               select
  976.                  when Free =>
  977.                     accept Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  978.                                   Available : out Boolean; Sentence : out T_Lang_array) do
  979.                        Info := To_Unbounded_String(" I'm free... Enjoy !" &
  980.                                                    " " &
  981.                                                    (Character'value
  982.                                                     (T_Cross'image
  983.                                                      (Cross))) & "    " );
  984.                        Available := False;
  985.                        Cross  := Wrap_Succ(Cross);
  986.                     end Status;
  987.               or
  988.                  when not Free =>
  989.                     accept Status(Info : out Ada.Strings.Unbounded.Unbounded_String;
  990.                                   Available : out Boolean; Sentence : out T_Lang_array) do
  991.  
  992.                        Text_Io.Put("plantage 1" );
  993.                        Network_Manager.Status(Info, Available, Sentence);
  994.  
  995.                     end Status;
  996.               end select;
  997.            end if;
  998.            select
  999.               Network_Manager.Stop;
  1000.               Free := True;
  1001.            or
  1002.               delay 0.05;
  1003.  
  1004.            end select;
  1005.         end select;
  1006.      end loop;
  1007.   end Life_Cycle;


 
Mais merci beaucoup de t'être intéressé à mon code [:powa]


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Ada

  Plantage de taches.

 

Sujets relatifs
plannification des taches apache [pour test sur windows != CRON]]Faire disparaitre une appli de la barre des taches PyQt
Modifier et compiler code sourceExecuter périodiquement un .bat avec le planificateur des taches.
Plantage lors de l'execution d'une requete [PHP/MySQL]affecter des taches à un seule core
Plantage sur serveur Unix/Apache avec IE6[VBA] Plantage Excel avec Worksheet_Change
Ne pas afficher de bouton dans la barre des tâchescouleur de la barre des taches
Plus de sujets relatifs à : Plantage de taches.


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR