def generateSuperimposedSineData(sinefreqs, space, yScales=None):
    sine = SuperimposedSine(sinefreqs)
    if yScales is not None:
        sine.yScales = array(yScales)
    dataset = SequentialDataSet(0, 1)
    data = sine.getFuncValues(space)

    dataset.newSequence()
    for i in xrange(len(data)):
        dataset.addSample([], data[i])

    return dataset
Exemple #2
0
def list_to_dataset(inputs, outputs, dataset=None):
    """List to Dataset

    Convert a standard list to a dataset. The list must be given in the
    following format:

        Inputs: 2 dimension list (N x M)
        Outputs: 2 dimension list (N x K)

        N: Number of time steps in data series
        M: Number of inputs per time step
        K: Number of outputs per time step

    Arguments:
        inputs: The input list given under the above conditions.
        outputs: The output list given under the above conditions.
        dataset: A SequentialDataSet object to add a new sequence. New dataset
            generated if None. (Default: None)

    Returns:
        A SequentialDataSet object built from the retrieved input/output data.
    """
    assert len(inputs) > 0
    assert len(outputs) > 0
    assert len(inputs) == len(outputs)

    # The dataset object has not been initialized. We must determine the
    # input and output size based on the unpacked data
    num_samples = len(inputs)

    in_dim = 1 if len(inputs.shape) == 1 else inputs.shape[1]
    out_dim = 1 if len(outputs.shape) == 1 else outputs.shape[1]

    # If the dataset does not exist, create it. Otherwise, use the dataset
    # given
    if not dataset:
        dataset = SequentialDataSet(in_dim, out_dim)

    # Make a new sequence for the given input/output pair
    dataset.newSequence()

    for i in range(num_samples):
        dataset.addSample(inputs[i], outputs[i])

    return dataset
Exemple #3
0
rnn.addModule(TanhLayer(dim=hiddenSize, name='in_proc'))
rnn.addModule(LSTMLayer(dim=hiddenSize, peepholes=True, name='hidden'))
rnn.addModule(TanhLayer(dim=hiddenSize, name='out_proc'))
rnn.addOutputModule(SoftmaxLayer(dim=outputSize, name='out'))

rnn.addConnection(FullConnection(rnn['in'], rnn['in_proc'], name='c1'))
rnn.addConnection(FullConnection(rnn['in_proc'], rnn['hidden'], name='c2'))
rnn.addRecurrentConnection(
    FullConnection(rnn['hidden'], rnn['hidden'], name='c3'))
rnn.addConnection(FullConnection(rnn['hidden'], rnn['out_proc'], name='c4'))
rnn.addConnection(FullConnection(rnn['out_proc'], rnn['out'], name='c5'))

rnn.sortModules()

# Construct dataset
trainingData = SequentialDataSet(inputSize, outputSize)

for index, row in df.iterrows():
    trainingData.newSequence()
    inputSequence = list((row.values)[0])

    outputVector = [0, 0, 0, 0]
    if index == 'A':
        outputVector[0] = 1

    if index == 'B':
        outputVector[1] = 1

    if index == 'C':
        outputVector[2] = 1