Skip to content

Instantly share code, notes, and snippets.

View napsternxg's full-sized avatar
🎯
Focusing

Shubhanshu Mishra napsternxg

🎯
Focusing
View GitHub Profile
@napsternxg
napsternxg / MAG_ISSUES.md
Last active March 12, 2019 00:06
Author position issues in Microsoft Academic Graph data

Instances when same author position occurs in mutliple positions in a paper:

Total instances: 150783 E.g.

# PAPER  AUTHOR  NO_OF_OCCURENCENS
[((u'08D53976', u'4288B19F'), 2), 
 ((u'04659D00', u'3E8E4B9F'), 2), 
 ((u'0770BD71', u'41DFB1F8'), 2), 
@napsternxg
napsternxg / useful_pandas_snippets.py
Created January 27, 2016 09:37 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@napsternxg
napsternxg / LR_tensorflow.py
Last active January 26, 2016 08:39
Linear Regression using reusable modules defined using tensorflow ops
import numpy as np
import tensorflow as tf
# Define the data
X = np.random.randn(100, 2).astype(np.float32)
W_true = np.array([[2, 1]]).T.astype(np.float32)
y_true = X.dot(W_true) + 1.5
print X.shape, W_true.shape, y_true.shape, W_true
tf.python.framework.ops.reset_default_graph() # REST THE GRAPH
@napsternxg
napsternxg / sock.py
Last active January 23, 2016 23:41
Scratch code in python for solving sock bayesian inference problem
# Solve sock problem in python using solution provided by http://www.sumsar.net/blog/2014/10/tiny-data-and-the-socks-of-karl-broman/
## Youtube video by the author explaining the problem: https://www.youtube.com/watch?v=nKCT-Cdk0xY
import numpy as np
import pandas as pd
n_socks = 18
n_picks = 11
n_pairs = 7
n_odd = n_socks - 2*n_pairs
@napsternxg
napsternxg / Regression.ipynb
Created January 18, 2016 12:26
Measuring importance of coefficients of OLS
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@napsternxg
napsternxg / HackerNews_GoogleBQ.md
Last active March 12, 2019 00:06
TOP 10 HackerNews posts per year

Data collected from Google Big Query:

SELECT id, title, story_score, publish_year, title_rank, FORMAT_UTC_USEC(time_ts) as publish_time
  FROM
  (
    SELECT title, max(score) as story_score, Year(time_ts) as publish_year, time_ts, id, RANK() OVER(PARTITION BY publish_year ORDER BY story_score DESC) as title_rank
      FROM [fh-bigquery:hackernews.stories] WHERE title IS NOT NULL and time_ts is not NULL
 GROUP BY publish_year, title, time_ts, id
# "Colorizing B/W Movies with Neural Nets",
# Network/Code Created by Ryan Dahl, hacked by samim.io to work with movies
# BACKGROUND: http://tinyclouds.org/colorize/
# DEMO: https://www.youtube.com/watch?v=_MJU8VK2PI4
# USAGE:
# 1. Download TensorFlow model from: http://tinyclouds.org/colorize/
# 2. Use FFMPEG or such to extract frames from video.
# 3. Make sure your images are 224x224 pixels dimension. You can use imagemagicks "mogrify", here some useful commands:
# mogrify -resize 224x224 *.jpg
# mogrify -gravity center -background black -extent 224x224 *.jpg
@napsternxg
napsternxg / RandomWalkImage.ipynb
Last active July 7, 2023 08:34
Random Walk Image Generation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@napsternxg
napsternxg / markov.py
Created January 4, 2016 16:57
Find next state in Markov process
import numpy as np
trans_mat = np.array([[0.6, 0.4], [0.4, 0.6]]) # Define transition matrix
init_state = np.array([200, 0]) # Define initial state
n_iters = 10 # Define number of iterations
next_state = init_state
for i in xrange(n_iters):
next_state = next_state.dot(trans_mat)
print next_state
@napsternxg
napsternxg / Output.txt
Created September 9, 2015 17:20
Haiku Char-RNN
('----- diversity:', 0.2)
----- Generating with seed: " cane
the train's wh"
cane
the train's wh bcattat saobnahhsaaelmemm t ealaeeteueuiirrrrethu uriibiboboo tat stttalalllaer tmettummm p ooor rthhuie rrres aa
('----- diversity:', 0.5)
----- Generating with seed: " cane
the train's wh"
cane