int GLWidget::stepNuPIC(vector<UInt>& inputSDR, bool learn) { // clear the active columns indicies array m_activeColumnIndicies.assign(NUM_COLUMNS, 0); gs_SP.compute(inputSDR.data(), learn, m_activeColumnIndicies.data()); gs_SP.stripUnlearnedColumns(m_activeColumnIndicies.data()); gs_TM.compute(m_activeColumnIndicies.size(), m_activeColumnIndicies.data(), learn); return 0; }
void ConnectionsPerformanceTest::feedTM(TemporalMemory &tm, vector<Cell> sdr, bool learn) { vector<UInt> activeColumns; for (auto c : sdr) { activeColumns.push_back(c.idx); } tm.compute(activeColumns.size(), activeColumns.data(), learn); }
void ConnectionsPerformanceTest::runTemporalMemoryTest(UInt numColumns, UInt w, int numSequences, int numElements, string label) { clock_t timer = clock(); // Initialize TemporalMemory tm; vector<UInt> columnDim; columnDim.push_back(numColumns); tm.initialize(columnDim); checkpoint(timer, label + ": initialize"); // Learn vector< vector< vector<Cell> > >sequences; vector< vector<Cell> >sequence; vector<Cell> sdr; for (int i = 0; i < numSequences; i++) { for (int j = 0; j < numElements; j++) { sdr = randomSDR(numColumns, w); sequence.push_back(sdr); } sequences.push_back(sequence); } for (int i = 0; i < 5; i++) { for (auto sequence : sequences) { for (auto sdr : sequence) { feedTM(tm, sdr); tm.reset(); } } } checkpoint(timer, label + ": initialize + learn"); // Test for (auto sequence : sequences) { for (auto sdr : sequence) { feedTM(tm, sdr, false); tm.reset(); } } checkpoint(timer, label + ": initialize + learn + test"); }
GLWidget::GLWidget(const QString & inAudioFileName, QWidget *parent) : QGLWidget(parent)//, staticBuffer(0), dynamicBuffer(0), indexBuffer(0) { cout << "Num texture windows: " << NUM_TEXTURE_WINDOWS << endl; cout << "Texture window size: " << TEXTURE_WINDOW_SIZE << " ms" << endl; cout << "Samples per ms: " << SAMPLES_PER_MS << endl; cout << "Timer delta: " << TIMER_DELTA << " ms" << endl; cout << "Memory size: " << MEMORY_SIZE << endl; max_data.create(SPECTRUM_BUFFER_SIZE); for (int i = 0; i < SPECTRUM_BUFFER_SIZE; i++) { max_data(i) = -999999.9; } // // Create the MarSystem to play and analyze the data // MarSystemManager mng; // A series to contain everything MarSystem* net = mng.create("Series", "net"); m_marSystem = net; // Note that you can only add one Marsystem to an Accumulator // any additional Systems added are simply ignored outputwise !! // e.g. if you want to use multiple Marsystems in a row and accumulate // their combined output, you need to put them in a series which you add // to the accumulator MarSystem *accum = mng.create("Accumulator", "accum"); net->addMarSystem(accum); MarSystem *accum_series = mng.create("Series", "accum_series"); accum->addMarSystem(accum_series); accum_series->addMarSystem(mng.create("SoundFileSource/src")); accum_series->addMarSystem(mng.create("Stereo2Mono", "stereo2mono")); accum_series->addMarSystem(mng.create("AudioSink", "dest")); MarSystem* fanout = mng.create("Fanout", "fanout"); accum_series->addMarSystem(fanout); // Power spectrum MarSystem* spectrumMemory = mng.create("Series", "spectrumMemory"); fanout->addMarSystem(spectrumMemory); { MarSystem* net = spectrumMemory; net->addMarSystem(mng.create("Windowing", "ham")); net->addMarSystem(mng.create("Spectrum", "spk")); net->addMarSystem(mng.create("PowerSpectrum", "pspk")); } // Cochlear based/inspired MarSystem* cochlearFeatures = mng.create("Series", "cochlearFeatures"); //fanout->addMarSystem(cochlearFeatures); { MarSystem* net = cochlearFeatures; // Stabilised auditory image, from CARFAC net->addMarSystem(mng.create("CARFAC", "carfac")); } MarSystem* spatialFeatures = mng.create("Series", "spatialFeatures"); fanout->addMarSystem(spatialFeatures); { MarSystem* net = spatialFeatures; // Into time-domain net->addMarSystem(mng.create("Windowing", "ham")); net->addMarSystem(mng.create("Spectrum", "spk")); net->addMarSystem(mng.create("PowerSpectrum", "pspk")); net->addMarSystem(mng.create("ShiftInput", "si")); // DC offset? // Energy measures net->addMarSystem(mng.create("Centroid", "centroid")); net->addMarSystem(mng.create("Rolloff", "rolloff")); net->addMarSystem(mng.create("Flux", "flux")); net->addMarSystem(mng.create("ZeroCrossings", "zc")); // Mel-Frequency Cepstral Coefficients net->addMarSystem(mng.create("MFCC", "mfcc")); // Five MFCC coefficients required net->updControl("MFCC/mfcc/mrs_natural/coefficients", 5); // A resulting feature vector for describing timbral texture consists of the // following features: means and variances of spectral centroid, rolloff, flux, // zero crossings over the texture window (8), low energy (1), and means and // variances of the first five MFCC coefficients over the texture window // (excluding the coefficient corresponding to the DC component) resulting // in a 19-dimensional feature vector, __as a starting point__. } net->addMarSystem(mng.create("AutoCorrelation", "auto")); // Setup texture windows, and window memory size net->updControl( "Accumulator/accum/mrs_natural/nTimes", NUM_TEXTURE_WINDOWS); net->updControl( "Accumulator/accum/Series/accum_series/Fanout/fanout/" \ "Series/spatialFeatures/ShiftInput/si/mrs_natural/winSize", int(MEMORY_SIZE)); net->updControl("mrs_real/israte", SAMPLE_RATE); //m_marSystem->put_html(cout); //cout << *m_marSystem; ofstream oss; oss.open("audioAnalysis.mpl"); oss << *m_marSystem; // Create a Qt wrapper that provides thread-safe control of the MarSystem: m_system = new MarsyasQt::System(m_marSystem); // Get controls m_fileNameControl = m_system->control( "Accumulator/accum/Series/accum_series/" \ "SoundFileSource/src/mrs_string/filename"); m_initAudioControl = m_system->control( "Accumulator/accum/Series/accum_series/" \ "AudioSink/dest/mrs_bool/initAudio"); m_spectrumSource = m_system->control("mrs_realvec/processedData"); m_SAIbinauralSAI = m_system->control( "Accumulator/accum/Series/accum_series/Fanout/fanout/" \ "Series/cochlearFeatures/CARFAC/carfac/mrs_realvec/sai_output_binaural_sai"); m_SAIthreshold = m_system->control( "Accumulator/accum/Series/accum_series/Fanout/fanout/" \ "Series/cochlearFeatures/CARFAC/carfac/mrs_realvec/sai_output_threshold"); m_SAIstrobes = m_system->control( "Accumulator/accum/Series/accum_series/Fanout/fanout/" \ "Series/cochlearFeatures/CARFAC/carfac/mrs_realvec/sai_output_strobes"); // Initialize SP and TM vector<UInt> inputDimensions = {DIM_SDR}; vector<UInt> columnDimension = {NUM_COLUMNS}; m_inputSDR.reserve(DIM_SDR); gs_SP.initialize(inputDimensions, columnDimension, DIM_SDR, 0.5, true, -1.0, int(0.02*NUM_COLUMNS)); gs_SP.setSynPermActiveInc(0.01); gs_TM.initialize(columnDimension, CELLS_PER_COLUMN); // Connect the animation timer that periodically redraws the screen. // It is activated in the 'play()' function. connect( &m_updateTimer, SIGNAL(timeout()), this, SLOT(animate()) ); // Queue given audio file //play(inAudioFileName); m_audioFileName = inAudioFileName; m_fileNameControl->setValue(m_audioFileName, NO_UPDATE); m_system->update(); }