Example #1
0
 def __init__(self):
     super(BackgroundThread, self).__init__()
     self.GetConfig()
     self.Recv = Net.ShiroRecv(self.Queue)
     self.Send = Net.SendMessage(port=1300)
     self.sql = sql.ShiroSQL(name="123")
     self.FilePort = (20000, 30000)
     self.sched = BackgroundScheduler()
Example #2
0
 def __init__(self):
     super(BackgroundThread,self).__init__()
     self.GetConfig()
     self.Recv = Net.ShiroRecv(self.Queue,Port=1300)
     for i in self.share:
         self.watch_list.append(watch.Watch(i,self.Queue))
     self.Send = Net.SendMessage()
     self.sql = sql.ShiroSQL("../222")
     self.FilePort = (20000,30000)
Example #3
0
 def _show(self):
     self.show()
     self.Watch_List = Watch("D:\英雄时刻", self.data)
     self.NET = CA.ShiroNet(self.data, self.Watch_List.model)
     self.connectSlots()
     self.NET.start()
     self.Watch_List.start()
Example #4
0
 def on_ACKN(self,data,ip):
     # 收到确认包,开始链接服务器接收
     print("收到确认包")
     port = data.get("port")
     AckId = data.get("AckId")
     filedata = None
     w = False
     uu = ""
     for k,v in self.WaitAckFiles.items():
         if k == AckId:
             filedata = v.get("File")
             uu = self.sql.GetDirName(filedata.get("belong_dir"))
             print(uu)
             if not uu:
                 return
             w = k
             break
     if w:
         del self.WaitAckFiles[w]
     if filedata == None:
         return
     url = oc.path_join(oc.path_join(self.main_dir,uu),filedata.get("FileName")+filedata.get("suffix"))
     filedata["url"] = url
     print(filedata)
     def f(o):
         return filedata.get(o)
     e = self.sql.AddFile(f("_id"),f("FileName"),f("suffix"),f("md5"),f("belong_dir"),f("owner"),url,f("end_time"))
     if not e:
         filedata["abs_url"] = url
         self.sql.ChangeFile(f("_id"),filedata)
     thread = Net.FileRecv(ip,port,filedata)
     thread.start()
Example #5
0
def newhem(target, transf=None, max_iter=10, delta=0):
    """
    Create a Hemming recurrent network with 2 layers

    :Parameters:
        target: array like (l x net.co)
            train target patterns
        transf: func (default SatLinPrm(0.1, 0, 10))
            Activation function of input layer
        max_init: int (default 10)
            Maximum of recurent iterations
        delta: float (default 0)
            Minimum diference between 2 outputs for stop reccurent cycle
    :Returns:
        net: Net
    :Example:
        >>> net = newhop([[-1, -1, -1], [1, -1, 1]])
        >>> output = net.sim([[-1, 1, -1], [1, -1, 1]])

    """

    target = np.asfarray(target)
    assert target.ndim == 2

    cn = target.shape[0]
    ci = target.shape[1]

    if transf is None:
        transf = trans.SatLinPrm(0.1, 0, 10)
    layer_inp = layer.Perceptron(ci, cn, transf)

    # init input layer
    layer_inp.initf = None
    layer_inp.np['b'][:] = float(ci) / 2
    for i, tar in enumerate(target):
        layer_inp.np['w'][i][:] = tar / 2

    layer_out = layer.Reccurent(cn, cn, trans.SatLinPrm(1, 0, 1e6), max_iter, delta)
    # init output layer
    layer_out.initf = None
    layer_out.np['b'][:] = 0
    eps = - 1.0 / cn
    for i in range(cn):
        layer_out.np['w'][i][:] = [eps] * cn
        layer_out.np['w'][i][i] = 1
    # create network
    minmax = [[-1, 1]] * ci
    layers = [layer_inp, layer_out]
    connect = [[-1], [0], [1]]
    net = Net(minmax, cn, layers, connect, None, None)
    return net
Example #6
0
 def on_FILE(self, data, ip):
     print("收到一个请求文件的东西")
     file_id = data.get("GetId")
     AckId = data.get("AckId")
     url, md5, ttt = self.watch_dir_search(file_id)
     if not url:
         return
     port = oc.RngPort(self.FilePort)
     thread = Net.FileSend(url, port)
     thread.start()
     self.Send.SendTo(ip, "ACKN", {
         "port": thread.port,
         "md5": md5,
         "time": ttt,
         "AckId": AckId,
     })
Example #7
0
def newhop(target, transf=None, max_init=10, delta=0):
    """
    Create a Hopfield recurrent network

    :Parameters:
        target: array like (l x net.co)
            train target patterns
        transf: func (default HardLims)
            Activation function
        max_init: int (default 10)
            Maximum of recurent iterations
        delta: float (default 0)
            Minimum diference between 2 outputs for stop reccurent cycle
    :Returns:
        net: Net
    :Example:
        >>> net = newhop([[-1, -1, -1], [1, -1, 1]])
        >>> output = net.sim([[-1, 1, -1], [1, -1, 1]])

    """

    target = np.asfarray(target)
    assert target.ndim == 2

    ci = len(target[0])
    if transf is None:
        transf = trans.HardLims()
    l = layer.Reccurent(ci, ci, transf, max_init, delta)
    w = l.np['w']
    b = l.np['b']

    # init weight
    for i in range(ci):
        for j in range(ci):
            if i == j:
                w[i, j] = 0.0
            else:
                w[i, j] = np.sum(target[:, i] * target[:, j]) / ci
        b[i] = 0.0
    l.initf = None

    minmax = transf.out_minmax if hasattr(transf, 'out_minmax') else [-1, 1]

    net = Net([minmax] * ci, ci, [l], [[-1], [0]], None, None)
    return net
Example #8
0
def newff(minmax, size, transf=None):
    """
    Create multilayer perceptron

    :Parameters:
        minmax: list ci x 2
            Range of input value
        size: list of length equal to the number of layers
            Contains the number of neurons for each layer
        transf: list (default TanSig)
            List of activation function for each layer
    :Returns:
        net: Net
    :Example:
        >>> # create neural net with 2 inputs, 1 output and 2 layers
        >>> net = newff([[-0.5, 0.5], [-0.5, 0.5]], [3, 1])
        >>> net.ci
        2
        >>> net.co
        1
        >>> len(net.layers)
        2

    """

    net_ci = len(minmax)
    net_co = size[-1]

    if transf is None:
        transf = [trans.TanSig()] * len(size)
    assert len(transf) == len(size)

    layers = []
    for i, nn in enumerate(size):
        layer_ci = size[i - 1] if i > 0 else net_ci
        l = layer.Perceptron(layer_ci, nn, transf[i])
        l.initf = init.initnw
        layers.append(l)
    connect = [[i - 1] for i in range(len(layers) + 1)]

    net = Net(minmax, net_co, layers, connect, train.train_bfgs, error.SSE())
    return net
Example #9
0
def newhop_old(target, transf=None):
    """
    Create a Hopfield recurrent network.

    Old version need tool.simhop for use.
    Will be removed in future versions.

    :Parameters:
        target: array like (l x net.co)
            train target patterns
        transf: func (default HardLims)
            Activation function
    :Returns:
        net: Net
    :Example:
        >>> from neurolab.tool import simhop
        >>> net = newhop_old([[-1, 1, -1], [1, -1, 1]])
        >>> output = simhop(net, [[-1, 1, -1], [1, -1, 1]])
    """

    target = np.asfarray(target)
    ci = len(target[0])
    if transf is None:
        transf = trans.HardLims()
    l = layer.Perceptron(ci, ci, transf)
    w = l.np['w']
    b = l.np['b']

    # init weight
    for i in range(ci):
        for j in range(ci):
            if i == j:
                w[i, j] = 0.0
            else:
                w[i, j] = np.sum(target[:, i] * target[:, j]) / ci
        b[i] = 0.0
    l.initf = None

    minmax = transf.out_minmax if hasattr(transf, 'out_minmax') else [-1, 1]

    net = Net([minmax] * ci, ci, [l], [[0], [0]], None, None)
    return net
Example #10
0
def newelm(minmax, size, transf=None):
    """
    Create a Elman recurrent network

    :Parameters:
        minmax: list ci x 2
            Range of input value
        size: list of length equal to the number of layers
            Contains the number of neurons for each layer
    :Returns:
        net: Net
    :Example:
        >>> net = newelm([[-1, 1]], [1], [trans.PureLin()])
        >>> net.layers[0].np['w'][:] = 1
        >>> net.layers[0].np['b'][:] = 0
        >>> net.sim([[1], [1] ,[1], [3]])
        array([[ 1.],
               [ 2.],
               [ 3.],
               [ 6.]])
    """

    net_ci = len(minmax)
    net_co = size[-1]

    if transf is None:
        transf = [trans.TanSig()] * len(size)
    assert len(transf) == len(size)

    layers = []
    for i, nn in enumerate(size):
        layer_ci = size[i - 1] if i > 0 else net_ci + size[0]
        l = layer.Perceptron(layer_ci, nn, transf[i])
        #l.initf = init.InitRand([-0.1, 0.1], 'wb')
        layers.append(l)
    connect = [[i - 1] for i in range(len(layers) + 1)]
    # recurrent set
    connect[0] = [-1, 0]

    net = Net(minmax, net_co, layers, connect, train.train_gdx, error.MSE())
    return net
Example #11
0
def newc(minmax, cn):
    """
    Create competitive layer (Kohonen network)

    :Parameters:
        minmax: list ci x 2
            Range of input value
        cn: int
            Number of neurons
    :Returns:
        net: Net
    :Example:
        >>> # create network with 2 inputs and 10 neurons
        >>> net = newc([[-1, 1], [-1, 1]], 10)

    """
    ci = len(minmax)
    l = layer.Competitive(ci, cn)
    net = Net(minmax, cn, [l], [[-1], [0]], train.train_cwta, error.SAE())

    return net
Example #12
0
def newlvq(minmax, cn0, pc):
    """
    Create a learning vector quantization (LVQ) network

    :Parameters:
        minmax: list ci x 2
            Range of input value
        cn0: int
            Number of neurons in input layer
        pc: list
            List of percent, sum(pc) == 1
    :Returns:
        net: Net
    :Example:
        >>> # create network with 2 inputs,
        >>> # 2 layers and 10 neurons in each layer
        >>> net = newlvq([[-1, 1], [-1, 1]], 10, [0.6, 0.4])

    """
    pc = np.asfarray(pc)
    assert sum(pc) == 1
    ci = len(minmax)
    cn1 = len(pc)
    assert cn0 > cn1

    layer_inp = layer.Competitive(ci, cn0)
    layer_out = layer.Perceptron(cn0, cn1, trans.PureLin())
    layer_out.initf = None
    layer_out.np['b'].fill(0.0)
    layer_out.np['w'].fill(0.0)
    inx = np.floor(cn0 * pc.cumsum())
    for n, i in enumerate(inx):
        st = 0 if n == 0 else inx[n - 1]
        layer_out.np['w'][n][st:i].fill(1.0)
    net = Net(minmax, cn1, [layer_inp, layer_out], [[-1], [0], [1]],
              train.train_lvq, error.MSE())

    return net
Example #13
0
def newp(minmax, cn, transf=trans.HardLim()):
    """
    Create one layer perceptron

    :Parameters:
        minmax: list ci x 2
            Range of input value
        cn: int
            Number of neurons
        transf: func (default HardLim)
            Activation function
    :Returns:
        net: Net
    :Example:
        >>> # create network with 2 inputs and 10 neurons
        >>> net = newp([[-1, 1], [-1, 1]], 10)

    """

    ci = len(minmax)
    l = layer.Perceptron(ci, cn, transf)
    net = Net(minmax, cn, [l], [[-1], [0]], train.train_delta, error.SSE())
    return net
Example #14
0
File: util.py Project: Pibben/sim74
 def __init__(self, names):
     self.nets = [Net(name) for name in names]