Example #1
0
  def AddData(self, data_list):
    if validations.isList(data_list):
      for idx in data_list:

        if validations.isList(idx):
          if self._coords != [] and len(idx) <> self._dim:
            pass
            #Error - coord_set not same size
          elif not self._coords:
            self._dim = len(idx)
            self._coords = [[] for i in xrange(len(idx))]


          [self._coords[i].append(idx[i]) for i in xrange(len(idx))]
Example #2
0
  def NormalizeDataset_RL(self, num_list, sliding=True, forced_high = None, forced_low = None):
    """Normalize data in RollingList object.

    Sliding:
      True - High's/Low's re-defined during iteration of list.
      False - High/Low defined once in the context of the entire list.
    """

    normalized_list = []
    if validations.isList(num_list) and validations.isNumeric(num_list):
      if sliding:
        low, high = None, None
        for val in num_list:
          low = val if val < low or low is None else low
          high = val if val > high or high is None else high

          low = forced_low if forced_low is not None else low
          high = forced_high if forced_high is not None else high

          normalized_list.append(self.Normalize(low, high, val))
      else:
        low = np.min(num_list) if forced_low is not None else forced_low
        high = np.max(num_list) if forced_high is not None else forced_high
        for val in num_list:
          normalized_list.append(self.Normalize(low, high, val))

    return normalized_list
Example #3
0
def ReStDev(new_data, old_stdev, old_mean, old_periods, error_obj=None):
    """Calculate St. Deviation using existing stdev/mean/period values.

    Without having to calculate ENTIRE raw_data. (faster than StDev)
    """
    err_is_object = not isinstance(error_obj, type(None))
    def Calc(val, old_stdev, old_mean, old_periods):
      sumsq = SumSq(old_stdev, old_mean, old_periods)
      new_periods = old_periods + 1
      new_mean = ((old_mean * old_periods) + val) / new_periods
      new_sumsq = sumsq + pow(val, 2)
      new_stdev = StDevSumSq(new_sumsq, new_mean, new_periods)
      return new_stdev, new_mean, new_periods

    if validations.isNumeric(new_data):
      if validations.isList(new_data):
        for data in new_data:
          old_stdev, old_mean, old_periods = Calc(data, old_stdev, old_mean, old_periods)
        new_stdev, new_mean, new_periods = old_stdev, old_mean, old_periods
      else:
        new_stdev, new_mean, new_periods = Calc(new_data, old_stdev, old_mean, old_periods)
    elif err_is_object:
      error_obj.Add(STDEV_ERRORKEY, 'Input(s) must be numeric.')
      return error_obj
    else:
      return False

    return new_stdev, new_periods, new_mean
Example #4
0
def StDev(data_array, error_obj=None):
  """Calculate Standard Deviation from array of numeric datapoints."""

  #Validate array.
  sum_variance = 0.0
  validated = True
  err_is_object = not isinstance(error_obj, type(None))
  if validations.isList(data_array):
    if not validations.isNumeric(data_array):
      validated = False
      if err_is_object:
          error_obj.Add(STDEV_ERRORKEY, 'Array contents must be numeric.')
  elif err_is_object:
    error_obj.Add(STDEV_ERRORKEY, 'Input must be a list or tuple.')
    validated = False
  else:
    validated = False

  # Calculate Standard Deviation.
  if validated:
    periods = len(data_array)
    if periods > 1:
      mean = np.mean(data_array)
      for val in data_array:
        sum_variance += pow(val - mean, 2)
      stdev = pow(pow(periods-1, -1) * sum_variance, .5)
    else:
      mean = float(data_array[0])
      stdev = 0.0

    return stdev, periods, mean
  elif error_obj:
    return error_obj
  else:
    return False
 def Add(self, val):
   if validations.isNumeric(val):
     if validations.isList(val):
       for x in val:
         self.Add(x)
     else:
       self.data.add(val)
       self._calcAverages()
Example #6
0
 def Add(self, val):
   if self._only_numerical and validations.isNumeric(val):
     if validations.isList(val):
       for x in val:
         self._Add(x)
     else:
       self._Add(val)
   elif not self._only_numerical:
     self._Add(val)
Example #7
0
  def Add(self, data):
    """Receives singular value or list/tuple of values to add to raw_data."""

    if validations.isList(data) and validations.isNumeric(data):
      for x in data:
        self._Add(x)
    elif validations.isNumeric(data):
      self._Add(data)
    else:
      self.error.Add(self.base_error_key, ERRORMSG_RA_ADDFAIL.format(data))
 def Add(self, val):
   if validations.isNumeric(val) and self._only_numerical_values:
     if validations.isList(val):
       for x in val:
         self.Add(x)
     else:
       self._rollinglist.append(val)
       if len(self) > self.limit:
         self.Delete()
   elif not self._only_numerical_values:
     self._rollinglist.append(val)
Example #9
0
def numberFormat_list(val, dec_places=None, error=(None, None)):
  if validations.isList(val) and validations.isNumeric(val):
    return [x for numberFormat(x, dec_places, error)]