diff --git a/ppvoisin.ml b/ppvoisin.ml index d399666..7f34e71 100644 --- a/ppvoisin.ml +++ b/ppvoisin.ml @@ -556,4 +556,152 @@ let ppvmoinsnaif ns xx yy = cherche plus loin autour pour trouver le résultat*) maxrpz (ppvmoinsnaif 50 xa ya) 100_000;; maxrpz (ppvmoinsnaif 500 xb yb) 1_000_000;; -maxrpz (ppvmoinsnaif 1000 xc yc) 1_000_000;; \ No newline at end of file +maxrpz (ppvmoinsnaif 1000 xc yc) 1_000_000;; + + +(* Q8 bis *) + +let dessineSurMatrice xx n0 = + let out = Array.make_matrix n0 n0 (-1) in + let n = Array.length xx in + for i=0 to (n-1) + do + let cox = xx.(i).(0) and coy = xx.(i).(1) in + if out.(cox).(coy) = -1 then out.(cox).(coy) <- i + done; + out;; + +let rec minlst l = match l with + | [] -> raise EmptyException + | [e] -> e + | e::s -> let o = minlst s in + min e o;; + +let ppvPositionnel0 dessin n0 y = + let cox,coy = y.(0),y.(1) in + if dessin.(cox).(coy)<>(-1) then dessin.(cox).(coy) else + let mins = ref [] in + for i=(if cox<>0 then -1 else 0) to (if cox<(n0-1) then 1 else 0) do + for j=(if coy<>0 then -1 else 0) to (if coy<(n0-1) then 1 else 0) do + let cc=dessin.(cox+i).(coy+j) in + if cc<>(-1) then empile mins cc + done + done; + minlst !mins;; + +let ppvPositionnel xx yy n0 = + let dessin = dessineSurMatrice xx n0 in + let m = Array.length yy in + let out = Array.make m (-1) in + for j=0 to (m-1) do + out.(j) <- ppvPositionnel0 dessin n0 yy.(j) + done; + out;; + +let maxreparr arr nm = + let n = Array.length arr in + let count = Array.make nm 0 in + for i=0 to (n-1) do + if arr.(i)<>(-1) then + count.(arr.(i)) <- count.(arr.(i))+1 + done; + maxindex count;; + +let xa,ya = getxy 2 100_000 10_000;; +let xb,yb = getxy 2 1_000_000 100_000;; +let xc,yc = getxy 2 1_000_000 1_000_000;; +maxreparr (ppvPositionnel xa ya 1000) 100_000;; +maxreparr (ppvPositionnel xb yb 1000) 1_000_000;; +maxreparr (ppvPositionnel xc yc 1000) 1_000_000;; + +(* Question 9 *) + +let getxy d n m = + let xx = Array.make n [||] in + let yy = Array.make m [||] in + for i=0 to (n-1) + do + xx.(i) <- Array.make d 0; + for k=0 to (d-1) + do + xx.(i).(k) <- (u ((i*d)+k)) mod 2 + done + done; + for j=0 to (m-1) do + yy.(j) <- Array.make d 0; + for k=0 to (d-1) + do + yy.(j).(k) <- (u ((n+j)*d+k)) mod 2 + done + done; + (xx,yy);; + +let xa,ya = getxy 10 1000 1_000_000;; +let xb,yb = getxy 10 10_000 1_000_000;; +let xc,yc = getxy 20 1_000_000 1_000_000;; + +(* Au final, la distance max entre deux vecteurs, c'est la dimension *) + +let vectToInt x = + let d = Array.length x in + let sum = ref 0 in + for i=0 to d-1 do + sum := !sum + (x.(i))*(1 lsl i) + done; + !sum;; + +let vectsToInts xx = + let n = Array.length xx in + let out = Array.make n (-1) in + for i=0 to (n-1) do + out.(i) <- vectToInt xx.(i) + done; + out;; + +let xia,yia = (vectsToInts xa,vectsToInts ya);; +let xib,yib = (vectsToInts xb,vectsToInts yb);; +let xic,yic = (vectsToInts xc,vectsToInts yc);; + +let dessineSurLigne xx d = + let out = Array.make (1 lsl d) (-1) in + let n = Array.length xx in + for i=0 to (n-1) + do + if out.(xx.(i)) = -1 then out.(xx.(i)) <- i + done; + out;; + +let listeCopains x d = + let rec aux x d i l= + if i=d + then l + else aux x d (i+1) (((1 lsl i) lxor x)::l) + in aux x d 0 [];; + +let ppvBPositionnel0 dessin d y = + if dessin.(y)<>(-1) then dessin.(y) else (* Le cas où le plus proche voisin est déjà ici *) + let mins = ref [] in + for i=0 to d-1 do + let cc = dessin.((1 lsl i) lxor y) in + if cc<>(-1) then empile mins cc + done; + minlst !mins;; + +let ppvBPositionnel xx yy d = + let dessin = dessineSurLigne xx d in + let m = Array.length yy in + let out = Array.make m (-1) in + for j=0 to (m-1) do + out.(j) <- ppvBPositionnel0 dessin d yy.(j) + done; + out;; + +xa.(1);; +vectToInt xa.(1);; +dessineSurLigne xia 10;; +ppvBPositionnel xib yib 10;; +maxreparr (ppvBPositionnel xia yia 10) (1 lsl 10);; +maxreparr (ppvBPositionnel xib yib 10) (1 lsl 20);; +maxreparr (ppvBPositionnel xic yic 20) (1 lsl 20);; + +