# feyn.filters

```
A collection of filters to use with QGraphs.
A QGraph is a partially ordered infinite list of graphs with some constraints on the actual structure of the graphs.
One way to tune these constraints is to filter the QGraph with one or more filters from this package.
# Consider only graphs that are two deep and involve the "x" register.
> qgraph = qgraph.filter(feyn.filters.Depth(2))
> qgraph = qgraph.filter(feyn.filters.Contains("x"))
> qgraph.fit(data)
Notice that QGraph filters can be chained, and will be and'ed together.
This module has a useful collection of filters. It's also possible to define custom filters by deriving from the QGraphFilter baseclass
```

*class* Contains

```
def __init__(
regname: Union[str, List[str]]
) -> Contains
```

```
Use this class to obtain a QGraph that only contain graphs involving certain registers.
# Consider only graphs that are two deep and involve the "x" register
> qgraph = qgraph.filter(feyn.filters.Depth(2))
> qgrpah = qgraph.filter(feyn.filters.Contains("x"))
> qgraph.fit(data)
Notice that this example demonstrates searching for all graphs that involve 'x' plus zero or one of the other input features.
Using this chained filter approach it's possible to guide the search for non-linear and dynamic correlations in your dataset with the output variable.
```

*method* Contains.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* Depth

```
def __init__(
depth
) -> Depth
```

```
Use this class obtain a QGraph that only contain graphs of a certain depth.
# Consider only graphs with depth 2
> qgraph = qgraph.filter(feyn.filters.Depth(2))
> qgraph.fit(data)
```

*method* Depth.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* Edges

```
def __init__(
edges
) -> Edges
```

```
Use this class obtain a QGraph that only contain graphs with a certain number of edges.
# Consider only graphs with 3 edges
> qgraph = qgraph.filter(feyn.filters.Edges(3))
> qgraph.fit(data)
```

*method* Edges.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* ExcludeFunctions

```
def __init__(
functions: Union[List[str], str]
) -> ExcludeFunctions
```

```
Use this class to obtain a QGraph that does not use certain named functions.
# Consider only graphs that do not use the "gaussian" and "tanh" function
> qgraph = qgraph.filter(feyn.filters.ExcludeFunctions(["gaussian", "tanh"]))
> qgraph.fit(data)
```

*method* ExcludeFunctions.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* Functions

```
def __init__(
functions: Union[List[str], str]
) -> Functions
```

```
Use this class to obtain a QGraph that only uses certain named functions.
# Consider only graphs made of "add" and "multiply"
> qgraph = qgraph.filter(feyn.filters.Functions(["add","multiply"]))
> qgraph.fit(data)
```

*method* Functions.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* MaxDepth

```
def __init__(
depth
) -> MaxDepth
```

```
Use this class obtain a QGraph that only contain graphs up to a certain depth.
# Consider only graphs with depth smaller or equal to 2
> qgraph = qgraph.filter(feyn.filters.MaxDepth(2))
> qgraph.fit(data)
```

*method* MaxDepth.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* MaxEdges

```
def __init__(
edges
) -> MaxEdges
```

```
Use this class to obtain a QGraph that only contain graphs with a up to a certain number of edges.
# Consider only graphs with up to 3 edges
> qgraph = qgraph.filter(feyn.filters.MaxEdges(3))
> qgraph.fit(data)
```

*method* MaxEdges.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* QGraphFilter

```
def __init__(
/,
*args,
**kwargs
) -> QGraphFilter
```

```
The abstract base class for QGraph Filters
```

*method* QGraphFilter.key

```
def key(
self
) -> str
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```

*class* Query

```
def __init__(
query_string: str
) -> Query
```

```
Use this class obtain a QGraph that only contains graphs that contain a subgraph matching the input query.
# Consider only graphs that take an inverse of "age"
> qgraph = qgraph.filter(feyn.filters.Query('inverse("age")'))
> qgraph.fit(data)
```

*method* Query.key

```
def key(
self
)
```

```
Return a unique key for this filter. A QGraph can only have one filter with a given key, so filters can be made mutually exlusive using this method.
When defining a filter that derives from this class, be sure to override this method and return a custom key.
```