This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <htm/algorithms/TemporalMemory.hpp> | |
#include <htm/encoders/ScalarEncoder.hpp> | |
using namespace htm; | |
float benchmarkTemporalMemory(const std::vector<UInt>& out_shape, const std::vector<SDR>& x, size_t num_epoch) | |
{ | |
TemporalMemory tm; | |
tm.initialize(out_shape, 16, 2, 0.21, 0.1, 1, 1024, 0.1, 0.1, 0, 42, 1, 1024, false); | |
// sp.permanences_ = sp.permanences_.cast(DType::Half); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch import nn, optim | |
import torch.functional as F | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# Use ROOT as a binding between C++ and Python | |
import ROOT | |
gROOT = ROOT.gROOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void missing_creator_pct() | |
{ | |
// Now we can use the new and improved RDataFrame interface | |
auto rdf = ROOT::RDataFrame("library", "library.root"); | |
auto rdf_with_year = rdf.Filter("publication_year != 0x7fffffff"); | |
auto rdf_missing = rdf_with_year.Filter("creator != \"\""); | |
std::map<std::string, int> books; | |
std::map<std::string, int> all_books; | |
rdf_with_year.Foreach([&](std::string title, int year) {all_books[title] = year;}, {"title", "publication_year"}); | |
rdf_missing.Foreach([&](std::string title, int year) {books[title] = year;}, {"title", "publication_year"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void missing_creator() | |
{ | |
// Now we can use the new and improved RDataFrame interface | |
auto rdf = ROOT::RDataFrame("library", "library.root"); | |
auto rdf_missing = rdf.Filter("creator != \"\" && publication_year != 0x7fffffff"); | |
std::map<std::string, int> books; | |
rdf_missing.Foreach([&](std::string title, int year) {books[title] = year;}, {"title", "publication_year"}); | |
auto h1 = new TH1F("h1", "books with missing creator", 100, 1850, 2019); | |
for(auto [title, year] : books) | |
h1->Fill(year); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A basic parser, it might get stuff wrong, but good enought for EDA | |
Int_t parse_year(std::string year) | |
{ | |
if(year == "") | |
throw std::runtime_error("year is empty"); | |
if(year[0] == '[' || year[0] == 'c' || year[0] == 'p') // Handle format of [2000], c2000 and p2000 | |
return std::stoi(std::string(year.begin()+1, year.begin()+5)); | |
else if(isdigit(year[0]) == true) | |
return std::stoi(std::string(year.begin(), year.begin()+4)); | |
throw std::runtime_error("cannot parse format"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void count_zeros() | |
{ | |
// Now we can use the new and improved RDataFrame interface | |
auto rdf = ROOT::RDataFrame("library_raw", "library.root"); | |
auto columns = rdf.GetColumnNames(); | |
auto empty_lst = std::map<std::string, size_t>(); | |
ProgressDisplay disp(*rdf.Count()*columns.size()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void to_root_raw() | |
{ | |
// Create a reader from CSV | |
csv::CSVReader reader("checkouts-by-title.csv"); | |
// Create a ROOT File. For the first pass, we'll be saving everything as a string | |
auto f = new TFile("library.root", "recreate"); | |
TTree *t = new TTree("library_raw","raw data from csv file"); | |
auto fields = reader.get_col_names(); | |
auto buf = std::vector<std::string>(fields.size()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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> | |
#include <Etaler/Backends/OpenCLBackend.hpp> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
int main() | |
{ | |
size_t n = 0; | |
size_t count = 0; | |
while(std::cin >> n) { | |
std::vector<size_t> vec(n); |