Skip to content

Instantly share code, notes, and snippets.

@Sandy4321
Sandy4321 / lda.py
Created May 27, 2018 20:04 — forked from amintos/lda.py
LDA with Gibbs Sampling in Python
import random
def dirichlet(alpha):
"""Sample dirichlet-distributed vector from Dir(alpha)"""
s = [random.gammavariate(a, 1) for a in alpha]
norm = sum(s)
return [d / norm for d in s]
@Sandy4321
Sandy4321 / tf512.py
Created May 27, 2018 20:03 — forked from amintos/tf512.py
Simple string encryption and decryption in pure Python using Threefish-512. No guarantee this implementation is 100% correct!
#
# Simple Pure-Python Threefish-512 Encryption.
# (No guarantee that this implementation is 100% correct!)
#
# Use encrypt(text, key) and decrypt(text, key) for string encryption.
#
# The cipher operates in CBC mode with a random tweak value.
#
from StringIO import StringIO
@Sandy4321
Sandy4321 / btm.py
Created May 27, 2018 19:39 — forked from amintos/btm.py
Bi-term Topic Model implementation in pure Python
"""
Bi-Term Topic Model (BTM) for very short texts.
Literature Reference:
Xiaohui Yan, Jiafeng Guo, Yanyan Lan, and Xueqi Cheng:
"A biterm topic model for short texts"
In Proceedings of WWW '13, Rio de Janeiro, Brazil, pp. 1445-1456.
ACM, DOI: https://doi.org/10.1145/2488388.2488514
This module requires pre-processing of textual data,
import pandas as pd
from collections import Counter
import tensorflow as tf
from tffm import TFFMRegressor
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
import numpy as np
# Loading datasets'
@Sandy4321
Sandy4321 / TDA_resources.md
Created November 29, 2016 23:51 — forked from calstad/TDA_resources.md
List of resources for TDA

Quick List of Resources for Topological Data Analysis with Emphasis on Machine Learning

This is just a quick list of resourses on TDA that I put together for @rickasaurus after he was asking for links to papers, books, etc on Twitter and is by no means an exhaustive list.

Survey Papers

Both Carlsson's and Ghrist's survey papers offer a very good introduction to the subject

Other Papers and Web Resources

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
protected override void OnBarUpdate()
{
if (Historical) return;Enumerable.Range(0,14).ToList().ForEach(i =>DrawText((CurrentBar+i).ToString(),"\u0CA0_\u0CA0",0, i % 2 == 0 ? (Close[0]+TickSize) + (TickSize*i) : (Close[0]-TickSize)-(TickSize*i),i % 2 == 0 ? Color.FromArgb(255 - (i*15),0, 0,255):Color.FromArgb(255 - (i*15),255, 0,0)));
}
@Sandy4321
Sandy4321 / gist:d5e65cd4e8f371be6853c816c6cd87c2
Created September 4, 2016 23:46 — forked from DexterHaslem/gist:3085590
NinjaTrader create Indicator type @ runtime
using System;
using System.ComponentModel;
namespace NinjaTrader.Indicator
{
[Description("f")]
public class derp : Indicator
{
IndicatorBase myEMA;
protected override void Initialize()
@Sandy4321
Sandy4321 / df.py
Created August 31, 2016 16:59 — forked from rxin/df.py
DataFrame simple aggregation performance benchmark
data = sqlContext.load("/home/rxin/ints.parquet")
data.groupBy("a").agg(col("a"), avg("num")).collect()
@Sandy4321
Sandy4321 / Spark Dataframe Cheat Sheet.py
Created August 10, 2016 20:03 — forked from evenv/Spark Dataframe Cheat Sheet.py
Cheat sheet for Spark Dataframes (using Python)
# A simple cheat sheet of Spark Dataframe syntax
# Current for Spark 1.6.1
# import statements
from pyspark.sql import SQLContext
from pyspark.sql.types import *
from pyspark.sql.functions import *
#creating dataframes
df = sqlContext.createDataFrame([(1, 4), (2, 5), (3, 6)], ["A", "B"]) # from manual data