dqn | Basic DQN implementation | Machine Learning library

 by   sherjilozair Python Version: Current License: MIT

kandi X-RAY | dqn Summary

kandi X-RAY | dqn Summary

dqn is a Python library typically used in Artificial Intelligence, Machine Learning, Deep Learning applications. dqn has no bugs, it has no vulnerabilities, it has a Permissive License and it has high support. However dqn build file is not available. You can download it from GitHub.

This is a very basic DQN (with experience replay) implementation, which uses OpenAI's gym environment and Keras/Theano neural networks.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              dqn has a highly active ecosystem.
              It has 199 star(s) with 68 fork(s). There are 12 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 10 open issues and 0 have been closed. On average issues are closed in 1532 days. There are 2 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of dqn is current.

            kandi-Quality Quality

              dqn has 0 bugs and 0 code smells.

            kandi-Security Security

              dqn has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              dqn code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              dqn is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              dqn releases are not available. You will need to build from source code and install.
              dqn has no build file. You will be need to create the build yourself to build the component from source.
              dqn saves you 117 person hours of effort in developing the same functionality from scratch.
              It has 296 lines of code, 23 functions and 3 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed dqn and discovered the below as its top functions. This is intended to give you an instant insight into dqn implemented functionality, and help decide if they suit your requirements.
            • Reset the environment
            • Observation time series
            • Wrap a qn Environment
            • Create q - network
            • Sample from replay memory
            • Epsilon greedy algorithm
            • Forward an action
            • Get the name of a job
            Get all kandi verified functions for this library.

            dqn Key Features

            No Key Features are available at this moment for dqn.

            dqn Examples and Code Snippets

            Runs a DQN experiment .
            pythondot img1Lines of Code : 41dot img1no licencesLicense : No License
            copy iconCopy
            def main():
              env = gym.make('CartPole-v0')
              gamma = 0.99
              copy_period = 50
            
              D = len(env.observation_space.sample())
              K = env.action_space.n
              sizes = [200,200]
              model = DQN(D, K, sizes, gamma)
              tmodel = DQN(D, K, sizes, gamma)
              init = tf.glo  

            Community Discussions

            QUESTION

            Custom environment using TFagents
            Asked 2021-Jun-02 at 22:36

            I am trying to learn a custom environment using the TFAgents package. I am following the Hands-on-ML book (Code in colab see cell 129). My aim is to use DQN agent on a custom-written grid world environment.

            Grid-World environment:

            ...

            ANSWER

            Answered 2021-Jun-02 at 22:36

            You cannot use TensorSpec with PyEnvironment class objects, this is why your attempted solution does not work. A simple fix should be to use the original code

            Source https://stackoverflow.com/questions/65743558

            QUESTION

            DQN Pytorch Loss keeps increasing
            Asked 2021-Jun-02 at 17:39

            I am implementing simple DQN algorithm using pytorch, to solve the CartPole environment from gym. I have been debugging for a while now, and I cant figure out why the model is not learning.

            Observations:

            • using SmoothL1Loss performs worse than MSEloss, but loss increases for both
            • smaller LR in Adam does not work, I have tested using 0.0001, 0.00025, 0.0005 and default

            Notes:

            • I have debugged various parts of the algorithm individually, and can say with good confidence that the issue is in the learn function. I am wondering if this bug is due to me misunderstanding detach in pytorch or some other framework mistake im making.
            • I am trying to stick as close to the original paper as possible (linked above)

            References:

            ...

            ANSWER

            Answered 2021-Jun-02 at 17:39

            The main problem I think is the discount factor, gamma. You are setting it to 1.0, which mean that you are giving the same weight to the future rewards as the current one. Usually in reinforcement learning we care more about the immediate reward than the future, so gamma should always be less than 1.

            Just to give it a try I set gamma = 0.99 and run your code:

            Source https://stackoverflow.com/questions/67789148

            QUESTION

            Resize a state of a gym environment composed by 4 frames (atari environment)
            Asked 2021-May-24 at 22:09

            I'm developing an Autonomous Agent based on DQN. I am using the gym library to make the environments that I want to test, but I'm stuck in processing the frames of the state. The state that the gym environment returns, using the FrameStack wrapper, has the following observation space:

            ...

            ANSWER

            Answered 2021-May-24 at 22:09

            Fixed! I was just doing it in the wrong way.

            Source https://stackoverflow.com/questions/67674324

            QUESTION

            Mean squared logarithmic error using pytorch
            Asked 2021-May-22 at 09:44

            hello I'm new with PyTorch and i would like to use Mean squared logarithmic error as a loss function in my neural network for training my DQN agent but i can't find the MSLE in the nn.functional in PyTorch what the best way to implement it ?

            ...

            ANSWER

            Answered 2021-May-22 at 09:44

            well is not hard to do it the MSLE equation as the photo below shows

            now, as some user on the PyTorch form suggested

            you can be added as a class like this

            Source https://stackoverflow.com/questions/67648033

            QUESTION

            index 1 is out of bounds for dimension 0 with size 1
            Asked 2021-Apr-23 at 20:14

            I am starting to learn about DQN, and I am trying to solve the FrozenLake-v0 problem from scratch by my self and using Pytorch so I will put the whole code since it's connected.

            ...

            ANSWER

            Answered 2021-Apr-23 at 20:14

            since you are calling a tensor that contains a matrix, you need to specify which indices your calling in your case just adding [0] to the forward statement will solve the problem and in the [actions], replace it with [actions.item()]

            Source https://stackoverflow.com/questions/67185851

            QUESTION

            ValueError: Error when checking input: expected dense_input to have 2 dimensions, but got array with shape (1, 1, 15)
            Asked 2021-Apr-08 at 12:00

            I am trying to make a custom Gym Environment so that I can use it in a Keras Network. But there is a problem that is happening to me when I try to fit de neural network.

            ...

            ANSWER

            Answered 2021-Apr-08 at 12:00

            The input shape should be (1,15) in your case. This is because the actual input shape is increased by an additional dimension to what you specify in shape as keras processes inputs in batches, with the batch size being the first parameter.

            The error message is telling you that inputs of shape (1,1,15) are being passed to the model ( i.e. batch of 1, and input shape (1,15), so ndims=3), but you only have ndims=2. Despite only passing (15,) as the input shape, notice that ndims = 2. This is because Keras is adding an additional dimension for the batch.

            So to fix, set shape=(1,15) which will then be processed as (1,1,15) which is what Keras expects.

            Source https://stackoverflow.com/questions/67000544

            QUESTION

            Convert a 2D array with first rows a headers to object JavaScript
            Asked 2021-Apr-07 at 08:59

            I have an array that has first rows as header:

            ...

            ANSWER

            Answered 2021-Apr-07 at 08:45

            Destructure the array, and take the keys (1st item), and the values (the rest). Map the values array, and then map each sub-array of values, take the respective key by the value, and return a pair of [key, value]. Convert the array pairs to an object with Object.fromEntries():

            Source https://stackoverflow.com/questions/66982431

            QUESTION

            How to fix AttributeError: 'tuple' object has no attribute 'rank' creating a DqnAgent with Tensorflow?
            Asked 2021-Feb-27 at 15:49

            I'm trying to create a DqnAgent using an own environment. But i'm receiving the following error

            AttributeError: 'tuple' object has no attribute 'rank' In call to configurable 'DqnAgent' ()

            Below is the code for my environment myEnv

            ...

            ANSWER

            Answered 2021-Feb-27 at 15:49

            The DqnAgent expects a TFPyEnvironment but you're implementing the environment as an PyEnvironment.

            To fix this error you should convert the environment into the TensorFlow implementation before you are creating the agent.

            You can do it this way:

            Source https://stackoverflow.com/questions/66397282

            QUESTION

            How to build a DQN that outputs 1 discrete and 1 continuous value as a pair?
            Asked 2021-Feb-26 at 19:02

            I am building a DQN for an Open Gym environment. My observation space is only 1 discrete value but my actions are:

            ...

            ANSWER

            Answered 2021-Feb-26 at 19:02

            As you've already noted in your comment, DQN is not compatible with continuous action spaces because of how DQN works; argmax of "a" for Q(s,a) - It's impossible to check Q(s,a) for all a when a is continuous.

            Having said that, when applying this to Policy Gradient methods (which are compatible with continuous action spaces) you will run into the same issue in your question because with policy gradient you need to provide a probability for each action that you take. Something like this could work:

            • Actor (a neural net in this case) gives 3 outputs.
            • First 2 outputs are probabilities of each discrete value.
            • 3rd output is your continuous value.

            Take the softmax of the first two outputs which gives you your discrete value and then take the third output which is continuous and this will give you your action. You then need to derive the probability of that action which is given by the combined probability of all of your outputs.

            Source https://stackoverflow.com/questions/66326130

            QUESTION

            Reinforcement learning DQN environment structure
            Asked 2021-Feb-03 at 14:59

            I am wondering how best to feed back the changes my DQN agent makes on its environment, back to itself.

            I have a battery model whereby an agent can observe a time-series forecast of 17 steps, and 5 features. It then makes a decision on whether to charge or discharge.

            I want to includes its current state of charge (empty, half full, full etc) in its observation space (i.e. somewhere within the (17,5) dataframes I am feeding it).

            I have several options, I can either set a whole column to the state of charge value, a whole row, or I can flatten the whole dataframe and set one value to the state of charge value.

            Is any of these unwise? It seem a little rudimentary to me to set a whole columns to a single value, but should it actually impact performance? I am wary of flattening the whole thing as I plan to use either conv or lstm layers (although the current model is just dense layers).

            ...

            ANSWER

            Answered 2021-Feb-03 at 14:59

            You would not want to add in unnecessary features which are repetitive in the state representation as it might hamper your RL agent convergence later when you would want to scale your model to larger input sizes(if that is in your plan).

            Also, the decision of how much of information you would want to give in the state representation is mostly experimental. The best way to start would be to just give in a single value as the battery state. But if the model does not converge, then maybe you could try out the other options you have mentioned in your question.

            Source https://stackoverflow.com/questions/66008062

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install dqn

            You can download it from GitHub.
            You can use dqn like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/sherjilozair/dqn.git

          • CLI

            gh repo clone sherjilozair/dqn

          • sshUrl

            git@github.com:sherjilozair/dqn.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link