credit.replay_buffer
====================

.. py:module:: credit.replay_buffer


Classes
-------

.. autoapisummary::

   credit.replay_buffer.TOADataLoader
   credit.replay_buffer.WeightedRMSE
   credit.replay_buffer.ReplayBuffer
   credit.replay_buffer.Trainer


Functions
---------

.. autoapisummary::

   credit.replay_buffer.cleanup
   credit.replay_buffer.cycle
   credit.replay_buffer.accum_log


Module Contents
---------------

.. py:function:: cleanup()

.. py:function:: cycle(dl)

.. py:function:: accum_log(log, new_logs)

.. py:class:: TOADataLoader(conf)

   .. py:attribute:: TOA


   .. py:attribute:: times_b
      :value: None



   .. py:method:: __call__(datetime_input)


.. py:class:: WeightedRMSE(conf)

   Bases: :py:obj:`torch.nn.Module`


   Base class for all neural network modules.

   Your models should also subclass this class.

   Modules can also contain other Modules, allowing them to be nested in
   a tree structure. You can assign the submodules as regular attributes::

       import torch.nn as nn
       import torch.nn.functional as F


       class Model(nn.Module):
           def __init__(self) -> None:
               super().__init__()
               self.conv1 = nn.Conv2d(1, 20, 5)
               self.conv2 = nn.Conv2d(20, 20, 5)

           def forward(self, x):
               x = F.relu(self.conv1(x))
               return F.relu(self.conv2(x))

   Submodules assigned in this way will be registered, and will also have their
   parameters converted when you call :meth:`to`, etc.

   .. note::
       As per the example above, an ``__init__()`` call to the parent class
       must be made before assignment on the child.

   :ivar training: Boolean represents whether this module is in training or
                   evaluation mode.
   :vartype training: bool


   .. py:attribute:: lat_weights
      :value: None



   .. py:method:: forward(predictions, targets)


.. py:class:: ReplayBuffer(conf, buffer_size=32, device='cpu', dtype=np.float32, rank=0)

   .. py:attribute:: buffer_size
      :value: 32



   .. py:attribute:: ptr
      :value: 0



   .. py:attribute:: size
      :value: 0



   .. py:attribute:: dtype


   .. py:attribute:: device
      :value: 'cpu'



   .. py:attribute:: rank
      :value: 0



   .. py:attribute:: input_shape


   .. py:attribute:: forecast_hour


   .. py:attribute:: index


   .. py:attribute:: q_values


   .. py:attribute:: rmse_scores


   .. py:attribute:: dataset


   .. py:attribute:: numpy_dir


   .. py:attribute:: metric_fn


   .. py:method:: add(x, lookup_key)

      Add new experience to the buffer.



   .. py:method:: sample(batch_size, epsilon=0.2)

      Sample a batch of experiences from the buffer, increment forecast_hour, and update x with new predictions.



   .. py:method:: update_q_values(indices, y_predict, y_truth)


   .. py:method:: update(indices, new_x, new_lookup_key)

      Update existing data in the buffer.



   .. py:method:: update_with_predictions(model, sample_size, epsilon=0.2)

      Use stored predictions as inputs for future predictions.



   .. py:method:: concat_and_reshape(x1, x2)


   .. py:method:: load_inputs(idx)


   .. py:method:: populate()

      Populate the buffer with random data points from the dataset.



   .. py:method:: save()

      Save the forecast hours, index arrays, pointer, size, Q-values, and RMSE scores to disk.



   .. py:method:: reload()

      Reload the buffer from saved numpy files.



.. py:class:: Trainer(model: torch.nn.Module, rank: int, conf: Dict[str, Any])

   Bases: :py:obj:`credit.trainers.base_trainer.BaseTrainer`


   Helper class that provides a standard way to create an ABC using
   inheritance.


   .. py:method:: train_one_epoch(epoch, conf, trainloader, optimizer, criterion, scaler, scheduler, metrics)


