neupy.datasets.reber module

neupy.datasets.reber.make_reber(n_words=100)[source]

Generate list of words valid by Reber grammar.

Parameters:

n_words : int

Number of reber words, defaults to 100.

Returns:

list

List of Reber words.

Examples

>>> from neupy.datasets import make_reber
>>> make_reber(4)
['TPTXVS', 'VXXVS', 'TPPTS', 'TTXVPXXVS']
neupy.datasets.reber.is_valid_by_reber(word)[source]

–°hecks whether a word belongs to grammar Reber.

Parameters:

word : str or list of letters

The word that you want to test.

Returns:

bool

True if word valid by Reber grammar and False otherwise.

Examples

>>> from neupy.datasets import is_valid_by_reber
>>>
>>> is_valid_by_reber('TTS')
True
>>> is_valid_by_reber('STS')
False
>>>
>>> is_valid_by_reber(['T', 'T', 'S'])
True
>>> is_valid_by_reber(['S', 'T', 'S'])
False
neupy.datasets.reber.make_reber_classification(n_samples, invalid_size=0.5, return_indeces=False)[source]

Generate random dataset for Reber grammar classification. Invalid words contains the same letters as at Reber grammar, but they are build whithout grammar rules.

Parameters:

n_samples : int

Number of samples in dataset.

invalid_size : float

Proportion of invalid words in dataset, defaults to 0.5. Value must be between 0 and 1.

return_indeces : bool

If True, each word will be converted to array where each letter converted to the index. Defaults to False.

Returns:

tuple

Return two lists. First contains words and second - labels for them.

Examples

>>> from neupy.datasets import make_reber_classification
>>>
>>> data, labels = make_reber_classification(10, invalid_size=0.5)
>>> data
array(['SXSXVSXXVX', 'VVPS', 'VVPSXTTS', 'VVS', 'VXVS', 'VVS',
       'PPTTTXPSPTV', 'VTTSXVPTXVXT', 'VSSXSTX', 'TTXVS'],
      dtype='<U12')
>>> labels
array([0, 1, 0, 1, 1, 1, 0, 0, 0, 1])
>>>
>>> data, labels = make_reber_classification(
...     4, invalid_size=0.5, return_indeces=True)
>>> data
array([array([1, 3, 1, 4]),
       array([0, 3, 0, 3, 0, 4, 3, 0, 4, 4]),
       array([1, 3, 1, 2, 3, 1, 2, 4]),
       array([0, 3, 0, 0, 3, 0, 4, 2, 4, 1, 0, 4, 0])], dtype=object)