<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Tensorflow details
TODO
Work out how to handle variable-sized input (masking?)
If masking, should it be sparse?
Work out how to integrate into standard optimizers with minimum messing about
Can I do FFT or other such optimised transforms inside the loop?
can I export a binary?
installation
latest version
Mac OS
export TF_BINARY_URL=https
Step1:  basic use
First we create a Graph, which is some kind of computational graph abstraction which will be executed later.
We then create a session object that encapsulates the connection between our graph and the weird morass of C++/GPU task distribution and graph compilation and so on.
A clear example of doing this is in the MNIST tutorial.
Step2:  Interactive style session
For ease of use in interactive Python environments, such as IPython you can instead use the InteractiveSession class, and the Tensor.eval() and Operation.run() methods. This avoids having to keep a variable holding the session.
An MNIST example of this
Step3:  placeholders, variables, scope
placeholder
Step4:  So that worked beautifully with TF's own built-in optimizer. But how do we use an external optimiser?
tf.contrib.opt.ScipyOptimizerInterface.
More generally, internal loops can be constructed using  control flow operations.
Now I want to know how to mask variables for use in my estimators
<ASSISTANT_TASK:>
Python Code:
import numpy as np
import warnings
from scipy.optimize import minimize
from scipy.integrate import quad
from scipy.interpolate import interp1d
from scipy import stats
from importlib import reload
from src import sim_cts, sim_discrete
from scipy.stats import poisson, geom
import tensorflow as tf
## web graphics
%matplotlib inline
## interactive graphics
#%matplotlib notebook
## SVG graphics
#%config InlineBackend.figure_format = 'svg' 
# plotting requirements
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from src.rng import default_random_state
Explanation: Tensorflow details
TODO
Work out how to handle variable-sized input (masking?)
If masking, should it be sparse?
Work out how to integrate into standard optimizers with minimum messing about
Can I do FFT or other such optimised transforms inside the loop?
can I export a binary?
installation
latest version
Mac OS
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl
Linux GPU
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl
Linux no-GPU
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl
Everyone
Finally
pip install --upgrade $TF_BINARY_URL
How to do stuff
placeholder variables explained through MNIST
going deeper on how that works, still with MNIST
graphs and sessions
abusing tensorflow for cheezy time-dependent PDEs
abusing tensorflow for cheezy Mandelbrot sets
shared variables a.k.a. scope in Tensorflow
variables are pointers to tensor buffers
data types
high performance parallel tensorflow
End of explanation
#This is making a Graph implicity (or at least, puting operations onto the default graph)
# Create a Constant op that produces a 1x2 matrix.  The op is
# added as a node to the default graph.
#
# The value returned by the constructor represents the output
# of the Constant op.
matrix1 = tf.constant([[3., 3.]])
# Create another Constant that produces a 2x1 matrix.
matrix2 = tf.constant([[2.],[2.]])
# Create a Matmul op that takes 'matrix1' and 'matrix2' as inputs.
# The returned value, 'product', represents the result of the matrix
# multiplication.
product = tf.matmul(matrix1, matrix2)
# Launch the session, which will execute, per default, the default Graph when we request operations from it..
sess = tf.Session()
# To run the matmul op we call the session 'run()' method, passing 'product'
# which represents the output of the matmul op.  This indicates to the call
# that we want to get the output of the matmul op back.
#
# All inputs needed by the op are run automatically by the session.  They
# typically are run in parallel.
#
# The call 'run(product)' thus causes the execution of three ops in the
# graph: the two constants and matmul.
#
# The output of the op is returned in 'result' as a numpy `ndarray` object.
result = sess.run(product)
print(result)
# ==> [[ 12.]]
# Close the Session when we're done.
sess.close()
with tf.Session() as sess:
  result = sess.run(product)
  print(result)
Explanation: basic use
First we create a Graph, which is some kind of computational graph abstraction which will be executed later.
We then create a session object that encapsulates the connection between our graph and the weird morass of C++/GPU task distribution and graph compilation and so on.
A clear example of doing this is in the MNIST tutorial.
End of explanation
# Enter an interactive TensorFlow Session.
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])
# Initialize 'x' using the run() method of its initializer op.
x.initializer.run()
# Add an op to subtract 'a' from 'x'.  Run it and print the result
sub = tf.sub(x, a)
print(sub.eval())
# ==> [-2. -1.]
# Close the Session when we're done.
sess.close()
Explanation: Interactive style session
For ease of use in interactive Python environments, such as IPython you can instead use the InteractiveSession class, and the Tensor.eval() and Operation.run() methods. This avoids having to keep a variable holding the session.
An MNIST example of this
End of explanation
x_data = np.random.rand(10000).astype(np.float32)
y_data = x_data * 5 + 0.3 + np.random.normal(scale=2, size=x_data.size)
plt.scatter(x_data, y_data, marker='.');
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b
# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))
sess.close()
Explanation: placeholders, variables, scope
placeholder: input data that we expect to be filled in with, e.g. minibatches of observations,
Variables: parameters that we might expect to update inside the loop
Scope: a scope to manage shared variables, like a class instance's member variables (which would be an alternative and also simple way to manage this thingy.) 
Iteration
MNIST levels up
linear regression
Is a good sanity check.
End of explanation
a=tf.Variable([[-3.3, -2, -1,0,1,2,3],[-3, -2, -1,0,1,2,3],[-3, -2, -1,0,1,2,3],], name="a")
b=tf.maximum(tf.sign(a), 0)
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
b.eval()
Explanation: So that worked beautifully with TF's own built-in optimizer. But how do we use an external optimiser?
tf.contrib.opt.ScipyOptimizerInterface.
More generally, internal loops can be constructed using  control flow operations.
Now I want to know how to mask variables for use in my estimators
End of explanation
<END_TASK>