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 tweepy | |
| import os | |
| from typing import List, Optional | |
| class TwitterClient: | |
| def __init__( | |
| self, | |
| consumer_key: str, | |
| consumer_secret: str, |
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 jax | |
| import jax.numpy as jnp | |
| def ou_process(key, steps, dt, mu, tau, sigma): | |
| """ Generate an Ornstein-Uhlenbeck process sample. """ | |
| ou_init = jnp.zeros((steps + 1, )) | |
| noise = jax.random.normal(key, (steps,)) | |
| def ou_step(t, val): | |
| dx = (-(val[t-1]-mu)/tau * dt | |
| + sigma*jnp.sqrt(2/tau)* |
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
| def binary_cross_entropy(y_true, y_pred): | |
| y_true = np.append(1 - y_true, y_true, axis=1) | |
| y_pred = np.append(1 - y_pred, y_pred, axis=1) | |
| bce = -(y_true * np.log(y_pred)).sum(axis=1) | |
| return bce |
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
| def train_logistic_regression(n, d, n_epoch, batch_size, b_init, l_rate): | |
| # Generate the data for a coefficient vector & init progress tracker! | |
| data_loader = DataLoader(n, d, batch_size, binary=True) | |
| b_hist, func_val_hist, param_error, acc_hist = [], [], [], [] | |
| # Get the coefficients as solution to optimized sklearn function | |
| logreg = LogisticRegression(penalty='none', solver='lbfgs', multi_class='multinomial') | |
| logreg.fit(data_loader.X, data_loader.y) | |
| norm_coeff = np.linalg.norm(logreg.coef_.ravel()) |
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 numpy as np | |
| from sklearn.linear_model import LogisticRegression | |
| class DataLoader(object): | |
| # Small class object for dual number - Two real numbers (real & dual part) | |
| def __init__(self, n, d, batch_size, binary=False): | |
| self.total_dim = d + 1 | |
| self.X, self.y = self.generate_regression_data(n, d, binary) | |
| # Set batch_id for different indices |