Skip to content

Instantly share code, notes, and snippets.

@Redchards
Redchards / SparseTensor.cxx
Created September 28, 2022 10:04
Noodling about
```c++
template<class V>
using AvialMap = std::map<std::string, V>;
namespace Meta
{
template<class, uint8_t depth>
struct RecursiveMapDepthAux : std::integral_constant<uint8_t, depth>
{};
template<class K, class V, uint8_t depth>
struct RecursiveMapDepthAux<std::map<K, V>, depth> : RecursiveMapDepthAux<V, depth + 1>
import numpy as np
import cv2
import tsp
import pickle as pkl
def euclidian_distance(x1, x2):
return np.sqrt((x2[0] - x1[0]) ** 2 + (x2[1] - x1[1]) ** 2)
class EMDEHGDataset(Dataset):
def __init__(self, log_eps=1e-6, filt=None, channels=(2,), truncate=True, average_time=False):
super(EMDEHGDataset, self).__init__()
assert sum([int(x > 2) for x in channels]) == 0, 'Invalid channel number, can only be in {0, 1, 2}'
assert filt is None or filt in ['f1', 'f2', 'f3'], 'Invalid filter option, must be either None or of f1, f2, f3'
if filt is None:
offset = 0
elif filt == 'f1':
@Redchards
Redchards / retard_q_learning.py
Last active November 12, 2018 16:23
Retarded Q-learning
#!/usr/bin/env python
# OH NO ! IT'S RETARDED !!
'''
1, 1 [[ 0.94235238 0.4 ]
[ 0. 0. ]
[ 0. 0. ]
[-0.4 -1.35506596]
[ 0. 0. ]
@Redchards
Redchards / conv1d.py
Last active November 8, 2018 22:03
pytorch implementation of 1D convolutional NN
# -*- coding: utf-8 -*-
"""
Éditeur de Spyder
Ceci est un script temporaire.
"""
import logging
import torchtext.datasets as datasets
import torchtext.data as data
@Redchards
Redchards / HighwayNetworks
Last active November 5, 2018 23:45
pytorch implementation of highway networks
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 5 17:22:52 2018
@author: Vladslinger """
import torch
from torchvision import datasets, transforms
def generate_linear_layers(in_size, out_size, layer_count):
return [torch.nn.Linear(in_size, in_size) for _ in range(layer_count)]
@Redchards
Redchards / SelfImprovingAgents_.idea_SelfImprovingAgents.iml
Created October 23, 2018 21:49
Reinforcement learning project based on the paper "Self-Improving Reactive Agents Based on Reinforcement Learning, Planning and Teaching"
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
@Redchards
Redchards / tp1.py
Last active October 9, 2018 08:31
First lab of the Statistical Learning course at Sorbonne University
# -*- coding: utf-8 -*-
"""
Éditeur de Spyder
Ceci est un script temporaire.
"""
import torch
from torchvision import datasets, transforms
from math import sqrt
# -*- coding: utf-8 -*-
"""
Created on Mon May 7 23:34:58 2018
@author: admin
"""
from sklearn import linear_model
import matplotlib.pyplot as plt
from matplotlib.colors import rgb_to_hsv
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 11 11:01:05 2018
@author: 3775548
"""
import matplotlib.pyplot as plt
import numpy as np
import random