This file contains hidden or 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 tensorflow as tf | |
import numpy as np | |
from tensorflow.python.framework import ops | |
from tensorflow.python.data.ops import dataset_ops | |
from tensorflow.python.util.tf_export import tf_export | |
from tensorflow.python.data.experimental import group_by_window | |
from tensorflow.python.framework import constant_op |
This file contains hidden or 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
#!/usr/bin/python3 | |
import sys | |
import os | |
from Xlib import X, display, Xutil | |
import select | |
# http://python-xlib.sourceforge.net/doc/html/python-xlib_11.html | |
# Application window (only one) |
This file contains hidden or 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 tensorflow as tf # 1.3.0 | |
import numpy as np | |
# model + input | |
w = tf.Variable(1, name="w", dtype=tf.float32 ) # parameter to optimize for | |
x = tf.placeholder(shape=(), dtype=tf.float32, name="x") # input | |
# graph operations | |
diff_op = tf.multiply(w, x) # an operation that is differentiable | |
non_diff_op = tf.cast(tf.equal(diff_op, 0), dtype=tf.float32) # operation that is non differentiable |
This file contains hidden or 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
# needs bibtexparser==0.6.2, argparse | |
""" | |
Parses a Bib file and checks if all links are available | |
""" | |
# imports | |
import bibtexparser | |
import argparse | |
import re | |
import requests |
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 hidden or 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
""" | |
Simple example to demostrate the embedding visualization for word embeddings in tensorflow / tensorboard | |
https://www.tensorflow.org/how_tos/embedding_viz/ | |
""" | |
import tensorflow as tf | |
import os | |
assert tf.__version__ == '1.0.0-rc0' # if code breaks, check tensorflow version | |
from tensorflow.contrib.tensorboard.plugins import projector |
This file contains hidden or 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
from keras.models import Sequential # model used | |
from keras.layers import Dense, Embedding, LSTM # layers used | |
batch_size = 2 # how many sequence to process in parallel | |
time_steps = 3 # lstm length, number of cells, etc. | |
input_dim = 1 # number of features | |
embedding_size = 5 # size of embedding vector | |
model = Sequential() | |
model.add(Embedding( |
This file contains hidden or 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
""" | |
Learning Task: | |
Given a sequence, predict a label based on the first value of the sequence | |
Explanation of stateful LSTM and setup: | |
http://philipperemy.github.io/keras-stateful-lstm/ | |
Exmple: | |
given a sequence [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], predict 1 | |
given a sequence [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], predict 0 |
This file contains hidden or 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 numpy as np | |
from scipy.stats import entropy # calculate kl divergence #http://scipy.github.io/devdocs/generated/scipy.stats.entropy.html | |
np.set_printoptions(precision=2) | |
# https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm | |
# Original Paper http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.367.5281&rep=rep1&type=pdf | |
deletion_cost = 1 | |
insertion_cost = 1 | |
substitution_cost = 1 |
This file contains hidden or 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
# sudo pip install pulp | |
# sudo apt-get install python-glpk gplk-utils | |
from pulp import * | |
optimization_problem = LpProblem("Nutrients Optimization", LpMinimize) | |
# Cost Parameters for Selecting a food | |
# diversity (minimum amount of certain foods) | |
# diversity (minimum amount of vegetables) | |
# multiple cost factors (money, co2, water) |
NewerOlder