Exemple #1
0
    private void StoreInformation(float[] current_state, float[] next_state, int action, float reward)
    {
        network_memory[memory_index] = new MemoryStructure();
        network_memory[memory_index].current_state = current_state;
        network_memory[memory_index].next_state    = next_state;
        network_memory[memory_index].picked_action = action;
        network_memory[memory_index].reward        = reward;
        memory_index++;

        if (memory_index == memory_size)
        {
            memory_index = 0;
        }
    }
Exemple #2
0
        static int CalculateEditDistance(string x, string y, int substitutionCost, MemoryStructure memory)
        {
            if (string.IsNullOrEmpty(x))
            {
                return(string.IsNullOrEmpty(y) ? 0 : y.Length);
            }

            var m = x.Length + 1;
            var n = y.Length + 1;

            // Map empties to each other

            for (int i = 0; i < m; i++)
            {
                memory[i, 0] = i;
            }

            for (int i = 0; i < n; i++)
            {
                memory[0, i] = i;
            }

            for (int i = 1; i < m; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    if (x[i - 1] == y[j - 1])
                    {
                        // No cost, letters are the same

                        memory[i, j] = memory[i - 1, j - 1];
                    }
                    else
                    {
                        var delete       = memory[i - 1, j] + 1;
                        var insert       = memory[i, j - 1] + 1;
                        var substitution = memory[i - 1, j - 1] + substitutionCost;

                        memory[i, j] = Math.Min(delete, Math.Min(insert, substitution));
                    }
                }
            }

            return(memory[m - 1, n - 1]);
        }