Muennighoff/xP3x-sample huggingface dataset:
inputs: # Feature columns.
# - age
# - sex
# - ca        number of major vessels (0-3) colored by flourosopy
# - thal      3 = normal; 6 = fixed defect; 7 = reversable defect
feature_columns = [
    fc.numeric_column('age', default_value=-1),
    fc.categorical_column_with_vocabulary_list('sex', [0, 1]),
    fc.numeric_column('ca'),
    fc.categorical_column_with_vocabulary_list(
        'thal', ['normal', 'fixed', 'reversible']),
]
Given the above code, generate some markdown instructions for it.

targets: 
Feature Columns
As for any other TF estimator, data needs to be passed to the estimator, which is typically via an input_fn and parsed using FeatureColumns.
inputs: By definition, a Graph is a collection of nodes (vertices) along with identified pairs of nodes (called edges, links, etc). In NetworkX, nodes can be any hashable object e.g. a text string, an image, an XML object, another Graph, a customized node object, etc. (Note: Python's None object should not be used as a node as it determines whether optional function arguments have been assigned in many functions.)
Nodes
The graph G can be grown in several ways. NetworkX includes many graph generator functions and facilities to read and write graphs in many formats. To get started, we'll look at simple manipulations. You can add one node at a time,

targets: G.add_node(1)
inputs: "04-lista manipulálás

az alábbi cellában definiált kicsi lista segítségével építs egy olyan listát ami háromszor egymás után fordított sorrendben tartalmazza a kicsi lista elemeit.
építs egy olyan listát, ami 6 elemű, az első 5 eleme az eredeti kicsi lista elemei a 6. eleme pedig maga a kicsi lista."
Please write code following the instructions in jupyter notebook style.

targets: 
kicsi=['al',9,'+',42.137,'szoveg',69,1j]
inputs: "<div class="alert alert-success">

<b>EXERCISE</b>: The evolution of the yearly averages with, and the overall mean of all stations

 <ul>
  <li>Use `resample` and `plot` to plot the yearly averages for the different stations.</li>
  <li>The overall mean of all stations can be calculated by taking the mean of the different columns (`.mean(axis=1)`).</li>
</ul>
</div>"
Please write code following the instructions in jupyter notebook style.

targets: 
# %load snippets/02-pandas_introduction97.py
inputs: "2 - For three stocks of your choosing, put their symbols into a list and use pandas to retrieve their data from google for the time frame you created in part (1).  Print the results."
Please write code following the instructions in jupyter notebook style.

targets: 
import pandas_datareader.data as web
inputs: I am working on the file "2.2/tutorials/constraints.ipynb".
The first task is:
Even though under-the-hood the constraints are being rebuilt from scratch, they will remember if you have flipped them to solve for some other parameter.
To show this, let's flip the constraint for the secondary mass to solve for 'period' and then change the hierarchy back to its original value.
Can you write Python code for it?

targets: 
print("M1: {}, M2: {}, period: {}, q: {}".format(b.get_value('mass@primary@component'),
                                                 b.get_value('mass@secondary@component'),
                                                 b.get_value('period@binary@component'),
                                                 b.get_value('q@binary@component')))

b.flip_constraint('mass@secondary@constraint', 'period')

print("M1: {}, M2: {}, period: {}, q: {}".format(b.get_value('mass@primary@component'),
                                                 b.get_value('mass@secondary@component'),
                                                 b.get_value('period@binary@component'),
                                                 b.get_value('q@binary@component')))

b.set_value('mass@secondary@component', 1.0)

print("M1: {}, M2: {}, period: {}, q: {}".format(b.get_value('mass@primary@component'),
                                                 b.get_value('mass@secondary@component'),
                                                 b.get_value('period@binary@component'),
                                                 b.get_value('q@binary@component')))
inputs: "Conclusion: F460M and F480M provide the best contrast for medium band filters across all masses and ages considered (1-100 Myr, 0.5-10 MJup).
Linder Models for Wide Band Filters"
Please write code following the instructions in jupyter notebook style.

targets: 
fig, axes_all = plt.subplots(3,3,figsize=(14,9),sharex=True)

ages = [1, 10, 100] # Myr
mass_min, mass_max = (0.1, 10)  # MJup
masses = np.logspace(np.log10(mass_min),np.log10(mass_max),num=30)
filters = ['F277W', 'F356W', 'F444W']

# Normalize a G2V star to it's K-Band absolute magnitude
bp_k = pynrc.bp_2mass('k')
spt = 'G2V'
sp_star = pynrc.stellar_spectrum(spt, 3.2, 'vegamag', bp_k)

model = 'linder'

for i, age in enumerate(ages):
    axes = axes_all[i]
    
    for filt in filters:
        bp = nrc_utils.read_filter(filt, module='B')

        res = get_planet_counts(bp, age, masses, return_mags=False, model=model)    
        axes[0].loglog(masses, res, marker='.', label=filt)

        res = get_planet_counts(bp, age, masses, return_mags=True, model=model)
        axes[1].semilogx(masses, res, marker='.', label=filt)

        obs = S.Observation(sp_star, bp, bp.wave)
        axes[2].semilogx(masses, res - obs.effstim('vegamag'), marker='.', label=filt)

    axes[0].set_ylabel("Flux (counts/sec)")
    axes[1].set_ylabel("Flux (mag)")
    axes[2].set_ylabel("Contrast (mag)")
    if i==0: 
        axes[0].set_title(f"Companion Flux (counts)")
        axes[1].set_title(f"Companion Flux (mags)")
        axes[2].set_title(f"Contrast Relative to {spt} Primary")

    
    for j, ax in enumerate(axes):
        if j>0:
            ax.set_ylim(ax.get_ylim()[::-1])
        ax.legend(title=f'Age = {age} Myr', loc='lower right')
        if i==2: 
            ax.set_xlabel('Companion Mass ($M_{Jup}$)')
            
            
mod_str = 'BEX' if model=='linder' else 'COND'
fig.suptitle(f'{mod_str} Models', fontsize=15)
    
fig.tight_layout()
inputs: I am working on the file "06-Diverse-pyradi-utilities.ipynb".
The first task is:
Reading two-dimensional lookup tables
The ryfiles.read2DLookupTable
Reads a 2D lookup table and extract the data. The table has the following format:
line 1: xlabel ylabel title
line 2: 0 (vector of y (col) abscissa)
lines 3 and following: (element of x (row) abscissa), followed
by table data.

From line/row 3 onwards the first element is the x abscissa value
followed by the row of data, one point for each y abscissa value.
The file format can depicted as follows:
x-name y-name ordinates-name
0 y1 y2 y3 y4
x1 v11 v12 v13 v14
x2 v21 v22 v23 v24
x3 v31 v32 v33 v34
x4 v41 v42 v43 v44
x5 v51 v52 v53 v54
x6 v61 v62 v63 v64

The function has the signature:
`read2DLookupTable(filename)`


fname (string) input path and filename    

The function returns the following:

xVec ((np.array[N])) x abscissae
yVec ((np.array[M])) y abscissae
data ((np.array[N,M])) data corresponding the x,y
xlabel (string) x abscissa label
ylabel (string) y abscissa label
title (string) dataset title
Can you write Python code for it?

targets: 
filecont = ['x-name y-name ordinates-name\n',
'0 1   2   3  4\n',
'10 11 12 13 14\n',
'20 21 22 23 24\n',
'30 31 32 33 34\n',
'40 41 42 43 44\n',
'50 51 52 53 54\n',
'60 61 62 63 64\n']

with open('2dfile.dat', 'wt') as f:
    f.writelines(filecont)

import os.path    
if os.path.sep == '/':
    !cat 2dfile.dat
else:
    !type 2dfile.dat    
    
xVec,yVec,data,xlabel, ylabel, title = ryfiles.read2DLookupTable('2dfile.dat')
print('\n')
print('xVec={}'.format(xVec))
print('yVec={}'.format(yVec))
print('data={}'.format(data))
print('xlabel={}'.format(xlabel))
print('ylabel={}'.format(ylabel))
print('title={}'.format(title))
inputs: I am working on the file "Notebooks/HNSCC_MATH.ipynb".
The first task is:
From another angle, I don't see the HPV effect in my data.
Can you write Python code for it?

targets: 
draw_survival_curves(math_t, surv, hpv)
inputs: "Creating and Using a Rule-Based Matcher
This, typically involves the following steps:
1. Creating the rule-based matcher
2. Creating features
3. Adding Rules
4. Using the Matcher to Predict Results
Creating the Rule-Based Matcher"
Please write code following the instructions in jupyter notebook style.

targets: 
brm = em.BooleanRuleMatcher()
inputs: I am working on the file "Challenge+Project+Euler.ipynb".
The first task is:
Problem 6
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Can you write Python code for it?

targets: 
#Define the range of numbers we are going to check
r = range(1, 101)  
a = sum(r)

#Multipy the sum of the number and subtract the suqae of the sum of the numbers

print (a * a - sum(i*i for i in r))
inputs: I am working on the file "Lectures/Lecture_2/Jupyter_notebook_sheets/random_module.ipynb".
The first task is:
Given $\mu\in[0,2\pi)$ and $\kappa>0$, the density function of the von Mises (or circular normal, or Tikhonov) distribution of parameters $\mu$ and $\kappa$, defined over $[0,2\pi]$, is equal to $\frac{e^{\kappa\cos(x-\mu)}}{2\pi\Sigma_{m=0}^\infty\frac{1}{m!\Gamma(m+\alpha+1)}(\frac{x}{2})^{2m+\alpha}}$. It is illustrated with $\mu=\pi$ and $\kappa=4$.
Can you write Python code for it?

targets: 
%matplotlib inline
from matplotlib.pyplot import hist, xlim, gca
from matplotlib.ticker import FuncFormatter

from random import vonmisesvariate
from math import pi

nb_of_values = 100000
generated_values = []
for i in range(nb_of_values):
    generated_values.append(vonmisesvariate(pi, 4))
    
def to_percent(x, _):
    return str(x / nb_of_values * 100) + '%'

xlim(0, 2 * pi)
gca().yaxis.set_major_formatter(FuncFormatter(to_percent))
hist(generated_values, 50)
print()
inputs: A word about TensorFlow model serving
Exporting an inference graph and the serving signature is "simple" (though the serving_fn interface could be improved). The cool thing is that once you have your tf.estimator and your serving_input_fn, you can just use tensorflow_serving and get a RESTful API serving your model!
Serving interface

targets: def serving_input_fn():
    tokens = tf.placeholder(
        dtype=tf.int32, shape=[None, None], name="tokens")
    sequence_length = tf.size(tokens)
    features = {'tokens': tokens, 'sequence_length': sequence_length}
    return tf.estimator.export.ServingInputReceiver(
        features=features, receiver_tensors=tokens)

estimator.export_savedmodel('export', serving_input_fn)
inputs: "B
Write a function that computes the remainder of two numbers.

named remainder
takes 2 arguments, two numbers x and y
returns 1 number, the remainder of x (the first argument) divided by y (the second argument)"
Please write code following the instructions in jupyter notebook style.

targets: 
import numpy as np
np.testing.assert_allclose(0.0, remainder(100, 2))
np.testing.assert_allclose(6.0, remainder(123, 39))
np.testing.assert_allclose(3.0, remainder(987, 4))
inputs: # YOUR CODE HERE
from scipy.interpolate import interp2d 

xnew=np.linspace(-5,5,100)
ynew=np.linspace(-5,5,100)

Xnew, Ynew = np.meshgrid(xnew,ynew)

Fnew=griddata((x,y),f,(Xnew,Ynew),method='cubic')



assert xnew.shape==(100,)
assert ynew.shape==(100,)
assert Xnew.shape==(100,100)
assert Ynew.shape==(100,100)
assert Fnew.shape==(100,100)
Given the above code, generate some markdown instructions for it.

targets: 
Use meshgrid and griddata to interpolate the function $f(x,y)$ on the entire square domain:

xnew and ynew should be 1d arrays with 100 points between $[-5,5]$.
Xnew and Ynew should be 2d versions of xnew and ynew created by meshgrid.
Fnew should be a 2d array with the interpolated values of $f(x,y)$ at the points (Xnew,Ynew).
Use cubic spline interpolation.
inputs: 2.4) Dilate footprint to provide a window or region for the point source.
We will use this window to compute the centroid and total flux of the star in the next two lessons. In the meantime, compute the flux like we did in introductionToStellarPhotometry assuming the input center.

targets: # complete
growBy = fwhm
mask = detection_image > threshold_value
print(np.count_nonzero(mask))
dilated_mask = scipy.ndimage.binary_dilation(mask, iterations=growBy)
print(np.count_nonzero(dilated_mask))

fig, ax = pixel_plot(x[dilated_mask], image[dilated_mask])

# easy aperture flux:
np.sum(image[dilated_mask])

# Copied from solutions of previous notebook

from scipy.optimize import minimize

psf = phi(x[dilated_mask], mu=35, fwhm=5)
im = image[dilated_mask]

# minimize the square of the residuals to determine flux
def sum_res(A, flux=im, model=psf):
    return sum((flux - A*model)**2)

sim_star = simulate(x, mu, fwhm, S, F)
psf_flux = minimize(sum_res, 300, args=(im, psf))

print("The PSF flux is {:.3f}".format(psf_flux.x[0]))
inputs: "<table>
    <tr>
        <td><center>15 Collision Hotspots of Manhattan</center></td>
    </tr>
    <tr>
        <td><img src="images/kmeans_1.jpg" alt="Drawing" style="width: 350px;"/> </td>
    </tr>
</table>

You can observe that a small area between the 25th and 60th Streets, the Midtown Manhattan area, has as many collision hotspots as the northern part of Manhattan, including uptown Manhattan area, and twice as many collision hotspots as Lower Manhattan. This is an interesting result that suggests just how many more collisions happen Midtown compared to the rest of Manhattan.
We can focus on parts of New York City to get a more granular understanding of problematic areas. Let's take Midtown Manhattan, for example. We can run kmeans only on the collisions that occur in Midtown Manhattan and plot them. To (roughly) get the collisions in Midtown Manhattan, we can define and use a function to return the collisions that are in a circle:"
Please write code following the instructions in jupyter notebook style.

targets: 
def get_collisions_in_circle(collisions, latitude, longitude, radius_miles):
    location_data = collisions.loc[:, ['LATITUDE', 'LONGITUDE']]
    center = np.array([latitude, longitude])
    # Calculate distances of each collision to the center
    distances = location_data.apply(lambda x: distance((x['LATITUDE'], x['LONGITUDE']), center).miles, axis = 1)
    # Return the collisions inside the circle
    return collisions[distances <= radius].reset_index(drop=True)
inputs: 1 Specialized libraries
Specialized libraries, which provide efficient compiled implementations of the heavy computations, is an easy way to solve the performance problem. That is for example NumPy, which uses efficient BLAS and LAPACK implementations as a backend. SciPy and scikit-learn fall in the same category.
Implement below the accuracy function using:
1. Only functions provided by NumPy. The idea here is to vectorize the computation.
2. The implementation of scikit-learn, our machine learning library.
Then test that it provides the correct result and measure it's execution time. How much faster are they compared to the pure Python implementation ?

targets: def accuracy_numpy(y_pred, y_true):
    """Numpy implementation."""
    # Your code here.
    return 0

def accuracy_sklearn(y_pred, y_true):
    """Scikit-learn implementation."""
    # Your code here.
    return 0

# assert np.allclose(accuracy_numpy(y_pred, y_true), accuracy_python(y_pred, y_true))
# assert np.allclose(accuracy_sklearn(y_pred, y_true), accuracy_python(y_pred, y_true))

# %timeit accuracy_numpy(y_pred, y_true)
# %timeit accuracy_sklearn(y_pred, y_true)
inputs: # build a model specifying the MLP model with hyperband
model_mlp = ModelPipeline(model='multilayer_perceptron_classifier',
                          model_name='MLP example',
                          primary_key='UNITID',
                          dependent_variable=['CONTROL'],
                          cross_validation_parameters='hyperband',
                          etl=etl
                          )
train_mlp = model_mlp.train(train_data, 
                            n_jobs=10) # parallel hyperparameter optimization and validation!
# block until the job finishes
train_mlp.result()
Given the above code, generate some markdown instructions for it.

targets: 
Hyperparameter optimization with Hyperband and Neural Networks
Multilayer Perceptrons (MLPs) are simple neural networks, which are now built in to CivisML. The MLP estimators in CivisML come from muffnn, another open source package written and maintained by Civis Analytics using tensorflow. Let's fit one using hyperband.
Tuning hyperparameters is a critical chore for getting an algorithm to perform at its best, but it can take a long time to run. Using CivisML 2.0, we can use hyperband as an alternative to conventional grid search for hyperparameter optimization-- it runs about twice as fast. While grid search runs every parameter combination for the full time, hyperband runs many combinations for a short time, then filters out the best, runs them for longer, filters again, and so on. This means that you can try more combinations in less time, so we recommend using it whenever possible. The hyperband estimator is open source and available on GitHub. You can learn about the details in the original paper, Li et al. (2016).
Right now, hyperband is implemented in CivisML named preset models for the following algorithms: 
- Multilayer Perceptrons (MLPs)
- Stacking
- Random forests
- GBTs
- ExtraTrees
Unlike grid search, you don't need to specify values to search over. If you pass cross_validation_parameters='hyperband' to ModelPipeline, hyperparameter combinations will be randomly drawn from preset distributions.
inputs: I am working on the file "CS231n/assignment1/two_layer_net.ipynb".
The first task is:
Backward pass
Implement the rest of the function. This will compute the gradient of the loss with respect to the variables W1, b1, W2, and b2. Now that you (hopefully!) have a correctly implemented forward pass, you can debug your backward pass using a numeric gradient check:
Can you write Python code for it?

targets: 
from cs231n.gradient_check import eval_numerical_gradient

# Use numeric gradient checking to check your implementation of the backward pass.
# If your implementation is correct, the difference between the numeric and
# analytic gradients should be less than 1e-8 for each of W1, W2, b1, and b2.

loss, grads = net.loss(X, y, reg=0.1)

# these should all be less than 1e-8 or so
for param_name in grads:
  f = lambda W: net.loss(X, y, reg=0.1)[0]
  param_grad_num = eval_numerical_gradient(f, net.params[param_name], verbose=True)
  print '%s max relative error: %e' % (param_name, rel_error(param_grad_num, grads[param_name]))
inputs: I am working on the file "01-Fundamentals.ipynb".
The first task is:
We now solve for $\boldsymbol{A} \boldsymbol{x}=  \boldsymbol{b}$ and $\boldsymbol{A} (\boldsymbol{x}+ \delta \boldsymbol{x}) = \boldsymbol{b} + \delta \boldsymbol{b}$:
Can you write Python code for it?

targets: 
x  = np.linalg.solve(H, b)
x1 = np.linalg.solve(H, b1)
inputs: "<b> <font color=red>NOTE</font>: to shorten the output of the next command, click the leftmost mouse button on the left of the output to activate a scrolling window. Do the same to anyother help output which follows after this one </b>"
Please write code following the instructions in jupyter notebook style.

targets: 
dir(scores)

xmean = scipy.mean(scores)
sigma = scipy.std(scores)
n = scipy.size(scores)
print ("({0:0.14f}, {1:0.15f}, {2:0.14f})".format(xmean, xmean - 2.576*sigma/scipy.sqrt(n), 
                                                  xmean + 2.576*sigma/scipy.sqrt(n) ))


from scipy import stats
result=scipy.stats.bayes_mvs(scores)
inputs: # DATASET 1 CLASSIFIER CODE GOES HERE

# DATASET 2 CLASSIFIER CODE GOES HERE
Given the above code, generate some markdown instructions for it.

targets: 
Train your classifiers
Next you need to copy/paste in the code from your ML-4 Homework to train your classifiers on the data. Because we're using exactly the same data and you set a random seed, we can expect to get the same classifiers.
inputs: "(2b) Root mean squared error 
We naturally would like to see how well this naive baseline performs.  We will use root mean squared error (RMSE) for evaluation purposes.  Implement a function to compute RMSE given an RDD of (label, prediction) tuples, and test out this function on an example."
Please write code following the instructions in jupyter notebook style.

targets: 
 # TODO: Replace <FILL IN> with appropriate code
def squaredError(label, prediction):
    """Calculates the the squared error for a single prediction.

    Args:
        label (float): The correct value for this observation.
        prediction (float): The predicted value for this observation.

    Returns:
        float: The difference between the `label` and `prediction` squared.
    """
    return np.power(label - prediction, 2)

def calcRMSE(labelsAndPreds):
    """Calculates the root mean squared error for an `RDD` of (label, prediction) tuples.

    Args:
        labelsAndPred (RDD of (float, float)): An `RDD` consisting of (label, prediction) tuples.

    Returns:
        float: The square root of the mean of the squared errors.
    """
    return np.sqrt(1.0 / labelsAndPreds.count() * labelsAndPreds.map(lambda (x, y): squaredError(x, y)).reduce(lambda x, y: x+y))

labelsAndPreds = sc.parallelize([(3., 1.), (1., 2.), (2., 2.)])
# RMSE = sqrt[((3-1)^2 + (1-2)^2 + (2-2)^2) / 3] = 1.291
exampleRMSE = calcRMSE(labelsAndPreds)
print exampleRMSE

# TEST Root mean squared error (2b)
Test.assertTrue(np.allclose(squaredError(3, 1), 4.), 'incorrect definition of squaredError')
Test.assertTrue(np.allclose(exampleRMSE, 1.29099444874), 'incorrect value for exampleRMSE')
inputs: 6. Family simulation (5pts)
Use a simulation to determine the average number of children in a family if all families had children until they had a girl (and then stopped). Assume equal probability of girls and boys and use a random generator to simulate each birth. Simulate 10,000 families and output the average number of children they had. Your answer should be close to 2.
Note: I'm purposely not giving any step by step instructions here because I'd like you to practice translating a word problem into code. It may help if you try break down the problem into smaller parts first. For example, see if you can simulate just one family first, then once that's working, add code to make it run through 10,000 families. Alternatively, you might feel more comfortable writing code to print "hi" 10,000 times, and then replace "print hi" with code for simulating each family. Do whatever makes the problem feel more manageable to you. Learning to break down big problems into smaller parts like this is an essential skill for programming, so I encourage you to work through this. If you get it, then I think it's safe to say you've mastered the material in this lesson and are well on your way to becoming a true programmer!
I'll give partial credit for good efforts!

targets: import random

# By convention, variables with a set, pre-defined value ("constants")
# are indicated by ALL_CAPS variable names and are defined at the top.
# It's not really necessary to define GIRL = 1, but it will make
# the code easier to read and understand, so it's considered good form.
NUM_FAMS = 10000 
GIRL = 1

# regular variables, like this counter, are lower case/camelCase
totalKidsAllFams = 0

for i in range(NUM_FAMS):
    numKids = 0
    hadGirl = False

    while not hadGirl:
        numKids = numKids + 1
        gender = random.randint(0,1) #the miracle of birth
        if gender == GIRL:
            hadGirl = True
        
    # once we exit the while loop, we must have had a girl.
    # so add the number of kids this fam had to the running total, and
    # move on to the next family
    totalKidsAllFams = totalKidsAllFams + numKids

# finally, divide the total number of kids by the number of families to get the avg
print "Avg kids per fam:", float(totalKidsAllFams) / NUM_FAMS
inputs: Converting blast .srl to .csv

targets: !cd $blastDir; \
    CLdb -- arrayBlast -- srl2csv \
    spacers_cut1_blastn_filt.srl \
    > spacers_cut1_blastn_filt.txt
    
# assessing table of blast hits    
!cd $blastDir; \
    head spacers_cut1_blastn_filt.txt

#!printf "Number of blast hits: "
nhits = !cd $blastDir; wc -l spacers_cut1_blastn_filt.txt
nhits = nhits[0].split(' ')[0]
print "Number of blast hits: {}".format(int(nhits) - 1)
inputs: I am working on the file "2.3/tutorials/logg.ipynb".
The first task is:
Relevant Parameters
The 'logg' parameter defines the stellar surface gravity at requiv and is constrained by default.
IMPORTANT NOTE: as the logg parameter is defined to be the surface gravity given the value of mass and requiv, it may not be appropriate to compare or fix the value from an "observed" value of logg (from a spectrum, for example).
Can you write Python code for it?

targets: 
print(b.filter('logg', context='component'))

print(b.filter('logg', context='constraint'))
inputs: 9. Adaptive learning rate

exponential_decay
consine_decay
linear_cosine_decay
consine_decay_restarts
polynomial decay
piecewise_constant_decay

targets: def create_estimator(params, run_config):
  
  wide_columns, deep_columns = create_feature_columns()
  
  def _update_optimizer(initial_learning_rate, decay_steps):
    
    # learning_rate = tf.train.exponential_decay(
    #   initial_learning_rate,
    #   global_step=tf.train.get_global_step(),
    #   decay_steps=decay_steps,
    #   decay_rate=0.9
    # )

    learning_rate = tf.train.cosine_decay_restarts(
      initial_learning_rate,
      tf.train.get_global_step(),
      first_decay_steps=50,
      t_mul=2.0,
      m_mul=1.0,
      alpha=0.0,
    )

    tf.summary.scalar('learning_rate', learning_rate)

    return tf.train.AdamOptimizer(
      learning_rate=initial_learning_rate)
    
  estimator = tf.estimator.DNNLinearCombinedClassifier(

    n_classes=len(TARGET_LABELS),
    label_vocabulary=TARGET_LABELS,
    weight_column=WEIGHT_COLUMN_NAME,

    dnn_feature_columns=deep_columns,
    dnn_optimizer=lambda: _update_optimizer(params.learning_rate, params.max_steps),
    dnn_hidden_units=params.hidden_units,
    dnn_dropout=params.dropout,
    batch_norm=True,
    
    linear_feature_columns=wide_columns,
    linear_optimizer='Ftrl',
    
    config=run_config
  )
  
  return estimator

params.learning_rate = 0.1
params.max_steps = 1000
run_config = tf.estimator.RunConfig(
    tf_random_seed=RANDOM_SEED,
    save_checkpoints_steps=200,
    model_dir=model_dir,
)

if COLAB:
  from tensorboardcolab import *
  TensorBoardColab(graph_path=model_dir)

estimator = create_estimator(params, run_config)
run_experiment(estimator, params, run_config)
inputs: I am working on the file "Housing Prices.ipynb".
The first task is:
Feature Selection using Lasso
Can you write Python code for it?

targets: 
#Feature Selection using Lasso

plt.figure(figsize=(20, 5))
sns.set_style("whitegrid")

plt.subplot(1, 4, 1)
for lambd in [x * 0.01 for x in range(1, 100)]:
    lasso = Lasso(alpha=lambd)
    lasso_coef = lasso.fit(X0, Y).coef_
    plt.xticks(range(len(names)), names, rotation=90)
    plt.ylabel('Coefficients')
    plt.plot(range(len(names)), lasso_coef)
    plt.title('Lasso (All features)')

plt.subplot(1, 4, 2)
for lambd in [x * 0.01 for x in range(1, 100)]:
    lasso = Lasso(alpha=lambd)
    lasso_coef = lasso.fit(XRFE, Y).coef_
    plt.xticks(range(len(namesRFE)), namesRFE, rotation=90)
    plt.ylabel('Coefficients')
    plt.plot(range(len(namesRFE)), lasso_coef)
    plt.title('Lasso RFE')

plt.subplot(1, 4, 3)    
for lambd in [x * 0.01 for x in range(1, 100)]:
    lasso = Lasso(alpha=lambd)
    lasso_coef = lasso.fit(XBS, Y).coef_
    plt.xticks(range(len(namesBS)), namesBS, rotation=90)
    plt.ylabel('Coefficients')
    plt.plot(range(len(namesBS)), lasso_coef)
    plt.title('Lasso (Best Selector)')
    
plt.subplot(1, 4, 4)
for lambd in [x * 0.01 for x in range(1, 100)]:
    lasso = Lasso(alpha=lambd)
    lasso_coef = lasso.fit(XFIRF, Y).coef_
    plt.xticks(range(len(namesFIRF)), namesFIRF, rotation=90)
    plt.ylabel('Coefficients')
    plt.plot(range(len(namesFIRF)), lasso_coef)
    plt.title('Lasso on Random Forest')
    
plt.tight_layout()
plt.show()

#New set of features based on results obtained in with Lasso, Random Forest and RFE

Xl = X1[['Rooms', 'BuildingArea', 'Regionname','Distance', 'Neighbourhood']]

#Split the data into training and testing datasets. Split: 70/30; train/test

X_train, X_test, y_train, y_test = train_test_split(Xl,Y, test_size=0.3, random_state=0)

#Initiating the cross validation generator, N splits = 5
kf = KFold(5)
inputs: "%%cython_pyximport magična funkcija služi da se unese proizvoljan Cython kod u IPython notebook ćeliju. Taj kod se sprema u .pyx u radnom direktoriju i onda importira koristeći pyximport. Moramo specificirati ime modula (u donjem slučaju foo). Svi objekti modula se automatski importiraju."
Please write code following the instructions in jupyter notebook style.

targets: 
%%cython_pyximport foo
def f(x):
    return 4.0*x

f(10)
inputs: An example solution from our reference model, at high resolution:

targets: reference.y[0].sel(time=slice(10, 60)).plot.imshow()
inputs: "And a final check to make this newly defined LFC log only has values within the range 1 to 4 (there will be no undefined samples in this particular depth interval, i.e. classes with LFC=0):"
Please write code following the instructions in jupyter notebook style.

targets: 
print("LFC min: {0}, LFC max: {1}".format(logs.LFC.min(), logs.LFC.max()))
inputs: "Create a class with Inheritance"
Please write code following the instructions in jupyter notebook style.

targets: 
class Teacher(Human):
    ''' Teacher of Python '''

    def give_lecture(self):
        ''' Print lecture on the screen ''' 
        
        print ('bla bla bla')
inputs: "<a id='num_mod_sev'></a>
Number of Moderate Severe Symptoms

In this analysis, we create an indicator variable for moderate/severe for the following 5 symptoms:
    - Pain
    - Dyspnea
    - Fatigue
    - Anxiety
    - Constipation
We start by first create a yes/no variable for each symptom. For instance, for pain, if the symptom score is [5,10], then a '1' is coded, else a '0' is coded (this includes things like <5, a 994 code which indicates unable to ascertain, as well as missing values). If any of this needs to be changed let me know. Once created, we then create 3 new variables which look to determin how many of the symptoms are moderate or severe. What follows is a summary of findings."
Please write code following the instructions in jupyter notebook style.

targets: 
#first read in the (summary) data
import pandas as pd
summ = pd.read_csv(open("./python_scripts/14_number_of_modsev_symptoms.csv","r"))
#now print those with '1 or more moderate/severe symptoms'
summ[0:2]

#now print those with '2 or more moderate/severe symptoms'
summ[2:4]

#now print those with '3 or more moderate/severe symptoms'
summ[4:6]
inputs: I am working on the file "IoT_Camera.ipynb".
The first task is:
GRAVANT UN VIDEO
Can you write Python code for it?

targets: 
camera.start_preview()
camera.start_recording('/home/pi/video.h264')
sleep(10)
camera.stop_recording()
camera.stop_preview()
inputs: "Calculate GLCM Features"
Please write code following the instructions in jupyter notebook style.

targets: 
glcmFeatures = glcm.RadiomicsGLCM(croppedImage, croppedMask, **settings)

# Set the features to be calculated
# glcmFeatures.enableFeatureByName('SumEntropy', True)
glcmFeatures.enableAllFeatures()

# Print out the docstrings of the enabled features
print('Will calculate the following GLCM features: ')
for f in glcmFeatures.enabledFeatures.keys():
  print(f)
  print(getattr(glcmFeatures, 'get%sFeatureValue' % f).__doc__)

# Calculate the features and print(out result)
print('Calculating GLCM features...',)
result = glcmFeatures.execute()
print('done')

print('Calculated GLCM features: ')
for (key, val) in six.iteritems(result):
  print('  ', key, ':', val)
inputs: <ol start="8">
  <h4><li> Comparez la réponse au gros bloc, avec le double de la réponse au petit bloc, en faisant un graphe de la différence des deux signaux.</li></h4>
</ol>

targets: %%matlab
bloc_conv2 = conv(bloc2,noyau,'same');
plot(time_samples,bloc_conv-bloc_conv2,'b-o')
inputs: Conditioning the data set
Now we extract just the feature variables we need to perform the classification.  The predictor variables are the five wireline values and two geologic constraining variables. We also get a vector of the facies labels that correspond to each feature vector.

targets: correct_facies_labels = training_data['Facies'].values

# dropping certain labels and only keeping the geophysical log values to train on
feature_vectors = training_data.drop(['Formation', 'Well Name', 'Depth','Facies','FaciesLabels'], axis=1)
feature_vectors.describe()
inputs: A simple text-processing function, and baseline speed test
The function I'll be testing is a simple text-processing function for tokenizing a string - returning the string as a list of words, after doing a bit of preprocessing.

targets: import re
from nltk.corpus import stopwords

def tokenize(text):
    ''' Accept a string, return list of words (lowercased) without punctuation or stopwords'''

    # lowercase everything
    text = text.lower()
    
    # remove punctuation (\W matches any non-alphanumeric character)
    text = re.sub("\W", " ", text)
    
    # return list of words, without stopwords (stopwords are very common words which may not convey much info)
    droplist = stopwords.words('english')
    
    return [word for word in text.split() if word not in droplist]
    
tokenize('This is a sentence. And another one with punctuation and special characters to strip!?*&^%')
inputs: # PROPERTY ID - DO NOT EDIT !  
DOC.set_id('cmip6.atmoschem.key_properties.timestep_framework.split_operator_advection_timestep')  

# PROPERTY VALUE: 
# Set as follows: DOC.set_value(value)  
DOC.set_value(30) 

Given the above code, generate some markdown instructions for it.

targets: 
3.2. Split Operator Advection Timestep
Is Required: FALSE&nbsp;&nbsp;&nbsp;&nbsp;Type: INTEGER&nbsp;&nbsp;&nbsp;&nbsp;Cardinality: 0.1
Timestep for chemical species advection (in seconds)
inputs: "2.Mache dasselbe mit einer Liste aus 100 Elementen und ordne sie der Variabel b zu."
Please write code following the instructions in jupyter notebook style.

targets: 
list(range(100))

b = list(range(100))

b
inputs: I am working on the file "08._Clustering_Hierarquico_Microarray.ipynb".
The first task is:
Exibição de um dendograma
Função que, para um índice $i$, devolve o nome do gene:
Can you write Python code for it?

targets: 
llf = lambda id : genes[id]

plt.figure(figsize=(12, 30))
plt.title('Dendrograma')
plt.ylabel('Gene')
plt.xlabel(u'Distância (Ward)')
den = dendrogram(Z, orientation='left', leaf_font_size=9, leaf_label_func=llf)
inputs: --- 2.2 . Además de definir las columnas, es necesario definir cuántos renglones tiene que ignorar el script antes de encontrar los encabezados. Estos renglones se definen a continuación en un diccionario:

targets: skiprows = {
    '02' : 7,   # Tipo de piso
    '08' : 7,   # Combustible utilizado para cocinar
    '09' : 7,   # Utilizan leña o carbón para cocinar y distribucion porcentual segun disponibilidad de estufa o fogon 
    '16' : 7,   # disponibilidad de energía eléctrica
    '19' : 7,   # Forma de eliminación de residuos
    '20' : 8,   # Viviendas que entregan sus residuos al servicio publico y distribucion porcentual por condición de separacion
    '21' : 7,   # Separación y reutilización de residuos
    '23' : 7,   # Disponibilidad y tipo de equipamiento
    '24' : 8,   # Disponibilidad de agua entubada según disponibilidad y acceso
    '25' : 7,   # Disponibilidad de agua entubada según fuente de abastecimiento
    '26' : 8,   # Disponibilidad de drenaje y lugar de desalojo
}
inputs: I am working on the file "Project/trained_mental_rotation_ens_inhibition.ipynb".
The first task is:
Testing
Can you write Python code for it?

targets: 
testing = np.dot(ONE,np.dot(label_weights,activity_to_img_weights))
testing = output_acts[300]
plt.subplot(131)
pylab.imshow(np.reshape(testing,(dim, dim), 'F').T, cmap=plt.get_cmap('Greys_r'))

#Get image
#testing = np.dot(ONE,np.dot(label_weights,activity_to_img_weights))
#noise = np.random.random([28,28]).ravel()
testing = node_func(0,testing)

plt.subplot(132)
pylab.imshow(np.reshape(testing,(dim, dim), 'F').T, cmap=plt.get_cmap('Greys_r'))


#Get activity of image
_, testing_act = nengo.utils.ensemble.tuning_curves(ens, sim, inputs=testing)

#Get encoder outputs
testing_filter = np.dot(testing_act,rotated_counter_after_encoder_weights_filter)

#Get activities
testing_filter = ens.neuron_type.rates(testing_filter, sim.data[ens].gain, sim.data[ens].bias)

for i in range(5):
    testing_filter = np.dot(testing_filter,rotated_counter_after_encoder_weights_filter)
    testing_filter = ens.neuron_type.rates(testing_filter, sim.data[ens].gain, sim.data[ens].bias)
    testing_filter = np.dot(testing_filter,activity_to_img_weights)
    testing_filter = node_func(0,testing_filter)
    _, testing_filter = nengo.utils.ensemble.tuning_curves(ens, sim, inputs=testing_filter)


#testing_rotate = np.dot(testing_rotate,rotation_weights)

testing_filter = np.dot(testing_filter,activity_to_img_weights)

plt.subplot(133)
pylab.imshow(np.reshape(testing_filter,(dim, dim), 'F').T, cmap=plt.get_cmap('Greys_r'))

plt.show()


plt.subplot(121)
pylab.imshow(np.reshape(X_train[0],(dim, dim), 'F').T, cmap=plt.get_cmap('Greys_r'))

#Get activity of image
_, testing_act = nengo.utils.ensemble.tuning_curves(ens, sim, inputs=X_train[0])

testing_rotate = np.dot(testing_act,activity_to_img_weights)

plt.subplot(122)
pylab.imshow(np.reshape(testing_rotate,(dim, dim), 'F').T, cmap=plt.get_cmap('Greys_r'))

plt.show()
inputs: %%tikz --size 600,400
\tikzstyle{neuron}=[circle, draw, minimum size=2 cm,inner sep=5pt, node distance=2cm]

\node () at (0, 4.5) {$l$th layer};
\node () at (4, 4.5) {$l+1$th layer};
\node[neuron] (i1) at (0,  2) {l, k};
\node[neuron] (i2) at (0, -2) {l, k+1};
\node[neuron] (h11) at (4,  3) {l+1, j-1};
\node[neuron] (h12) at (4,  0) {l+1, j};
\node[neuron] (h13) at (4, -3) {l+1, j+1};
\draw[->] (i1) -- (h11);
\draw[->] (i2) -- (h11);
\draw[->, line width=0.5mm] (i1) -- node[above=0.2] {$w^{l}_{j,k}$ } (h12);
\draw[->] (i2) -- (h12);
\draw[->] (i1) -- (h13);
\draw[->] (i2) -- (h13);
#이거 코드는 무시
Given the above code, generate some markdown instructions for it.

targets: 
<table style="display: inline-table; margin-right: 30pt;">
<tbody><tr style="background:#def; text-align:center;">
<td colspan="2"><b>INPUT</b></td>
<td><b>OUTPUT</b></td>
</tr>
<tr style="background:#def; text-align:center;">
<td>A</td>
<td>B</td>
<td>A NAND B</td>
</tr>
<tr style="background:#dfd; text-align:center;">
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
<tr style="background:#dfd; text-align:center;">
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr style="background:#dfd; text-align:center;">
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr style="background:#dfd; text-align:center;">
<td>1</td>
<td>1</td>
<td>0</td>
</tr>
</tbody></table>


$x_1 = 0$, $x_2 = 0$
$ (−2)\times 0+(−2)\times 0+3=(−2)\times 0+(−2)\times 0+3=3 > 0 \rightarrow 1$
$x_1 = 0$, $x_2 = 1$
$ (−2)\times 0+(−2)\times 1+3=(−2)\times 0+(−2)\times 1+3=1 > 0 \rightarrow 1$
$x_1 = 1$, $x_2 = 0$
$ (−2)\times 1+(−2)\times 0+3=(−2)\times 1+(−2)\times 0+3=1 > 0 \rightarrow 1$
$x_1 = 1$, $x_2 = 1$
$ (−2)\times 1+(−2)\times 1+3=(−2)\times 1+(−2)\times 1+3=-1 < 0 \rightarrow 0$

시그모이드를 통과하면 1,1,1,0의 값들로 된다.
디지털 회로에서는 복수개의 NAND 게이트를 조합하면 어떤 디지털 로직이라도 구현 가능하다. 예를 들어 다음 회로는 두 입력 신호의 합과 자릿수를 반환하는 반가산기(half adder) 회로이다.
<img src="https://datascienceschool.net/upfiles/3002b65c9f034818a318ad7f6b09671f.png">
이 퍼셉트론 조합을 보면 4개의 퍼셉트론을 연결하여 XOR 로직을 구현하였음을 알 수 있다.
다계층 퍼셉트론 (MLP: Multi-Layer Perceptrons)

이런 것을 여러 개 그렸을 때 이런 그림이 나온다. 2차 다항식은 차원이 하나 늘어난 것이고 RBF의 경우에는 무한대다.
이왕 히든 레이어 만든 거 여러개 더 만들면 되지 않느냐? 바이너리 클레시피케이션 하는 애다. 아웃풋 레이어.
히든레이어 15개 썼다는 것은 PCA와 같은 개념. 리니어에 시그모이드를 통과하면 리니어가 안 된다. 이 모델에서 선택적으로 15개 쓴 것이다. 1개 쓰는 케이스는 뭘까? 그것은 압축기다. 784개 들어가서 15개 히든으로 쓰고 784개로 아웃풋 나와서 비슷한게 나오는 웨이트를 발견했다면 압축기가 만들어진 것이다. 오토인코더라고 부른다.
보통은 앞단이 엄청 많고 히든은 그거보다 좀 적고 아웃풋은 그거보다 좀 더 적다.

신경망은 퍼셉트론을 여러개 연결한 것으로 다계층 퍼셉트론(MLP: Multi-Layer Perceptrons)이라고도 한다. 신경망에 속한 퍼셉트론은 뉴론(neuron) 또는 노드(node)라고 불린다.
각 계층(layer)은 다음 계층에 대해 적응형 기저 함수의 역할을 한다. 최초의 계층은 입력 계층(input layer), 마지막 계측은 출력 계층(output layer)이라고 하며 중간은 은닉 계층(hidden layer)라고 한다.
<img...
inputs: <hr>

Vaccine effectiveness and &ldquo;herd immunity&rdquo;
&ldquo;Herd immunity&rdquo; has somewhat varying meanings, but: 

&ldquo;A common implication of the term is that the risk of infection among susceptible individuals in a population is reduced by the presence and proximity of immune individuals (this is sometimes referred to as “indirect protection” or a “herd effect”).&rdquo;<sup><a href="#id1">1</a></sup>

Herd immunity depends on

the percent of that population vaccinated (the vaccination rate) and 
the effectiveness of the vaccine.

$$vaccine\ effectiveness \cdot vaccination\ rate = herd\ immunity$$
<hr>

Effectiveness: Measles
The vaccination for measles is categorized in this dataset as measles, which the data dictionary does not describe any further except to say that this field is a count of students who have had two doses of a measles-containing vaccine.
We reached out to Stacy Matthews, the Oregon Public Health Division's immunization school law coordinator to request more comprehensive information on what vaccine this would have been, and she said that this was almost always MMR, but may have been a different vaccine in some cases.
The effectiveness rate of two doses of MMR for measles is 97%.

targets: measles_1 = 0.93
measles_2 = 0.97
inputs: Cell Description
This cell is responsible for building and submitting the Streams applications to the Streams cluster. 
Healthcare Patient Python Topology Application
This cell contains source code for the Python Topology application. As described in the above architecture, this is a Streaming Python application that ingests the patient data from the ingest-physionet topic, performs filtering and analysis on the data, and then sends the data to the Streams view server.

targets: from healthdemo.patientmonitoring_functions import streaming_rpeak
from healthdemo.healthcare_functions import PatientFilter, GenTimestamp, aggregate
from healthdemo.windows import SlidingWindow

def getPatientView(patient_id):
    '''
    Select data of given patient_id, perform analysis and return view.
    
    Parameters
    ----------
    patient_id: int
      patient_id (1-based)
      
    Returns
    -------
    view: topology.View
      view data from Streams server
    '''
    topo = Topology('HealthcareDemo_Patient%d' % (patient_id))

    ## Ingest, preprocess and aggregate patient data
    sample_rate = 125
    patient_data = topo.subscribe('ingest-physionet', schema.CommonSchema.Json) \
                       .map(functions.identity) \
                       .filter(PatientFilter('patient-%d' % (patient_id))) \
                       .transform(GenTimestamp(sample_rate)) \
                       .transform(SlidingWindow(length=sample_rate, trigger=sample_rate-1)) \
                       .transform(aggregate)
                        
    ## Calculate RPeak and RR delta
    patient_data = streaming_rpeak(patient_data, sample_rate, data_label='ECG Lead II')

    ## Create a view of the data
    patient_view = patient_data.view()
    
    submit('ANALYTICS_SERVICE', topo, config)
    return patient_view
    
# Retrieve view for a patient    
patient_view = getPatientView(2)
    
print('DONE')
inputs: 721 expenses reimbursed to parties.

targets: parties = congressperson_list[congressperson_list['party'].isnull()]
parties

party_expenses = data[data['applicant_id'].isin(parties['applicant_id'])]
len(party_expenses)

party_expenses.head()
inputs: "Ancient Codes and Partially Developed Tools"
Please write code following the instructions in jupyter notebook style.

targets: 
### Store data to a pickle file
# saved_filename = '/global/homes/b/bpb/Downloads/20160818_POS_MO_HEfungusonly_V1.pkl'
# with open(output_filename,'w') as f:
#     dill.dump(metatlas_dataset,f)

### Load a pre-existing metatlas dataset  
# metatlas_dataset = ma_data.get_dill_data(saved_filename)

### copy files to $SCRATCH
### You will likely never have to do this, but just in case, here is the code.
# from shutil import copyfile
# scratch = os.environ['SCRATCH']
# for my_group in groups:
#     for my_file in my_group.items:
#         new_path = os.path.join(scratch,'temp_metatlas')
#         if not os.path.isdir(new_path):
#             os.mkdir(new_path)
#         new_file = os.path.join(new_path,os.path.basename(my_file.hdf5_file))
#         copyfile(my_file.hdf5_file, new_file)
#         my_file.hdf5_file = new_file
#         print my_file.hdf5_file

# %matplotlib inline
# dp = reload(dp)
# pickles = ['/global/homes/b/bpb/Downloads/KZ_Avena_Exudate_atlases_and_groups_1/neg_data.pkl',
#           '/global/homes/b/bpb/Downloads/KZ_Avena_Exudate_atlases_and_groups_1/pos_data.pkl',
# '/global/homes/b/bpb/Downloads/KZ_Avena_Uptake_atlases_and_group_2/pos_data.pkl',
# '/global/homes/b/bpb/Downloads/KZ_Avena_Uptake_atlases_and_group_2/neg_data.pkl']
# for p in pickles:
#     plot_location_label = p.split('.')[0]+'/'
#     print plot_location_label
#     if not os.path.exists(plot_location_label):
#         os.makedirs(plot_location_label)
#     metatlas_dataset = ma_data.get_dill_data(p)
#     dp.make_identification_figure(input_dataset = metatlas_dataset, input_fname = p, include_lcmsruns = [],exclude_lcmsruns = ['RootCass','QC','Blank','blank'], output_loc=plot_location_label+'/identification')

######### DO NOT USE #######
# output_filename = '/global/homes/b/bpb/Downloads/20160531_KBL_C18_Vio_cells_384_Q_1_to_4.pkl'
# data = dp.get_data_for_groups_and_atlas(groups,myAtlas,output_filename)
############################

######### DO NOT USE #######
### THIS STILL NEEDS SOME REPAIRS ###
#...
inputs: I am working on the file "Euler/euler_1-10.ipynb".
The first task is:
10: Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Can you write Python code for it?

targets: 
np.sum(primesfrom2to(2000000))
inputs: "Animation
Here's a draw function we can use to animate the results."
Please write code following the instructions in jupyter notebook style.

targets: 
from matplotlib.pyplot import plot

xlim = results.x.min(), results.x.max()
ylim = results.y.min(), results.y.max()

def draw_func(t, state):
    plot(state.x, state.y, 'bo')
    decorate(xlabel='x position (m)',
             ylabel='y position (m)',
             xlim=xlim,
             ylim=ylim)

# animate(results, draw_func)
inputs: Beta function contributions to the partial wave matrices (w/ factor of -3/2 included)

targets: def bMy1s1(l1, l3):
    return -(3/2)*My1s1(*betafunctions(l1, l3))
def bMy1s0(l1, l3):
    return -(3/2)*My1s0(*betafunctions(l1, l3))
def bMy0s1(l1, l3):
    return -(3/2)*My0s1(*betafunctions(l1, l3))
def bMy0s0(l1, l3):
    return -(3/2)*My0s0(*betafunctions(l1, l3))
inputs: # Calculate the partial derivative of cost with respect to m while treating c as a constant.
def gradient_descent_m(x, y, m, c):
  return -2.0 * np.sum(x * (y - m * x - c))

# Calculate the partial derivative of cost with respect to c while treating m as a constant.
def gradient_descent_c(x, y, m , c):
  return -2.0 * np.sum(y - m * x - c)

eta = 0.0001
g_m, g_c = 1.0, 1.0
change = True

# Iterate the partial derivatives until the outcomes do not change
while change:
  g_m_new = g_m - eta * gradient_descent_m(setosa_data[2], setosa_data[3], g_m, g_c)
  g_c_new = g_c - eta * gradient_descent_c(setosa_data[2], setosa_data[3], g_m, g_c)
  if g_m == g_m_new and g_c == g_c_new:
    change = False
  else:
    g_m, g_c = g_m_new, g_c_new
Given the above code, generate some markdown instructions for it.

targets: 
Use gradient descent
Gradient Descent is an approximation technique. To utilize this approximation technique, we guess the value that we wish to approximate and iteratively improve that guess.