from microprediction import MicroWriter from microprediction.samplers import exponential_bootstrap import time from pprint import pprint from microprediction.config_private import OXEATE_MAMMAL # Enters all the z2 streams WRITE_KEY = OXEATE_MAMMAL ANIMAL = MicroWriter.animal_from_key(WRITE_KEY) print(ANIMAL, flush=True) STOP_LOSS = 250. if __name__ == "__main__": mw = MicroWriter(write_key=WRITE_KEY) LONG = '~' + str(mw.DELAYS[-1]) SHORT = '~' + str(mw.DELAYS[0]) # Give up if things are going badly ... do it nicely for _ in range(5): mw.cancel_worst_active(stop_loss=STOP_LOSS, num=1) time.sleep(1) for name in mw.get_streams(): if 'z2~' in name and (LONG in name or SHORT in name): num = mw.num_predictions z11 = '~'.join(['z1', name.split('~')[1], name.split('~')[3]]) z12 = '~'.join(['z1', name.split('~')[2], name.split('~')[3]]) lagged1 = mw.get_lagged_values(z11) lagged2 = mw.get_lagged_values(z12) if len(lagged1) > 10:
# 1. Grab the Github secrets try: # For this script to work you need to create four separate GitHub secrets # called WRITE_KEY_1 WRITE_KEY_2 WRITE_KEY_3 and WRITE_KEY_4 # The idea is that this way you get 900 samples instead of 225 WRITE_KEYS = [os.environ.get('WRITE_KEY_' + str(i + 1)) for i in range(4)] assert len(WRITE_KEYS) == 4, 'Need four write keys to make the syndicate' except: # Or one secret called WRITE_KEY or WRITE_KEYS with them comma separated WRITE_KEYS_comma_sep = os.environ.get('WRITE_KEYS') or os.environ.get( 'WRITE_KEY') WRITE_KEYS = WRITE_KEYS_comma_sep.split(',') print('Copula syndicate is firing up.') for write_key in WRITE_KEYS: animal = MicroWriter.animal_from_key(write_key) print(animal) # 2. Pick a copula VINES = [ 'center', 'regular', 'direct' ] # See https://sdv.dev/Copulas/tutorials/03_Multivariate_Distributions.html#Vine-Copulas VINE_TYPE = random.choice( VINES ) # Perhaps you want to fix this choice. This way we get lots of plots. # 3. (Optional) Set the URL of your repo so that others can learn from it REPO = 'https://github.com/microprediction/microactors-plots/blob/master/fit.py' # <--- Change your username PLOTS_PATH = os.path.dirname( os.path.realpath(__file__)) + os.path.sep + 'gallery'
from microprediction import MicroWriter import numpy as np from pprint import pprint import matplotlib.pyplot as plt import random import time import warnings warnings.filterwarnings('ignore') from copulas.multivariate import GaussianMultivariate import pandas as pd # Grab the Github secret import os WRITE_KEY = os.environ.get('WRITE_KEY') # <-- You need to add a Github secret ANIMAL = MicroWriter.animal_from_key(WRITE_KEY) # <-- Your nom de plume REPO = 'https://github.com/microprediction/microactors/blob/master/fit.py' # <--- Change your username print('This is ' + ANIMAL + ' firing up') STOP_LOSS = 25 # <--- Governs when we give up on a stream/horizon # Get historical data, fit a copula, and submit def fit_and_sample(lagged_zvalues: [[float]], num: int, copula=None): """ Example of creating a "sample" of future values lagged_zvalues: [ [z1,z2,z3] ] distributed N(0,1) margins, roughly copula : Something from https://pypi.org/project/copulas/ returns: [ [z1, z2, z3] ] representative sample Swap out this function for whatever you like.
from microprediction import MicroWriter import time from pprint import pprint import numpy as np # This example illustrates how easy it is to enter z1~ streams # For a video explanation of z1 streams and see https://www.linkedin.com/feed/update/urn:li:activity:6696569137365430272/ # See https://www.linkedin.com/pulse/short-introduction-z-streams-peter-cotton-phd/ for an explanation of z-streams. # You need to set a write key. # Supplying a URL to your repository is optional. # This will do is make your position on the leaderboards clickable and direct people to your work. # You can alternatively provide your personal homepage or LinkedIn profile WRITE_KEY = DODDLE_MAMMAL ANIMAL = MicroWriter.animal_from_key(DODDLE_MAMMAL) REPO = 'https://github.com/microprediction/microprediction/blob/master/crawler_alternatives/' + ANIMAL.lower( ).replace(' ', '_') + '.py' # We simply loop over all z1~ streams # These streams are approximately normally distributed. # We enter N(0,1) distributed samples so as to try to take advantage of algorithms # which accidentally submit distributional predictions far from this. # This code could be run as a cron job or scheduled task at PythonAnywhere, for example def jiggle(): return 0.001 * np.random.randn() if __name__ == "__main__":