示例#1
0
文件: test.py 项目: Baxonn2/ids
def test(file_path):
    # Cargando data
    data_test = "./csv_files/KDDTest.txt"
    xv, yv = load_data(data_test)
    Xv = np.vstack([xv, np.full((1, xv.shape[1]), 1)])

    w1, w2 = load_w()

    D = Xv.shape[0]
    wh = np.reshape(w1, (Nh, D))
    H = activation(wh, Xv)
    zv = np.matmul(w2, H)

    accuracy, fscore = metrica(zv, yv)

    save(accuracy, fscore)
示例#2
0
文件: qpso.py 项目: Baxonn2/ids
def fitness(Xe, ye, Nh, X, Cpinv):
    N, D = Xe.shape
    Np = configs.Np

    # Shape (Np)
    W2 = np.zeros((Np, Nh))  # TODO: inicializar los pesos

    # Posiblemente dejemos la cagá
    MSE = np.full(Np, -1.0)

    for i in range(Np):
        p = X[i, :]
        w1 = np.reshape(p, (D, Nh))
        H = activation(Xe, w1)
        W2[i, :] = mlp_pinv(H, ye, configs.C)
        ze = W2[i, :].dot(np.transpose(H))

        MSE[i] = np.sqrt(mse(ye, ze))  # Error cuadratico medio

    # FIXME: esto está mal porque da cero siempre
    return MSE, W2
示例#3
0
import numpy as np
from activation import activation

act = activation()


def init_network():
    network = {}
    network['w1'] = np.array([[0.1, 0.3, 0.5], [0.2, 0.4, 0.6]])
    network['b1'] = np.array([0.1, 0.2, 0.3])
    network['w2'] = np.array([[0.1, 0.4], [0.2, 0.5], [0.3, 0.6]])
    network['b2'] = np.array([0.1, 0.2])

    return network


def forward(network, x):
    w1, w2 = network['w1'], network['w2']
    b1, b2 = network['b1'], network['b2']

    a1 = np.dot(x, w1) + b1
    z1 = act.sigmoid(a1)
    a2 = np.dot(z1, w2) + b2

    return a2


# --------- メイン処理 -----------
network = init_network()
x = np.array([1.0, 0.5])
y = forward(network, x)