Exemplo n.º 1
0
 public bool IsSameSession(Origin o)
 {
     return((SessionID.Equals(o.SessionID)) &&
            (UserName.Equals(o.UserName)) &&
            (NetworkType.Equals(o.NetworkType)) &&
            (AddressType.Equals(o.AddressType)) &&
            (Address.Equals(o.Address)));
 }
Exemplo n.º 2
0
    public bool Train(float[] fInput, float[] fCorrect, float[] reward = default)
    {
        Matrix input = new Matrix(fInput);

        Matrix[] postActivationFPrime = new Matrix[layers.Length];
        Matrix[] postActivationF      = new Matrix[layers.Length];
        int      a = 0;

        for (int l = 0; l < layers.Length; l++)
        {
            Matrix hidden = layers[l] * input;
            hidden = hidden + biases[l];
            postActivationFPrime[l] = hidden.duplicate();
            for (int i = 0; i < hidden.Rows; i++)
            {
                for (int j = 0; j < hidden.Columns; j++)
                {
                    postActivationFPrime[l][i, j] = ActivationFunctionDerivs[aFunctions[l][i]](hidden[i, j]);
                    hidden[i, j] = ActivationFunctions[aFunctions[l][i]](hidden[i, j]);
                }
            }
            a += hidden.Rows;
            postActivationF[l] = hidden.duplicate();

            input = hidden;
        }
        Matrix error = new Matrix(outputs, 1);

        if (type.Equals(NetworkType.Supervised))
        {
            for (int i = 0; i < error.Rows; i++)
            {
                error[i, 0] = fCorrect[i] - postActivationF[postActivationF.Length - 1].toArray()[i];
            }
        }
        else if (type.Equals(NetworkType.PolicyGradient))
        {
            for (int i = 0; i < error.Rows; i++)
            {
                error[i, 0] = (float)reward[i];
            }
        }
        //Debug.Log(layers.Length);
        for (int l = layers.Length - 1; l >= 0; l--)
        {
            //
            Matrix deltaB = learningrate * error.eWiseMultiply(postActivationFPrime[l]);
            biases[l] += deltaB;
            if (l > 0)
            {
                deltaB *= postActivationF[l - 1].Transpose();
            }
            else
            {
                //needs sigmoid
                deltaB *= new Matrix(fInput).Transpose();
            }
            layers[l] += deltaB;

            error = layers[l].Transpose() * error;
        }
        //learningrate = Random.Range(0.001f, 1f);
        //Random.InitState((int)System.DateTime.Now.Ticks);
        return(true);
    }
Exemplo n.º 3
0
        public void UpdateNetwork(ZeroTierNetwork network)
        {
            if (network == null)
            {
                return;
            }

            if (!NetworkId.Equals(network.NetworkId))
            {
                NetworkId = network.NetworkId;
            }

            if (!MacAddress.Equals(network.MacAddress))
            {
                MacAddress = network.MacAddress;
            }

            if (!NetworkName.Equals(network.NetworkName))
            {
                NetworkName = network.NetworkName;
            }

            if (!NetworkStatus.Equals(network.NetworkStatus))
            {
                NetworkStatus = network.NetworkStatus;
            }

            if (!NetworkType.Equals(network.NetworkType))
            {
                NetworkType = network.NetworkType;
            }

            if (MTU != network.MTU)
            {
                MTU = network.MTU;
            }

            if (DHCP != network.DHCP)
            {
                DHCP = network.DHCP;
            }

            if (Bridge != network.Bridge)
            {
                Bridge = network.Bridge;
            }

            if (BroadcastEnabled != network.BroadcastEnabled)
            {
                BroadcastEnabled = network.BroadcastEnabled;
            }

            if (PortError != network.PortError)
            {
                PortError = network.PortError;
            }

            if (NetconfRevision != network.NetconfRevision)
            {
                NetconfRevision = network.NetconfRevision;
            }

            AssignedAddresses = network.AssignedAddresses;

            Routes = network.Routes;

            if (!DeviceName.Equals(network.DeviceName))
            {
                DeviceName = network.DeviceName;
            }

            if (AllowManaged != network.AllowManaged)
            {
                AllowManaged = network.AllowManaged;
            }

            if (AllowGlobal != network.AllowGlobal)
            {
                AllowGlobal = network.AllowGlobal;
            }

            if (AllowDefault != network.AllowDefault)
            {
                AllowDefault = network.AllowDefault;
            }

            if (IsConnected != network.IsConnected)
            {
                IsConnected = network.IsConnected;
            }
        }