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
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
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"});
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);
// 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");
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());
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());
//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>
@marty1885
marty1885 / Etaler_API_example.ipynb
Last active August 5, 2019 16:46
Etaler_API_example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#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);
version value
0.1 1
0.1 1.257
0.2 2
0.2 1.3