Ejemplo n.º 1
0
#perCsp2 = np.array([0.000022,0.0006,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001])

perCsp1 = np.linspace(0.0000006, 0.00005, iteration_steps)
perCsp2 = np.linspace(0.000022, 0.0006, iteration_steps)

perCsp = np.zeros((iteration_steps, 1))

Usparsity1 = np.zeros((iteration_steps, 1))
Usparsity2 = np.zeros((iteration_steps, 1))

for i in range(0, iteration_steps):

    params1[8] = perCsp1[i]
    params2[8] = perCsp2[i]

    U1, obj1, tmp_sparsity1 = feta.FastNetTrim(Xtr1, Ytr1, Xval1, Yval1,
                                               params1)
    U2, obj2, tmp_sparsity2 = feta.FastNetTrim(Xtr2, Ytr2, Xval2, Yval2,
                                               params2)

    Usparsity1[i] = tmp_sparsity1[-1]
    Usparsity2[i] = tmp_sparsity2[-1]

    perCsp[i] = (Usparsity1[i] * weights1.shape[0] * weights1.shape[1] / 100 +
                 Usparsity2[i] * weights2.shape[0] * weights2.shape[1] /
                 100) / (weights1.shape[0] * weights1.shape[1] +
                         weights2.shape[0] * weights2.shape[1])

    new_dense_1 = U1[1:, :]
    new_dense_2 = U2[1:, :]

    bias1 = U1[0, :]
Ejemplo n.º 2
0
params[4]=200 # batch size.
params[8] = 0.0004 #the lambda parameter controlling sparsity. Needs to be hand tuned.

#Creating the synthetic dataset
Xtr = np.random.normal(0,1,(d_input,Training_size))
Xval = np.random.normal(0,1,(d_input,Validation_size))

U_dense = np.random.normal(0,1,(d_output,d_input))
bias_dense = np.random.normal(0,1,(d_output,1))

Ytr  = np.maximum(U_dense@Xtr+bias_dense,0)
Yval = np.maximum(U_dense@Xval+bias_dense,0)


# Running FeTa
U, obj, tmp_sparsity = feta.FastNetTrim(Xtr,Ytr,Xval,Yval,params)

# Plotting the results

size_font = 12

fig1, ax1 = plt.subplots()
plt.ylabel('|| ||_2',fontsize=size_font)
plt.xlabel('Iterations #',fontsize=size_font)
ax1.plot(np.arange(0,params[0]),obj,linestyle = '-',color = 'xkcd:blue')
plt.grid(linestyle=':')
plt.title('FeTa || ||_2')

fig2, ax2 = plt.subplots()
plt.ylabel('Sparsity %',fontsize=size_font)
plt.xlabel('Iterations #',fontsize=size_font)