Extractors Tutorial

Introduction

This tutorial is a guide of how you can create your custom feature extraction routine and add this extractor to feets.

Fundamentals

  • The feature extraction as modeled as a class.
  • The class must inerith from feets.Extractor
  • The extractor class must has at least three elements
    1. data: list with at least one valid feets data (time, magnitude, error, magnitude2, aligned_time, aligned_magnitude, aligned_magnitude2, aligned_error or aligned_error2)
    2. features: list with the name of the features that this extractor generates.
    3. fit: a method with the same parameters defined in the data list. fit() must return a dictionary with keys equals to the features list.

Example 1: MaxMagMinTime extractor

Let’s say we need to create a feature extractor called MaxMagMinTime that must return 2 features:

  1. magmax: The maximun magnitude
  2. mintime: the minimun time
In [21]:
import feets

class MaxMagMinTime(feets.Extractor):  # must inherit from Extractor

    data = ['magnitude', 'time']  # Which data is needed
                                  # to calculate this feature

    features = ["magmax", "mintime"] # The names of the expected
                                     # feature

    # The values of data are the params
    def fit(self, magnitude, time):
        # The return value must be a dict with the same values
        # defined in  features
        return {"magmax": magnitude.max(), "mintime": time.min()}

Finally to make the extractor available for the FeaturSpace class, you need to register it with the command:

In [24]:
feets.register_extractor(MaxMagMinTime)
Out[24]:
__main__.MaxMagMinTime

Now the extractor are available as any other provided in feets:

In [29]:
# let's create the feature-space
fs = feets.FeatureSpace(only=["magmax", "mintime"])
fs
Out[29]:
<FeatureSpace: MaxMagMinTime()>
In [30]:
# extract the features
fs.extract(time=[1,2,3], magnitude=[100, 200, 300])
Out[30]:
(array([u'magmax', u'mintime'],
       dtype='<U7'), array([300,   1]))
In [ ]: