Skip to content

Instantly share code, notes, and snippets.

View marty1885's full-sized avatar
👨‍💻
Writing code

Martin Chang marty1885

👨‍💻
Writing code
View GitHub Profile
@marty1885
marty1885 / root-realtime-plot.cpp
Last active October 1, 2021 15:52
Spectrum and waveform display using ROOT
// Using SFML as out audio loader and player
#include <SFML/Audio.hpp>
// The standard headers we need
#include <iostream>
#include <thread>
#include <chrono>
#include <stdexcept>
#include <memory>
#include <cassert>
//Released under BSD-3 Cluse licsence
//How to run: root -b stackedsp.cpp
//or: c++ stackedsp.cpp -o stackedsp -O3 -lEtaler `root-config --cflags --ldflags --glibs` && ./stackedsp
//Assuming you have Etaler installed in /use/local/lib. Change this if you have it in other places
#pragma cling load("/usr/local/lib/libEtaler.so")
#include <Etaler/Etaler.hpp>
#include <Etaler/Algorithms/SpatialPooler.hpp>
#include <Etaler/Encoders/GridCell1d.hpp>
#include <Etaler/Encoders/Scalar.hpp>
using namespace et;
The Meson build system
Version: 0.50.1
Source dir: /home/marty/Documents/phosh2
Build dir: /home/marty/Documents/phosh2/_build
Build type: native build
Project name: phosh
Project version: 0.0.2
Native C compiler: cc (gcc 8.3.0 "cc (GCC) 8.3.0")
Build machine cpu family: x86_64
Build machine cpu: x86_64
The Meson build system
Version: 0.50.1
Source dir: /home/marty/Documents/phosh
Build dir: /home/marty/Documents/phosh/_build
Build type: native build
Project name: phosh
Project version: 0.0.2
Native C compiler: cc (gcc 8.3.0 "cc (GCC) 8.3.0")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Directory already configured.
Just run your build command (e.g. ninja) and Meson will regenerate as necessary.
If ninja fails, run "ninja reconfigure" or "meson --reconfigure"
to force Meson to regenerate.
If build failures persist, run "meson setup --wipe" to rebuild from scratch
using the same options as passed when configuring the build.
To change option values, run "meson configure" instead.
ninja: Entering directory `_build'
inline size_t unfoldIndex(const std::vector<size_t>& index, const std::vector<size_t>& shape) noexcept
{
size_t s = 0;
size_t v = 1;
assert(index.size() == shape.size());
for(int i=(int)index.size()-1;i>=0;i--) {
v *= (i==(int)index.size()-1?1:shape[i+1]);
s += index[i] * v;
}
inline xt::xarray<uint16_t> load_image(std::string path)
{
std::ifstream in(path);
xt::xarray<int> arr = xt::load_csv<int>(in);
in.close();
//Image padding
xt::xarray<int> resized_image = xt::zeros<int>({arr.shape()[0]+2, arr.shape()[1]+1});
xt::view(resized_image, xt::range(1, arr.shape()[0]+1), xt::range(1, arr.shape()[1]+1)) = arr;
[marty@zack scripts]$ make clean
[marty@zack scripts]$ make -j6
[ 1%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/BacktrackingTMCpp.cpp.o
[ 3%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/Anomaly.cpp.o
[ 3%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/AnomalyLikelihood.cpp.o
[ 4%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/ClassifierResult.cpp.o
[ 5%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/Cells4.cpp.o
[ 6%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/Cell.cpp.o
[ 7%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/Connections.cpp.o
[ 7%] Building CXX object src/CMakeFiles/nupic_core.dir/nupic/algorithms/InSynapse.cpp.o
#include "HTMHelper.hpp"
using namespace HTM;
int main()
{
TemporalMemory tm({16}, 8);
CategoryEncoder encoder(2, 8);
std::vector<size_t> seq = {0,0,1,1};
//build: c++ tmperf.cpp -o tmperf -O3 -lnupic_core
//usage: ./tmperf
#include <nupic/algorithms/TemporalMemory.hpp>
#include <chrono>
#include <vector>
#include <random>
using TemporalMemory = nupic::algorithms::temporal_memory::TemporalMemory; //Yeah.... This is too redundent