• No se han encontrado resultados

INSTRUMENTOS PARA LA RECOGIDA DE INFORMA CIÓN DIRECTA

DISPOSITIVOS DE EVALUACION

INDICADORES CRITERIOS

4.6. INSTRUMENTOS PARA LA RECOGIDA DE INFORMA CIÓN DIRECTA

In what follows we will mostly use uniform distributions, or, in the parlance of social choice, impartial cultures. The general method for achieving this is to first generate all the possibilities and store them in an array. The following function then generates random indices for such an array and extracts the data that these point to.

Agg/Gen.hs

rndsFromArr :: (Random i, A.Ix i) => A.Array i e -> StdGen -> [e] rndsFromArr arr gen = map (arr A.!) (randomRs (A.bounds arr) gen)

Generating preferences

We start by showing how to generate random lists of lists. First, it would be nice to be able to count the number of possible weak orders. Recall Table 2.1;

a670 allows us to find out how many weak orders there are for much larger values. It uses the “choose” functionnCr. This formula is not trivial: it is taken from a self published note by Kochanski (2007).

Agg/Gen.hs nCr :: (Integral a, Show a) => a -> a -> a nCr n r | n==r = 1

| n>r = div (f n val) (factorial (n-val)) where val = max r (abs (r-n))

f x y | x == y = 1

| otherwise = x * f (x-1) y a670 :: Int -> Int

a670 0 = 1

a670 n = sum [(nCr n r) * (a670 r) | r <- [0..n-1]]

Becausea670grows as quickly as it does, generating all possible weak orders for even relatively small numbers of alternatives is infeasible. Nevertheless, here is the code that does so: given input nallLOLs creates all weak orders over the set{0, . . . , n−1}.

Agg/Gen.hs allLOLs :: Int -> [[[Int]]]

allLOLs 0 = [[]]

allLOLs n = concatMap (allLOLs' (n-1)) (allLOLs (n-1)) where allLOLs' :: (Eq a) => a -> [[a]] -> [[[a]]]

allLOLs' x [] = [[[x]]]

allLOLs' x (xs:xss) = ([x]:(xs:xss)) : ((x:xs):xss)

: map (xs:) (allLOLs' x xss)

Finally, we store these lists of lists in an array and applyrndsFromArr.

Agg/Gen.hs rndLOLs :: Int -> StdGen -> [LOL] rndLOLs nStates = rndsFromArr arr

where arr = A.listArray (1,a670 nStates) (allLOLs nStates)

We here note that it would be a simple matter to prepend a filter to this list, for e.g. to restrict to single peaked preferences. See Appendix B.2.6.

Generating transition sequences

As with preferences, the number of possible transition sequences increases ex- ponentially. Using Control.Applicative, the functiongenActions generates all possible actions for n states. Note there are nn such. We then generate

random such actions with rndActs. In order to turn this into a list of tran- sition sequences, we could simply unConcat them. However, unConcatNub is preferable in that it ensures that no transition sequence contains two identical actions. Note this means that if the number of actions is greater thannn then

Agg/Gen.hs genActions :: Int -> [[Int]]

genActions n = iterate (liftA2 (:) [0..n-1]) [[]] !! n rndActs :: Int -> StdGen -> [[Int]]

rndActs nSt = rndsFromArr arr

where arr = A.listArray (1,nSt^nSt) (genActions nSt) unConcat :: Int -> [a] -> [[a]]

unConcat n [] = [] unConcat n xs =

let (h,t) = splitAt n xs in h:(unConcat n t)

unConcatNub :: (Eq a) => Int -> [a] -> [[a]] unConcatNub n xs = unc [] n xs n

where unc hs 0 xs n = hs : (unConcatNub n xs) unc hs i (x:xs) n | x`elem`hs = unc hs i xs n

| otherwise = unc (x:hs) (i-1) xs n unc [] i [] n = []

unc hs i [] n = [hs] rndTSQs :: Int -> Int -> StdGen -> [TSQ]

rndTSQs nStates nActs = unConcatNub nActs . rndActs nStates

Definition 4.6.1. A transition sequence is covering if from every input state each output state is achievable by some action.

The following generates minimal covering transition sequences. In these there are exactly as many states as actions.

Agg/Gen.hs

unConcatTranspose :: Int -> [[a]] -> [[[a]]] unConcatTranspose n [] = []

unConcatTranspose n xs = let (h,t) = splitAt n xs

in (transpose h):( unConcatTranspose n t) rndCovTSQs :: Int -> StdGen -> [TSQ]

rndCovTSQs n = unConcatTranspose n. rndsFromArr perms

where perms = A.listArray (1,factorial n) (permutations [0..n-1])

Generating belief sets

As with lists of lists and transition sequences we could generate all the possi- ble belief sets, allBELs below, then randomly choose one by its index. The helper, allBELs', iteratively takes an element x from [0..n-1], and to each constructed belief sets both prepends xs and returns the original set as well, utilising the applicative property of lists. This obtains the result, only also including the (unwanted) emptyset.

Agg/Gen.hs allBELs' :: Int -> [BEL]

allBELs' n = foldr (\new ->(<*>) [(new:),id]) [[]] [0..n-1] allBELs :: Int -> [BEL]

allBELs n = init $ allBELs' n

However we here want (slightly) more complexity than a uniform distribution of belief sets. We want to model agents who can be more or less accurate, in some way.

With that aim in mind, we now treat possible worlds as complete sets of literals: equivalently, as a list ofTrueandFalsevalues. Call these listsBoolean descriptions. From such Boolean description, descToState returns a number identifying the state.

Agg/Gen.hs descToState :: [Bool] -> Int

descToState = foldl1 (+). zipWith (belT .(2^)) [0..] where belT x False = x

belT _ True = 0

Thus, Boolean descriptions of lengthk will be identified with states in the list

[0..2^k-1]. As 0 is present in any list [0..n], it makes sense to use it to represent the ‘actual’ world.

We model agents as ‘noisy’ observers of the propositions. For each proposi- tionp, the agent can either

(i) believep,

(ii) believe notp, or

(iii) believepor notp.

Note an agent cannot believe neither a proposition nor its negation, as then they will not thinkany world possible. The probability of these possibilities can be assigned byw1andw2in the theinterval [0,1], withw1>w2andw1+w2≤1, wherew1is the probability that an agent is correct about a proposition, andw2is the probability that the agent is wrong about a proposition. Given these weights and a random number x between 0 and 1, the function giveBoolreturns the possibilities for a given proposition. The functionrndBoolsgenerates a random list of such possibilities.

Agg/Gen.hs

giveBool :: Float -> Float -> Float -> [Bool] giveBool w1 w2 x | x < w1 = [True]

| x < w1+w2 = [False] | otherwise = [True ,False] rndBools :: Float -> Float -> StdGen -> [[Bool]] rndBools w1 w2 = map (giveBool w1 w2).randoms

From a list of possibilities for each proposition we can generate a list Boolean de- scriptions withtoDescs, which then correspond to the worlds believed possible. The functionrndBELsputs this all together to generate a list of belief sets, each of was created with the same uniform probability of getting each proposition correct.

Agg/Gen.hs toDescs :: [[a]] -> [[a]]

toDescs = foldr (liftA2 (:)) [[]]

rndBELs :: Int -> Float -> Float -> StdGen -> [BEL]

rndBELs nPrps w1 w2 = map (map descToState.toDescs).unConcat nPrps . rndBools w1 w2

Actual utilised data

Though the details are relegated to Appendix B.2.3, using the above we can clearly generate profiles for beliefs and preferences, and files containing multiple instances of each.