Ejemplo n.º 1
0
    public MyMatrix[] GetActivisions(float[] input)
    {
        MyMatrix[] activisions = new MyMatrix[m_layerCount];
        MyMatrix   activision  = new MyMatrix(input);

        activisions[0] = activision;

        for (int layerIndex = 0; layerIndex < m_layerCount - 1; layerIndex++)
        {
            // compensate weights scale for dropout
            MyMatrix weightsCompensated = null;
            if (m_dropoutKeepRate < 1)
            {
                weightsCompensated = new MyMatrix(m_weights[layerIndex], true);
                weightsCompensated.MultiplyByFactor(m_dropoutKeepRate);
            }
            else
            {
                weightsCompensated = m_weights[layerIndex];
            }

            activision = GetActivisionFunction(MyMatrix.AddMatrix(MyMatrix.Dot(weightsCompensated, activision), m_biases[layerIndex]), layerIndex);
            activisions[layerIndex + 1] = activision;
        }

        return(activisions);
    }
Ejemplo n.º 2
0
    private void FillActivisions(float[] input)
    {
        m_activisionValues[0] = new MyMatrix(input);
        for (int layerIndex = 0; layerIndex < m_layerCount - 1; layerIndex++)
        {
            m_rawValues[layerIndex]            = MyMatrix.AddMatrix(MyMatrix.Dot(m_weights[layerIndex], m_activisionValues[layerIndex]), m_biases[layerIndex]);
            m_activisionValues[layerIndex + 1] = GetActivisionFunction(m_rawValues[layerIndex], layerIndex);

            if (m_dropoutKeepRate < 1 && layerIndex != m_layerCount - 2)
            {
                if (m_dropoutKeepRate <= 0 || m_dropoutKeepRate > 1)
                {
                    Debug.Log("Warning: m_regularizationKeepRate was corrupt! (" + m_dropoutKeepRate + ")");
                }

                MyMatrix regularizationMask = new MyMatrix(m_activisionValues[layerIndex + 1].m_rowCountY, 1);// new float[m_layerLengths[layerIndex] + 1];
                for (int i = 0; i < regularizationMask.m_rowCountY; i++)
                {
                    float random = 0;
                    if (m_initDropoutSeed >= 0)
                    {
                        random = Utility.GetRandomWithSeed(0f, 1f, m_currentDropoutSeed++);
                    }
                    else
                    {
                        Random.Range(0f, 1f);
                    }
                    if (random < m_dropoutKeepRate)
                    {
                        regularizationMask.m_data[i][0] = 1;
                    }
                }

                m_rawValues[layerIndex]            = MyMatrix.MultiplyElementWise(m_rawValues[layerIndex], regularizationMask);
                m_activisionValues[layerIndex + 1] = MyMatrix.MultiplyElementWise(m_activisionValues[layerIndex + 1], regularizationMask);
            }
        }
    }