# Installation ``` conda install -c conda-forge py2cytoscape pip install -U handout ``` ## Prerequisites In addition to the RCy3 package, you will need the latest version of Cytoscape, which can be downloaded from http://www.cytoscape.org/download.php. Simply follow the installation instructions on screen. ## Getting started First, launch Cytoscape and keep it running whenever using py2cytoscape. Confirm that you have everything installed and running: """ import handout doc = handout.Handout('html_documents/py/differentially-expressed-genes') import io from contextlib import redirect_stdout from py2cytoscape import cyrest HOST = "localhost" cytoscape = cyrest.cyclient(host=HOST) f = io.StringIO() with redirect_stdout(f): cytoscape.status() cytoscape.version() s = f.getvalue() doc.add_text(s) doc.show() """
""" # IN-STK5000 Reproducibility assignment """ import handout # Tool for generating report-type documents import matplotlib.pyplot as plt import numpy as np import pandas as pd doc = handout.Handout('output') # handout: exclude """ Load the dataset. We used the Car Evaluation dataset from https://archive.ics.uci.edu/ To use the dataset for ML algorithms all variables are changed to numeric variables by label-encoder preprocessing. """ features = ["Buying", "Maintenaince", "Doors", "Persons", "Luggage", "Safety"] target = 'Class' df = pd.read_csv( 'https://archive.ics.uci.edu/ml/machine-learning-databases/car/car.data', names=features + [target]) doc.add_text(df.head()) # handout: exclude doc.show() # handout: exclude from sklearn import preprocessing # handout: exclude le = preprocessing.LabelEncoder() # handout: exclude df = df.apply(le.fit_transform) # handout: exclude """ Some setup code for the KNN classifier; data splitting and scaling:
""" # Python Handout Turn Python scripts into handouts with Markdown comments and inline figures. An alternative to Jupyter notebooks without hidden state that supports any text editor. """ import handout import matplotlib.pyplot as plt import numpy as np """Start your handout with an output directory.""" doc = handout.Handout('output') """ ## Markdown comments Comments with triple quotes are converted to text blocks. Text blocks support [Markdown formatting][1], for example: - Headlines - Hyperlinks - Inline `code()` snippets - **Bold** and *italic* [1]: https://commonmark.org/help/ """ """ ## Add text and variables
#### Underflow Multiplying lots of probabilities can result in floating-point underflow. For this, we can take advantage of a property of the $\log$ function: $\log(xy) = \log(x) + \log(y) $. So, we take the $\log$ of each probability and *sum* them together instead of multiply. # Part 4 """ from operator import add from random import random import handout from pyspark.sql import SparkSession spark = SparkSession.builder.getOrCreate() doc = handout.Handout("handout") """## Word Count""" lines = spark.read.text("./input/words.txt").rdd.map(lambda r: r[0]) counts = lines.flatMap(lambda x: x.split(" ")).map(lambda x: (x, 1)).reduceByKey(add) output = counts.collect() for word, count in output: doc.add_text("%s: %i" % (word, count)) doc.show() """## Pi Estimation""" partitions = 2
import builtins # handout: exclude import io # handout: exclude import handout # handout: exclude import os # handout: exclude import sys # handout: exclude sys.stdout = io.StringIO() # handout: exclude stdoutput = '' # handout: exclude fname = os.path.basename(__file__).replace('.py', '') # handout: exclude doc = handout.Handout(fname) # handout: exclude """ # Introduction to Python ## Using the tdt Package This primer walks through installing the tdt Python package, shows how to convert existing Matlab code to Python, and highlights some of the differences when working in Python. ## Installation 1. Make sure that you have [**Miniconda**](https://docs.conda.io/en/latest/miniconda.html) or [**Anaconda**](https://www.anaconda.com/distribution/) installed. You can choose the Python 3.7 64-bit version for your operating system (Linux, Windows, or OS X). 2. **Open a terminal** (on Windows, `cmd`, not Powershell) and type: ``` pip install tdt ``` 4. **Done**! ## Converting Existing Matlab Code to Python The tdt Python library for reading TDT data is one-to-one compatible with the Matlab library, however the function names and parameter names are different. ### Extracting Block Data
import numpy as np import matplotlib.pyplot as plt import tensorflow as tf import handout doc = handout.Handout('docs/ntk') """ ## Neural tangent kernel definition $$ k(x, x') = \langle\frac{\partial f_{\theta}(x)}{\partial \theta}, \frac{\partial f_{\theta}(x')}{\partial \theta} \rangle $$ NN dynamics $$ \frac{d f_{\theta(t)}(x)}{dt} = - K(t) \cdot (f_{\theta(t)}(x)) - y) $$ Infinite limit of NTK $$ \text{future talk...} $$ """ n = 500 # using inputs with the same norm! seems important? # (should try with shattered grads) t = np.linspace(-np.pi, np.pi, n).reshape((-1, 1)) x = np.concatenate([np.cos(t), np.sin(t)], axis=1)
""" # 마크다운이 포함 된, Python 스크립트를 HTML 형태의 핸드아웃 페이지로 변환해 주는 # 패키지를 소개해 드립니다. # https://github.com/danijar/handout """ print(__doc__) import handout import matplotlib.pyplot as plt import numpy as np # DESTIN_DIR = './handout_doc/' # Root Sub_folder DESTIN_DIR = 'handout_doc' # Sub_folder """ Start your handout with an output directory """ # doc = handout.Handout('/tmp/handout') doc = handout.Handout(DESTIN_DIR) """ Print text and Variables. """ for index in range(3): doc.add_text(f'Interation ... {index}') doc.show() """ Insert matplotlib figure """ fig, ax = plt.subplots(1,1, figsize=(4,3)) fig.tight_layout() doc.add_figure(fig) doc.show()
# original code from http://katbailey.github.io/post/gaussian-processes-for-dummies/ # but somewhat modified import numpy as np import matplotlib.pyplot as pl import handout doc = handout.Handout('docs/gp') """ ## GPs definition $$ f \sim \mathcal N(\mu, \Sigma),\quad\Sigma(x, x') = e^{-\frac{1}{2}(x-x')^2} $$ mean update $$ m_D(x) = m(x) + \Sigma(X, x)^T\Sigma^{-1}(f-m) $$ var update $$ k_D(x, x') =k(x, x') - \Sigma(X, x)^T \Sigma^{-1} \Sigma(X, x') $$ posterior $$ f^{* }|f \sim \mathcal N(m_D, k_D) $$
# Installation ``` conda install -c conda-forge py2cytoscape pip install -U handout ``` ## Prerequisites In addition to the RCy3 package, you will need the latest version of Cytoscape, which can be downloaded from http://www.cytoscape.org/download.php. Simply follow the installation instructions on screen. ## Getting started First, launch Cytoscape and keep it running whenever using py2cytoscape. Confirm that you have everything installed and running: """ import handout doc = handout.Handout('html_documents/py/stringApp') import io from contextlib import redirect_stdout from py2cytoscape import cyrest HOST = "localhost" cytoscape = cyrest.cyclient(host=HOST) f = io.StringIO() with redirect_stdout(f): cytoscape.status() cytoscape.version() s = f.getvalue() doc.add_text(s) doc.show() """
""" # Python Handout Turn Python scripts into handouts with Markdown comments and inline figures. An alternative to Jupyter notebooks without hidden state that supports any text editor. """ import handout import matplotlib.pyplot as plt import numpy as np """Start your handout with an output directory.""" doc = handout.Handout('./output') """ ## Markdown comments Comments with triple quotes are converted to text blocks. Text blocks support [Markdown formatting][1], for example: - Headlines - Hyperlinks - Inline `code()` snippets - **Bold** and *italic* - LaTeX math $f(x)=x^2$ [1]: https://commonmark.org/help/ """ """ ## Add text and variables Write to our handout using the same syntax as Python's `print()`: """ for index in range(3): doc.add_text('Iteration', index) doc.show()
""" This demonstrates some simple ways to encode time so that models can make sense of it. The problem at hand is prediction of web traffic on various wikipedia pages. The features we will use include: * Lagged values for traffic * Time of day expressed as continuous variables * Day of week expressed as continuous variables * Day of week expressed as one-hot variables * Page URL """ import handout import os os.mkdir("handouts") # handout: exclude doc = handout.Handout("handouts/time") # handout: exclude doc.show() # handout: exclude
# Installation ``` conda install -c conda-forge py2cytoscape pip install -U handout ``` ## Prerequisites In addition to the RCy3 package, you will need the latest version of Cytoscape, which can be downloaded from http://www.cytoscape.org/download.php. Simply follow the installation instructions on screen. ## Getting started First, launch Cytoscape and keep it running whenever using py2cytoscape. Confirm that you have everything installed and running: """ import handout doc = handout.Handout('html_documents/py/basic-data-visualization') import io from contextlib import redirect_stdout from py2cytoscape import cyrest cytoscape = cyrest.cyclient() f = io.StringIO() with redirect_stdout(f): cytoscape.status() cytoscape.version() s = f.getvalue() doc.add_text(s) doc.show() """ # Basic Data Visualization
import handout doc = handout.Handout('handout_output/ex00_original_after', 'ex00_original_after') """ # 封装集合-代码原型-重构后 --- """ class Foo: def __init__(self): """将列表属性私有,保证用户无法从外部进行访问""" self.__items = [] def add(self, item): """ 类内部的 add() 函数依然可以使用私有属性 __items :param item: 要添加的元素 :return: """ self.__items.append(item) @property def items(self): """ 只读属性,不允许用户从外部修改列表元素 :return: 列表属性 """ return tuple(self.__items)
import handout import numpy as np doc = handout.Handout('output/full_width') # Add some images. for _ in range(16): image = np.ones((64, 64, 3)) * np.random.uniform(0, 1, 3) doc.add_image((255 * image).astype(np.uint8), width=0.24) # Unset document width. doc.add_html('<style>article { max-width: none; }</style>') doc.show()
def test_handout_on_title_arg_inserts_title(tmp_path): output = handout.Handout(directory=tmp_path, title='This string')._generate(source='') assert '<title>This string</title>' in output
import handout doc = handout.Handout('handout_output/ex00_original_before', 'ex00_original_before') """ # 封装集合-代码原型-重构前 --- """ class Foo: def __init__(self): """定义了一个列表属性""" self.items = [] def add(self, item): """ 定义了 add() 函数用来向列表中添加新的元素 :param item: 要添加的元素 :return: """ self.items.append(item) # 客户端 foo = Foo() foo.add('a') # 希望客户端的操作方式 print(foo.items) # 输出列表中所有的元素 foo.items.append('b') # 有安全隐患的操作方式,绕过自定义的 add() 函数 print(foo.items) # 输出列表中所有的元素 """ --- domkn @ 2019-08-12 """
Ch + I + Cg + NX S = I + Net lending | W + t' + P Always a mystery: | S - I = NX = Net lending X - AX (See Open Economy identitites below) ``` """ """ ## Preparations """ import pandas as pd import handout doc = handout.Handout("handout") # handout: exclude """ `eq` function will check identities considering some rounding error. """ def eq(df1, df2, precision=0.5) -> bool: """Compare two dataframes by element with precision margin.""" return ((df1 - df2).abs() < precision).all() """ Read dataset from file. """ df = pd.read_csv("data/sna.csv", index_col=0)
""" # Python Handout Turn Python scripts into handouts with Markdown comments and inline figures. An alternative to Jupyter notebooks without hidden state that supports any text editor. """ import handout import matplotlib.pyplot as plt import numpy as np """Start your handout with an output directory.""" doc = handout.Handout('output/start') """ ## Markdown comments Comments with triple quotes are converted to text blocks. Text blocks support [Markdown formatting][1], for example: - Headlines - Hyperlinks - Inline `code()` snippets - **Bold** and *italic* - LaTeX math $f(x)=x^2$ [1]: https://commonmark.org/help/ """ """ ## Add text and variables