<commit_before>from unittest import TestCase

from matplotlib import pyplot as plt
import nose
import numpy as np

from nengo.simulator import Simulator
from nengo.old_api import Network

def rmse(a, b):
    return np.sqrt(np.mean((a - b) ** 2))


class TestOldAPI(TestCase):
    # -- Tests are in a class so that 
    #    nengo_ocl can automatically run all
    #    member unit tests for other simulators by
    #    subclassing this class and overriding this attribute.
    Simulator = Simulator

    show = False

    def test_direct_mode_simple(self):
        """
        """
        net = Network('Runtime Test', dt=0.001, seed=123,
                     Simulator=self.Simulator)
        net.make_input('in', value=np.sin)
        p = net.make_probe('in', dt_sample=0.001, pstc=0.001)
        net.run(0.01)
        data = p.get_data()
        print data.dtype
        print data
        assert np.allclose(data.flatten(),
                           np.sin(np.arange(0, 0.0095, .001)))


    def test_basic_1(self, N=1000):
        """
        Create a network with sin(t) being represented by
        a population of spiking neurons. Assert that the
        decoded value from the population is close to the
        true value (which is input to the population).

        Expected duration of test: about .7 seconds
        """

        net = Network('Runtime Test', dt=0.001, seed=123,
                     Simulator=self.Simulator)
        print 'make_input'
        net.make_input('in', value=np.sin)
        print 'make A'
        net.make('A', N, 1)
        print 'connecting in -> A'
        net.connect('in', 'A')
        A_fast_probe = net.make_probe('A', dt_sample=0.01, pstc=0.001)
        A_med_probe = net.make_probe('A', dt_sample=0.01, pstc=0.01)
        A_slow_probe = net.make_probe('A', dt_sample=0.01, pstc=0.1)
        in_probe = net.make_probe('in', dt_sample=0.01, pstc=0.01)

        net.run(1.0)
        print net.sim.signals[net.one]
        print net.sim.signals[net.steps]
        print net.sim.signals[net.simtime]

        target = np.sin(np.arange(0, 1000, 10) / 1000.)
        target.shape = (100, 1)

        for speed in 'fast', 'med', 'slow':
            probe = locals()['A_%s_probe' % speed]
            data = np.asarray(probe.get_data()).flatten()
            plt.plot(data, label=speed)

        in_data = np.asarray(in_probe.get_data()).flatten()

        plt.plot(in_data, label='in')
        plt.legend(loc='upper left')

        #print in_probe.get_data()
        #print net.sim.sim_step

        if self.show:
            plt.show()<commit_msg>Removed non-api prints from old_api test<commit_after>from unittest import TestCase

from matplotlib import pyplot as plt
import nose
import numpy as np

from nengo.simulator import Simulator
from nengo.old_api import Network

def rmse(a, b):
    return np.sqrt(np.mean((a - b) ** 2))


class TestOldAPI(TestCase):
    # -- Tests are in a class so that 
    #    nengo_ocl can automatically run all
    #    member unit tests for other simulators by
    #    subclassing this class and overriding this attribute.
    Simulator = Simulator

    show = False

    def test_direct_mode_simple(self):
        """
        """
        net = Network('Runtime Test', dt=0.001, seed=123,
                     Simulator=self.Simulator)
        net.make_input('in', value=np.sin)
        p = net.make_probe('in', dt_sample=0.001, pstc=0.001)
        net.run(0.01)
        data = p.get_data()
        print data.dtype
        print data
        assert np.allclose(data.flatten(),
                           np.sin(np.arange(0, 0.0095, .001)))


    def test_basic_1(self, N=1000):
        """
        Create a network with sin(t) being represented by
        a population of spiking neurons. Assert that the
        decoded value from the population is close to the
        true value (which is input to the population).

        Expected duration of test: about .7 seconds
        """

        net = Network('Runtime Test', dt=0.001, seed=123,
                     Simulator=self.Simulator)
        print 'make_input'
        net.make_input('in', value=np.sin)
        print 'make A'
        net.make('A', N, 1)
        print 'connecting in -> A'
        net.connect('in', 'A')
        A_fast_probe = net.make_probe('A', dt_sample=0.01, pstc=0.001)
        A_med_probe = net.make_probe('A', dt_sample=0.01, pstc=0.01)
        A_slow_probe = net.make_probe('A', dt_sample=0.01, pstc=0.1)
        in_probe = net.make_probe('in', dt_sample=0.01, pstc=0.01)

        net.run(1.0)

        target = np.sin(np.arange(0, 1000, 10) / 1000.)
        target.shape = (100, 1)

        for speed in 'fast', 'med', 'slow':
            probe = locals()['A_%s_probe' % speed]
            data = np.asarray(probe.get_data()).flatten()
            plt.plot(data, label=speed)

        in_data = np.asarray(in_probe.get_data()).flatten()

        plt.plot(in_data, label='in')
        plt.legend(loc='upper left')

        #print in_probe.get_data()
        #print net.sim.sim_step

        if self.show:
            plt.show()
{'fraction_non_alphanumeric': 0.12058130400628436, 'fraction_numerical': 0.03260015710919089, 'mean_word_length': 2.1477132262051915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3713386', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1649, 'n_words': 420}