Skip to content

Instantly share code, notes, and snippets.

View kingjr's full-sized avatar

Jean-Rémi KING kingjr

View GitHub Profile
import sys
import os
import os
import numpy as np
import torch
import matplotlib.pyplot as plt
sys.path.append(os.path.abspath('./sentence_embedding'))
from utils import load_model, build_XLM_dictionary # noqa
@kingjr
kingjr / linear_or_categorical.py
Last active February 22, 2019 23:03
linear_or_categorical.py
"""Fit sigmoid with parallel seeds to find global minimum.
"""
import matplotlib.pyplot as plt
import numpy as np
import torch
import torch.nn as nn
from scipy.stats import pearsonr, wilcoxon
from sklearn.base import BaseEstimator
from sklearn.model_selection import StratifiedKFold
from sklearn.linear_model import LinearRegression
@kingjr
kingjr / fit_sigmoid.py
Created February 22, 2019 21:57
Fit sigmoid with parallel seeds to find global minimum.
"""Fit sigmoid with parallel seeds to find global minimum.
"""
import matplotlib.pyplot as plt
import numpy as np
from sklearn.base import BaseEstimator
import torch
import torch.nn as nn
class SigmoidRegression(BaseEstimator):
@kingjr
kingjr / for_theo_nonlin_cmap.ipynb
Last active December 20, 2018 13:31
for theo: non lin colormap
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10, 10)
y = np.cos(x) / 2. + .5
z = np.sin(x) / 20. + .5
def jr_transform(x, baseline=.50, scaling=100):
x = x - baseline
above = np.log(scaling*x*(x>0)+1)
@kingjr
kingjr / for_jc.py
Created November 27, 2018 16:04
plot dyn system
"""
sudo apt-get install python-dev graphviz libgraphviz-dev pkg-config
pip install pygraphviz
"""
%matplotlib inline
import numpy as np
import os
import networkx as nx
from networkx.drawing.nx_agraph import to_agraph
from IPython.display import Image
@kingjr
kingjr / example_for_david.py
Last active November 26, 2018 17:04
for david
import numpy as np
from sklearn.linear_model import RidgeCV
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_predict, KFold
def correlation(x, y):
a = (x - x.mean(0)) / x.std(0)
b = (y - y.mean(0)) / y.std(0)
@kingjr
kingjr / results_500.csv
Created June 8, 2018 21:45
Google translate challenge first 500 results
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 3 columns, instead of 2. in line 4.
input,output,size
hco hco hco hco hco hco hco hco hco hco hco hco hco hco hco hco hco hco hco hco,"Frequently Asked Questions (FAQ) Contact Us Archive Top All times are GMT +7. The time now is. Contact Us Archive Top All times are GMT +7. The time now is Powered by vBulletin® Version 4.1.4 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.",31
kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy kpy,"Prices are without VAT and are therefore not included in the price. If you have any questions, ask them and we will contact you as soon as possible.",24
ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd ejd,list of other guests. Payment is usually accepted in the quoted currency (Euro) unless the currency and the amount is specifically agreed in advance with the owner / advertiser.,23
hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu hiu,be sure to check out the FAQ by clicking the link above. You may have to register before y
@kingjr
kingjr / google_translate_challenge.py
Created June 8, 2018 21:41
Find simplest google translate request that generate the maximum number of unique words
from googletrans import Translator
from itertools import product
from pandas import DataFrame, read_csv
import numpy as np
import string
import time
import os
# Get google translator object
translator = Translator()
@kingjr
kingjr / wang_wong_simplified.py
Created May 21, 2018 21:36
Wang and Wong perceptual decision making model
"""
Wang and Wong 2006 perceptual decision making model
adapted from https://github.com/xjwanglab/book/blob/b0a8e775a9f687cefbcbb4fcbe3fc19b6343bd70/wong2006/wong2006.py # noqa
"""
import numpy as np
import matplotlib.pyplot as plt
def run(coherence=.3):