How to resolve the algorithm Diversity prediction theorem step by step in the Ada programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Diversity prediction theorem step by step in the Ada programming language

Table of Contents

Problem Statement

The   wisdom of the crowd   is the collective opinion of a group of individuals rather than that of a single expert. Wisdom-of-the-crowds research routinely attributes the superiority of crowd averages over individual judgments to the elimination of individual noise,   an explanation that assumes independence of the individual judgments from each other. Thus the crowd tends to make its best decisions if it is made up of diverse opinions and ideologies.

Scott E. Page introduced the diversity prediction theorem:

Therefore,   when the diversity in a group is large,   the error of the crowd is small.

For a given   true   value and a number of number of estimates (from a crowd),   show   (here on this page):

Use   (at least)   these two examples:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Diversity prediction theorem step by step in the Ada programming language

Source code in the ada programming language

with Ada.Text_IO;
with Ada.Command_Line;

procedure Diversity_Prediction is

   type Real is new Float;
   type Real_Array is array (Positive range <>) of Real;

   package Real_IO is new Ada.Text_Io.Float_IO (Real);
   use Ada.Text_IO, Ada.Command_Line, Real_IO;

   function Mean (Data : Real_Array) return Real is
      Sum : Real := 0.0;
   begin
      for V of Data loop
         Sum := Sum + V;
      end loop;
      return Sum / Real (Data'Length);
   end Mean;

   function Variance (Reference : Real; Data : Real_Array) return Real is
      Res : Real_Array (Data'Range);
   begin
      for A in Data'Range loop
         Res (A) := (Reference - Data (A)) ** 2;
      end loop;
      return Mean (Res);
   end Variance;

   procedure Diversity (Truth : Real; Estimates : Real_Array)
   is
      Average       : constant Real := Mean (Estimates);
      Average_Error : constant Real := Variance (Truth, Estimates);
      Crowd_Error   : constant Real := (Truth - Average) ** 2;
      Diversity     : constant Real := Variance (Average, Estimates);
   begin
      Real_IO.Default_Exp := 0;
      Real_IO.Default_Aft := 5;
      Put ("average-error : "); Put (Average_Error);  New_Line;
      Put ("crowd-error   : "); Put (Crowd_Error);    New_Line;
      Put ("diversity     : "); Put (Diversity);      New_Line;
   end Diversity;

begin
   if Argument_Count <= 1 then
      Put_Line ("Usage: diversity_prediction <truth> <data_1> <data_2> ...");
      return;
   end if;

   declare
      Truth     : constant Real := Real'Value (Argument (1));
      Estimates : Real_Array (2 .. Argument_Count);
   begin
      for A in 2 .. Argument_Count loop
         Estimates (A) := Real'Value (Argument (A));
      end loop;

      Diversity (Truth, Estimates);
   end;
end Diversity_Prediction;


  

You may also check:How to resolve the algorithm Harshad or Niven series step by step in the FOCAL programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the ooRexx programming language
You may also check:How to resolve the algorithm Bifid cipher step by step in the Python programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the C++ programming language
You may also check:How to resolve the algorithm Playfair cipher step by step in the APL programming language