<commit_before># Copyright 2017 Battelle Energy Alliance, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
  AutoRegressive Moving Average time series analysis
"""
import copy
import collections
import numpy as np
import scipy as sp

import Decorators

from utils import InputData, InputTypes, randomUtils, xmlUtils, mathUtils, importerUtils
statsmodels = importerUtils.importModuleLazy('statsmodels', globals())

import Distributions
from .TimeSeriesAnalyzer import TimeSeriesAnalyzer


# utility methods
class ARMA(TimeSeriesAnalyzer):
  r"""
    AutoRegressive Moving Average time series analyzer algorithm
  """
  # class attribute
  ## define the clusterable features for this trainer.
  _features = [] # TODO

  @classmethod
  def getInputSpecification(cls):
    """
      Method to get a reference to a class that specifies the input data for
      class cls.
      @ Out, inputSpecification, InputData.ParameterInput, class to use for
        specifying input of cls.
    """
    specs = super(ARMA, cls).getInputSpecification()
    specs.name = 'arma' # NOTE lowercase because ARMA already has Fourier and no way to resolve right now
    specs.description = r"""TimeSeriesAnalysis algorithm for determining the stochastic
                            characteristics of signal with time-invariant variance"""
    specs.addParam('reduce_memory', param_type=InputTypes.BoolType, required=False,
                   descr=r"""activates a lower memory usage ARMA training. This does tend to result
                   in a slightly slower training time, at the benefit of lower memory usage. For
                   example, in one 1000-length history test, low memory reduced memory usage by 2.3
                   MiB, but increased training time by 0.4 seconds. No change in results has been
                   observed switching between modes. Note that the ARMA must be
                   retrained to change this property; it cannot be applied to serialized ARMAs.
                   \default{False}""")
    specs.addSub(InputData.parameterInputFactory('SignalLag', contentType=InputTypes.FloatType,
                 descr=r"""the number of terms in the AutoRegressive term to retain in the
                           regression; "P" in literature."""))
    specs.addSub(InputData.parameterInputFactory('NoiseLag', contentType=InputTypes.FloatType,
                 descr=r"""the number of terms in the Moving Average term to retain in the
                           regression; "Q" in literature."""))
    return specs

  #
  # API Methods
  #
  def __init__(self, *args, **kwargs):
    """
      A constructor that will appropriately intialize a supervised learning object
      @ In, args, list, an arbitrary list of positional values
      @ In, kwargs, dict, an arbitrary dictionary of keywords and values
      @ Out, None
    """
    # general infrastructure
    TimeSeriesAnalyzer.__init__(self, *args, **kwargs)
    self._minBins = 20 # this feels arbitrary; used for empirical distr. of data

  def handleInput(self, spec):
    """<commit_msg>improved verbiage<commit_after># Copyright 2017 Battelle Energy Alliance, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
  AutoRegressive Moving Average time series analysis
"""
import copy
import collections
import numpy as np
import scipy as sp

import Decorators

from utils import InputData, InputTypes, randomUtils, xmlUtils, mathUtils, importerUtils
statsmodels = importerUtils.importModuleLazy('statsmodels', globals())

import Distributions
from .TimeSeriesAnalyzer import TimeSeriesAnalyzer


# utility methods
class ARMA(TimeSeriesAnalyzer):
  r"""
    AutoRegressive Moving Average time series analyzer algorithm
  """
  # class attribute
  ## define the clusterable features for this trainer.
  _features = [] # TODO

  @classmethod
  def getInputSpecification(cls):
    """
      Method to get a reference to a class that specifies the input data for
      class cls.
      @ Out, inputSpecification, InputData.ParameterInput, class to use for
        specifying input of cls.
    """
    specs = super(ARMA, cls).getInputSpecification()
    specs.name = 'arma' # NOTE lowercase because ARMA already has Fourier and no way to resolve right now
    specs.description = r"""TimeSeriesAnalysis algorithm for determining the stochastic
                        characteristics of signal with time-invariant variance"""
    specs.addParam('reduce_memory', param_type=InputTypes.BoolType, required=False,
                   descr=r"""activates a lower memory usage ARMA training. This does tend to result
                         in a slightly slower training time, at the benefit of lower memory usage. For
                         example, in one 1000-length history test, low memory reduced memory usage by 2.3
                         MiB, but increased training time by 0.4 seconds. No change in results has been
                         observed switching between modes. Note that the ARMA must be
                         retrained to change this property; it cannot be applied to serialized ARMAs.
                         \default{False}""")
    specs.addSub(InputData.parameterInputFactory('SignalLag', contentType=InputTypes.FloatType,
                 descr=r"""the number of terms in the AutoRegressive term to retain in the
                       regression; typically represented as $P$ in literature."""))
    specs.addSub(InputData.parameterInputFactory('NoiseLag', contentType=InputTypes.FloatType,
                 descr=r"""the number of terms in the Moving Average term to retain in the
                       regression; typically represented as $Q$ in literature."""))
    return specs

  #
  # API Methods
  #
  def __init__(self, *args, **kwargs):
    """
      A constructor that will appropriately intialize a supervised learning object
      @ In, args, list, an arbitrary list of positional values
      @ In, kwargs, dict, an arbitrary dictionary of keywords and values
      @ Out, None
    """
    # general infrastructure
    TimeSeriesAnalyzer.__init__(self, *args, **kwargs)
    self._minBins = 20 # this feels arbitrary; used for empirical distr. of data

  def handleInput(self, spec):
    """
{'fraction_non_alphanumeric': 0.06833333333333333, 'fraction_numerical': 0.005, 'mean_word_length': 3.09613196814562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7110606', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1733, 'n_words': 773}