Ejemplo n.º 1
0
		else:
			w[i]=0;
	return w;

data = np.loadtxt("train")

(n,d) = data.shape
#split
s1 = np.random.choice(range(data.shape[0]), 700, replace=False);
s2 = list(set(range(data.shape[0])) - set(s1));

x1=data[:,0:d-1];
x2=data[s2,0:d-1];
y1=data[:,d-1:d];
y2=data[s2,d-1:d];
(j,k)=solver(x1,y1,0.1,1);
#print(j)
print(k)
'''w=np.zeros((1000, 1));
w[2]=4;
w[1]=3;
print(LA.norm(w,2))
r=1;

x1t=np.transpose(x1)

D=w-r*(2*(x1t @ ((x1 @ w)-y1)));
w1=s_mu(D,r)
z=np.transpose(w1);
print(5-np.dot(w1,w))
print(np.dot(z,w))
Ejemplo n.º 2
0
# To avoid unlucky outcomes try running the code several times
numTrials = 5

# Try various timeouts - the timeouts are in seconds
timeouts = np.array([0.1, 1, 2, 5])

# Try checking for timeout every 10 iterations
spacing = 10

result = np.zeros((len(timeouts), 4))

for i in range(len(timeouts)):
    to = timeouts[i]
    avgObj = 0
    avgDist = 0
    avgSupp = 0
    avgTime = 0
    for t in range(numTrials):
        (w, totTime) = solver(X, y, to, spacing)
        avgObj = avgObj + getObjValue(X, y, w)
        avgDist = avgDist + getModelError(w, wAst)
        avgSupp = avgSupp + getSupportError(w, wAst, k)
        avgTime = avgTime + totTime
    result[i, 0] = avgObj / numTrials
    result[i, 1] = avgDist / numTrials
    result[i, 2] = avgSupp / numTrials
    result[i, 3] = avgTime / numTrials

np.savetxt("result", result, fmt="%.6f")
Ejemplo n.º 3
0
import numpy as np
from submit import solver

def getObj( X, y, w, b ):
	hingeLoss = np.maximum( 1 - np.multiply( (X.dot( w ) + b), y ), 0 )
	return 0.5 * w.dot( w ) + C * hingeLoss.dot( hingeLoss )

Z = np.loadtxt( "data" )

y = Z[:,0]
X = Z[:,1:]
C = 1

avgTime = 0
avgPerf = 0

# To avoid unlucky outcomes try running the code several times
numTrials = 5
# 30 second timeout for each run
timeout = 30
# Try checking for timeout every 100 iterations
spacing = 100

for t in range( numTrials ):
	(w, b, totTime) = solver( X, y, C, timeout, spacing )
	avgTime = avgTime + totTime
	avgPerf = avgPerf + getObj( X, y, w, b )

print( avgPerf/numTrials, avgTime/numTrials )