#OK to post #Yonah Biers-Ariel #Homework 9 ArDataMV:=proc(A,v,N) local ra,x,i,produ,L,j: ra:=rand(-A*1.0..A*1.0): L:=[]: for j from 1 to N do x := [seq(ra(),i=1..nops(v))]: produ := add(x[i]*v[i],i=1..nops(v)): if produ < 0 then L:=[op(L),[x,0]]: else L:=[op(L),[x,1]]: fi: od: L: end: PAmv := proc(L,n,lambda:=1) local v, produ,i,j: v := [0\$n]: for i from 1 to nops(L) do produ := add(L[i][1][j]*v[j],j=1..n): if produ < 0 and L[i][2] = 1 then v := v + lambda*L[i][1]: elif produ >=0 and L[i][2] = 0 then v := v - lambda*L[i][1]: fi: od: v: end: TestPMV := proc(L,v) local fpos, fneg, n, i, j, guess: fpos:=0: fneg:=0: n:=nops(L): for i from 1 to n do guess:=add(L[i][1][j]*v[j],j=1..nops(v)): if guess < 0 and L[i][2] = 1 then fneg := fneg + 1: elif guess >=0 and L[i][2] =0 then fpos := fpos + 1: fi: od: [fneg, fpos, n]: end: PA1corrected := proc(L) local Lnew,i: Lnew := [seq([[op(L[i][1]),1],L[i][2]],i=1..nops(L))]: PAmv(Lnew,2,.1): end: ########COPIED FROM C9######### ArData:=proc(L1,H1,N,c) local L,ra,i,t: ra:=rand(L1..H1): L:=[]: for i from 1 to N do t:=ra(): if t>=c then L:=[op(L),[t,1]]: else L:=[op(L),[t,0]]: fi: od: L: end: PA1:=proc(L) local i,c,n: c:=0: n:=nops(L): for i from 1 to n do if L[i][2]=1 and L[i][1]c then #False negative then c:=c+L[i][1]: fi: od: c: end: TestP:=proc(L,c) local fn,fp,i: fn:=0: fp:=0: for i from 1 to nops(L) do if L[i][1]>=c and L[i][2]=0 then fp:=fp+1: elif L[i][1]=c gets 1 (admitted) and 0 (rejected) and a prob. p of mis-classifying #outputs the noisy data set NoisyData:=proc(L1,H1,N,c,p) local L,ra,i,t,ra1: ra:=rand(L1..H1): ra1:=rand(0.0..1.0): L:=[]: for i from 1 to N do t:=ra(): if t>=c then if ra1()<=p then L:=[op(L),[t,0]]: else L:=[op(L),[t,1]]: fi: else if ra1()<=p then L:=[op(L),[t,1]]: else L:=[op(L),[t,0]]: fi: fi: od: L: end: