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
| # compare treatment vs control, individual animals | |
| import numpy as np | |
| import pymc as pm | |
| import arviz as az | |
| import matplotlib.pyplot as plt | |
| # === REPLACE these with your 10 raw measurements per group === | |
| control = np.array([120, 118, 122, 121, 119, 117, 123, 116, 120, 119]) | |
| treatment = np.array([125, 128, 130, 127, 126, 124, 129, 125, 127, 126]) | |
| with pm.Model() as model: |
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 pandas as pd | |
| df = pd.DataFrame( | |
| { | |
| "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], | |
| "B": ["one", "one", "two", "three", "two", "two", "one", "three"], | |
| "C": np.random.randn(8), | |
| "D": np.random.randn(8), | |
| } | |
| ) |
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 dataframe with three columns | |
| df = pd.DataFrame({'a': [1, 2, 3, 4, 5], | |
| 'b': [5, 4, 3, 2, 1], | |
| 'c': ['A', 'B', 'C', 'D', 'E']}) | |
| df.assign(**{col: lambda df_, col=col: df[col]*2 for col in ['a', 'b']}) | |
| # a b c | |
| # 0 2 10 A | |
| # 1 4 8 B |
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
| # the query may be passed by the user directly | |
| # prepare query scaffold (e.g. '(R1)C1CC(R3)CCC1(R2)') | |
| # scaffold = indigo.loadQueryMoleculeFromFile(r"D:/tmp/query_mol.mol") | |
| scaffold = indigo.loadQueryMolecule('C1%91CCC%92CC%931.[*:1]%91.[*:2]%93.[*:3]%92 |$;;;;;;_R1;_R2;_R3$|') | |
| # init decomposition | |
| deco = indigo.createDecomposer(scaffold) | |
| # load molecule | |
| # if Br was H it would not match, even with implicit hydrogen atoms | |
| # hence need to repeat with multiple queries with R groups removed | |
| mol = indigo.loadMolecule('NC1CC(Br)CCC1(O)') # |
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
| ##### method 1, builtin highlighting | |
| # experiment with substructure matching (when tautomers, show the scaffold as in the target) | |
| indigo = Indigo() | |
| renderer = IndigoRenderer(indigo) | |
| indigo.setOption("render-output-format", "png") | |
| smiles1 = 'CCC(O)=CCCCC' | |
| mol1 = indigo.loadMolecule(smiles1) | |
| smiles2 = 'CC(=O)CC' | |
| mol2 = indigo.loadQueryMolecule(smiles2) | |
| flag = 'TAU' # other flags 'RES', 'TAU', 'TAU INCHI', 'TAU RSMARTS' |
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
| # for more details see | |
| # https://huggingface.co/sentence-transformers/multi-qa-MiniLM-L6-cos-v1 | |
| # compute embeddings with sentencepiece | |
| from sentence_transformers import SentenceTransformer, util | |
| docs = ["Around 9 Million people live in London", "This is nice"] | |
| #Load the model | |
| model = SentenceTransformer('sentence-transformers/multi-qa-MiniLM-L6-cos-v1') |
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
| # map values in pyspark | |
| import pyspark.sql.functions as F | |
| from itertools import chain | |
| data = [['a', 1], ['b', 2], ['a', 3], ['d', 4]] | |
| data = spark.createDataFrame(data, schema=['name', 'val']) | |
| data.show() | |
| # create mapping column | |
| mapping = {'a': 'hello a', 'b': 'hello b', 'c': 'hello c'} |
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
| spark = ( | |
| SparkSession.builder | |
| .appName('learn') | |
| # .config('spark.sql.shuffle.partitions', 10) | |
| # .config('spark.default.parallelism', 10) | |
| # .config('spark.executor.memory', '1g') | |
| # .config('spark.driver.memory', '1g') | |
| # .config('spark.executor.instances', 1) | |
| #.config('spark.executor.cores', 2) | |
| .getOrCreate() |
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
| # create dataframe from dictionary, without a schema | |
| df = [{'one': 1, 'two': [1,2,3]}, {'one': 101}] | |
| df = spark.createDataFrame(df) | |
| df.printSchema() | |
| # root | |
| # |-- one: long (nullable = true) | |
| # |-- two: array (nullable = true) | |
| # | |-- element: long (containsNull = true) | |
| df.show() | |
| # |one| two| |
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, create struct | |
| import pyspark.sql.functions as F | |
| df = [[1, 'mplah', 'gogo'], [2, 'mplah2', 'gogo2'], [3, 'mplah3', 'gogo3']] | |
| df = spark.createDataFrame(df, schema=['x', 'y', 'z']) | |
| res = df.select(F.col('x'), F.struct(F.col('x').alias('_x'), F.col('y').alias('_y')).alias('_xy')) | |
| res.show() | |
| # | x| _xy| | |
| # +---+-----------+ | |
| # | 1| {1, mplah}| | |
| # | 2|{2, mplah2}| |
NewerOlder