# pyFTS.common package

## Module contents

## Submodules

## pyFTS.common.Activations module

Activation functions for Time Series Classification

pyFTS.common.Activations.argmax(dist: dict) → str

pyFTS.common.Activations.scale(dist: dict) → dict

pyFTS.common.Activations.softmax(dist: dict) → dict

## pyFTS.common.Composite module

Composite Fuzzy Sets

class pyFTS.common.Composite.FuzzySet(name, superset=False, **kwargs)

  Bases: `pyFTS.common.FuzzySet.FuzzySet`

  Composite Fuzzy Set

  append(mf, parameters)

    Adds a new function to composition

    Parameters

      - mf –

      - parameters –

    Returns

  append_set(set)

    Adds a new function to composition

    Parameters

      - mf –

      - parameters –

    Returns

  membership(x)

    Calculate the membership value of a given input

    Parameters

      x – input value

    Returns

      membership value of x at this fuzzy set

  transform(x)

    Preprocess the data point for non native types

    Parameters

      x –

    Returns

      return a native type value for the structured type

## pyFTS.common.FLR module

This module implements functions for Fuzzy Logical Relationship generation

class pyFTS.common.FLR.FLR(LHS, RHS)

  Bases: `object`

  Fuzzy Logical Relationship

  Represents a temporal transition of the fuzzy set LHS on time t for the fuzzy set RHS on time t+1.

  LHS

    Left Hand Side fuzzy set

  RHS

    Right Hand Side fuzzy set

class pyFTS.common.FLR.IndexedFLR(index, LHS, RHS)

  Bases: `pyFTS.common.FLR.FLR`

  Season Indexed Fuzzy Logical Relationship

  index

    seasonal index

pyFTS.common.FLR.generate_high_order_recurrent_flr(fuzzyData)

  Create a ordered FLR set from a list of fuzzy sets with recurrence

  Parameters

    fuzzyData – ordered list of fuzzy sets

  Returns

    ordered list of FLR

pyFTS.common.FLR.generate_indexed_flrs(sets, indexer, data, transformation=None, alpha_cut=0.0)

  Create a season-indexed ordered FLR set from a list of fuzzy sets with recurrence

  Parameters

    - sets – fuzzy sets

    - indexer – seasonality indexer

    - data – original data

  Returns

    ordered list of FLR

pyFTS.common.FLR.generate_non_recurrent_flrs(fuzzyData, steps=1)

  Create a ordered FLR set from a list of fuzzy sets without recurrence

  Parameters

    fuzzyData – ordered list of fuzzy sets

  Returns

    ordered list of FLR

pyFTS.common.FLR.generate_recurrent_flrs(fuzzyData, steps=1)

  Create a ordered FLR set from a list of fuzzy sets with recurrence

  Parameters

    - fuzzyData – ordered list of fuzzy sets

    - steps – the number of steps ahead on the right side of FLR

  Returns

    ordered list of FLR

## pyFTS.common.FuzzySet module

class pyFTS.common.FuzzySet.FuzzySet(name: str, mf, parameters: list, centroid: float, alpha: float = 1.0, **kwargs)

  Bases: `object`

  Fuzzy Set

  Z

    Partition function in respect to the membership function

  alpha: float

    The alpha cut value

  centroid: float

    The fuzzy set center of mass (or midpoint)

  membership(x)

    Calculate the membership value of a given input

    Parameters

      x – input value

    Returns

      membership value of x at this fuzzy set

  mf

    The membership function

  name: str

    The fuzzy set name

  parameters: list

    The parameters of the membership function

  partition_function(uod=None, nbins=100)

    Calculate the partition function over the membership function.

    Parameters

      - uod –

      - nbins –

    Returns

  transform(x)

    Preprocess the data point for non native types

    Parameters

      x –

    Returns

      return a native type value for the structured type

  type: str

    The fuzzy set type (common, composite, nonstationary, etc)

  variable

    In multivariate time series, indicate for which variable this fuzzy set belogs

pyFTS.common.FuzzySet.check_bounds(data, fuzzy_sets, ordered_sets)

pyFTS.common.FuzzySet.check_bounds_index(data, fuzzy_sets, ordered_sets)

pyFTS.common.FuzzySet.fuzzyfy(data, partitioner, **kwargs)

  A general method for fuzzyfication.

  Parameters

    - data – input value to be fuzzyfied

    - partitioner – a trained pyFTS.partitioners.Partitioner object

    - kwargs – dict, optional arguments

    - alpha_cut – the minimal membership value to be considered on fuzzyfication (only for mode=’sets’)

    - method – the fuzzyfication method (fuzzy: all fuzzy memberships, maximum: only the maximum membership)

    - mode – the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership

  values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )

  :returns a list with the fuzzyfied values, depending on the mode

pyFTS.common.FuzzySet.fuzzyfy_instance(inst, fuzzy_sets: dict, ordered_sets: Optional[list] = None)

  Calculate the membership values for a data point given fuzzy sets

  Parameters

    - inst – data point

    - fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.

    - ordered_sets – a list with the fuzzy sets names ordered by their centroids.

  Returns

    array of membership values

pyFTS.common.FuzzySet.fuzzyfy_instances(data: list, fuzzy_sets: dict, ordered_sets=None) → list

  Calculate the membership values for a data point given fuzzy sets

  Parameters

    - inst – data point

    - fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.

    - ordered_sets – a list with the fuzzy sets names ordered by their centroids.

  Returns

    array of membership values

pyFTS.common.FuzzySet.fuzzyfy_series(data, fuzzy_sets, method='maximum', alpha_cut=0.0, ordered_sets=None)

pyFTS.common.FuzzySet.fuzzyfy_series_old(data, fuzzy_sets, method='maximum')

pyFTS.common.FuzzySet.get_fuzzysets(inst, fuzzy_sets: dict, ordered_sets: Optional[list] = None, alpha_cut: float = 0.0) → list

  Return the fuzzy sets which membership value for a inst is greater than the alpha_cut

  Parameters

    - inst – data point

    - fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.

    - ordered_sets – a list with the fuzzy sets names ordered by their centroids.

    - alpha_cut – Minimal membership to be considered on fuzzyfication process

  Returns

    array of membership values

pyFTS.common.FuzzySet.get_maximum_membership_fuzzyset(inst, fuzzy_sets, ordered_sets=None) → pyFTS.common.FuzzySet.FuzzySet

  Fuzzify a data point, returning the fuzzy set with maximum membership value

  Parameters

    - inst – data point

    - fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.

    - ordered_sets – a list with the fuzzy sets names ordered by their centroids.

  Returns

    fuzzy set with maximum membership

pyFTS.common.FuzzySet.get_maximum_membership_fuzzyset_index(inst, fuzzy_sets) → int

  Fuzzify a data point, returning the fuzzy set with maximum membership value

  Parameters

    - inst – data point

    - fuzzy_sets – dict of fuzzy sets

  Returns

    fuzzy set with maximum membership

pyFTS.common.FuzzySet.grant_bounds(data, fuzzy_sets, ordered_sets)

pyFTS.common.FuzzySet.set_ordered(fuzzy_sets)

  Order a fuzzy set list by their centroids

  Parameters

    fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.

  Returns

    a list with the fuzzy sets names ordered by their centroids.

## pyFTS.common.Membership module

Membership functions for Fuzzy Sets

pyFTS.common.Membership.bellmf(x, parameters)

  Bell shaped membership function

  Parameters

    - x –

    - parameters –

  Returns

pyFTS.common.Membership.gaussmf(x, parameters)

  Gaussian fuzzy membership function

  Parameters

    - x – data point

    - parameters – a list with 2 real values (mean and variance)

  Returns

    the membership value of x given the parameters

pyFTS.common.Membership.sigmf(x, parameters)

  Sigmoid / Logistic membership function

  Parameters

    - x –

    - parameters – an list with 2 real values (smoothness and midpoint)

  :return

pyFTS.common.Membership.singleton(x, parameters)

  Singleton membership function, a single value fuzzy function

  Parameters

    - x –

    - parameters – a list with one real value

  :returns

pyFTS.common.Membership.trapmf(x, parameters)

  Trapezoidal fuzzy membership function

  Parameters

    - x – data point

    - parameters – a list with 4 real values

  Returns

    the membership value of x given the parameters

pyFTS.common.Membership.trimf(x, parameters)

  Triangular fuzzy membership function

  Parameters

    - x – data point

    - parameters – a list with 3 real values

  Returns

    the membership value of x given the parameters

## pyFTS.common.SortedCollection module

class pyFTS.common.SortedCollection.SortedCollection(iterable=(), key=None)

  Bases: `object`

  Sequence sorted by a key function.

  SortedCollection() is much easier to work with than using bisect() directly. It supports key functions like those use in sorted(), min(), and max(). The result of the key function call is saved so that keys can be searched efficiently.

  Instead of returning an insertion-point which can be hard to interpret, the five find-methods return a specific item in the sequence. They can scan for exact matches, the last item less-than-or-equal to a key, or the first item greater-than-or-equal to a key.

  Once found, an item’s ordinal position can be located with the index() method. New items can be added with the insert() and insert_right() methods. Old items can be deleted with the remove() method.

  The usual sequence methods are provided to support indexing, slicing, length lookup, clearing, copying, forward and reverse iteration, contains checking, item counts, item removal, and a nice looking repr.

  Finding and indexing are O(log n) operations while iteration and insertion are O(n). The initial sort is O(n log n).

  The key function is stored in the ‘key’ attibute for easy introspection or so that you can assign a new key function (triggering an automatic re-sort).

  In short, the class was designed to handle all of the common use cases for bisect but with a simpler API and support for key functions.

      >>> from pprint import pprint
      >>> from operator import itemgetter

      >>> s = SortedCollection(key=itemgetter(2))
      >>> for record in [
      ...         ('roger', 'young', 30),
      ...         ('angela', 'jones', 28),
      ...         ('bill', 'smith', 22),
      ...         ('david', 'thomas', 32)]:
      ...     s.insert(record)

      >>> pprint(list(s))         # show records sorted by age
      [('bill', 'smith', 22),
       ('angela', 'jones', 28),
       ('roger', 'young', 30),
       ('david', 'thomas', 32)]

      >>> s.find_le(29)           # find oldest person aged 29 or younger
      ('angela', 'jones', 28)
      >>> s.find_lt(28)           # find oldest person under 28
      ('bill', 'smith', 22)
      >>> s.find_gt(28)           # find youngest person over 28
      ('roger', 'young', 30)

      >>> r = s.find_ge(32)       # find youngest person aged 32 or older
      >>> s.index(r)              # get the index of their record
      3
      >>> s[3]                    # fetch the record at that index
      ('david', 'thomas', 32)

      >>> s.key = itemgetter(0)   # now sort by first name
      >>> pprint(list(s))
      [('angela', 'jones', 28),
       ('bill', 'smith', 22),
       ('david', 'thomas', 32),
       ('roger', 'young', 30)]

  around(k)
  between(ge, le)
  clear()
  copy()
  count(item)

    Return number of occurrences of item

  find(k)

    Return first item with a key == k. Raise ValueError if not found.

  find_ge(k)

    Return first item with a key >= equal to k. Raise ValueError if not found

  find_gt(k)

    Return first item with a key > k. Raise ValueError if not found

  find_le(k)

    Return last item with a key <= k. Raise ValueError if not found.

  find_lt(k)

    Return last item with a key < k. Raise ValueError if not found.

  index(item)

    Find the position of an item. Raise ValueError if not found.

  insert(item)

    Insert a new item. If equal keys are found, add to the left

  insert_right(item)

    Insert a new item. If equal keys are found, add to the right

  inside(ge, le)
  property key

    key function

  remove(item)

    Remove first occurence of item. Raise ValueError if not found

## pyFTS.common.Util module

## pyFTS.common.flrg module

class pyFTS.common.flrg.FLRG(order, **kwargs)

  Bases: `object`

  Fuzzy Logical Relationship Group

  Group a set of FLR’s with the same LHS. Represents the temporal patterns for time t+1 (the RHS fuzzy sets) when the LHS pattern is identified on time t.

  LHS

    Left Hand Side of the rule

  RHS

    Right Hand Side of the rule

  append_rhs(set, **kwargs)
  get_key()

    Returns a unique identifier for this FLRG

  get_lower(sets)

    Returns the lower bound value for the RHS fuzzy sets

    Parameters

      sets – fuzzy sets

    Returns

      lower bound value

  get_membership(data, sets)

    Returns the membership value of the FLRG for the input data

    Parameters

      - data – input data

      - sets – fuzzy sets

    Returns

      the membership value

  get_midpoint(sets)

    Returns the midpoint value for the RHS fuzzy sets

    Parameters

      sets – fuzzy sets

    Returns

      the midpoint value

  get_midpoints(sets)
  get_upper(sets)

    Returns the upper bound value for the RHS fuzzy sets

    Parameters

      sets – fuzzy sets

    Returns

      upper bound value

  order

    Number of lags on LHS

  reset_calculated_values()

## pyFTS.common.fts module

## pyFTS.common.tree module

Tree data structure

class pyFTS.common.tree.FLRGTree

  Bases: `object`

  Represents a FLRG set with a tree structure

class pyFTS.common.tree.FLRGTreeNode(value)

  Bases: `object`

  Tree node for

  appendChild(child)
  getChildren()
  getStr(k)
  paths(acc=[])

pyFTS.common.tree.build_tree_without_order(node, lags, level)

pyFTS.common.tree.flat(dados)