def createPolyFit(coefs): # create partical function partialFit = part(polyFit, coefs) return partialFit
def __init__(self, vocabulary_hash, vocabulary_size, embedding_size, sentence_size, memory_size, hops=3, weight_tying_scheme=ADJACENT): # Model Configurations. super().__init__() self.vocabulary_hash = vocabulary_hash self.vocabulary_size = vocabulary_size self.embedding_size = embedding_size self.sentence_size = sentence_size self.memory_size = memory_size self.hops = hops self.weight_tying_scheme = weight_tying_scheme # Validate Configurations. assert self.weight_tying_scheme in self.WEIGHT_TYING_SCHEMES, ( 'Available weight tying schemes are: {schemes}' .format(schemes=self.WEIGHT_TYING_SCHEMES) ) # Memories. self.A_memories = nn.ModuleList() self.C_memories = nn.ModuleList() for i in range(hops): # Check if there's any previous memory layer. y = i > 0 A_prev = self.A_memories[i-1] if y else None C_prev = self.C_memories[i-1] if y else None # 2.2.1. Adjacent Weight Tying if self.tied_adjacent: A_embedding = C_prev.embedding if y else None C_embedding = None A_temporal_embedding = C_prev.temporal_embedding if y else None C_temporal_embedding = None # 2.2.2. Layer-Wise Weight Tying elif self.tied_layers: A_embedding = A_prev.embedding if y else None C_embedding = C_prev.embedding if y else None A_temporal_embedding = A_prev.temporal_embedding if y else None C_temporal_embedding = C_prev.temporal_embedding if y else None # No Weight Tying else: A_embedding = None C_embedding = None A_temporal_embedding = None C_temporal_embedding = None self.A_memories.append(Memory( self.vocabulary_size, self.embedding_size, self.sentence_size, self.memory_size, embedding=A_embedding, temporal_embedding=A_temporal_embedding, )) self.C_memories.append(Memory( self.vocabulary_size, self.embedding_size, self.sentence_size, self.memory_size, embedding=C_embedding, temporal_embedding=C_temporal_embedding )) # Affine layer & Query embedding layer. if self.tied_adjacent: deepest_embedding = self.C_memories[-1].embedding first_embedding = self.A_memories[0].embedding self.linear = part(F.linear, weight=deepest_embedding.weight) self.query_embedding = first_embedding else: self.linear = nn.Linear(self.embedding_size, self.vocabulary_size) self.query_embedding = nn.Embedding( self.vocabulary_size, self.embedding_size )
def simple_filter(signal: Signal, cutoff_freq: float, type: str) -> Signal: # cutoff_freq - Hz filtered_data = simple_filter_raw(signal.data, cutoff_freq, signal.frequency, type) return Signal(signal.info, filtered_data) # TODO: pretty sure the amplitude changes after filtering, # so the new info could be incorrect lowpass_filter_sig = ['cutoff_freq'] lowpass_default_params = m(cutoff_freq=10 * Hz) # lowpass_filter : (Signal, cutoff_freq: float) -> float lowpass_filter = part(simple_filter, type='low') lowpass_tr = Trans( 'Lowpass filter', lowpass_filter, lowpass_filter_sig, ) highpass_filter_sig = ['cutoff_freq'] highpass_default_params = m(cutoff_freq=0.05 * Hz) # highpass_filter : (Signal, float) -> float highpass_filter = part(simple_filter, type='high') highpass_tr = Trans('Highpass filter', highpass_filter, highpass_filter_sig) ###################################################################### # IMPORTANT - DON'T DELETE THESE CLASSES WITHOUT READING THE COMMENT # ######################################################################
eff_res[ACTIONS] ) # so we can process actions emitted during updating, if any for command in eff_res[EFFECTS]: state, eff_res = run_eff(handle(state, command), signal_id=current_signal_id) current_signal_id = eff_res[SIGNAL_ID] return state from debug_util import varied_dict_to_str as dts s = lambda f, g: lambda x: g(f(x)) pd = ch(dts, print) np = ch(part(map, str), part(str.join, '\n'), print) nps = ch(sorted, np) from typing import NamedTuple from collections import OrderedDict # from sumtype import sumtype NodeId = NamedTuple('NodeId', [('id_', int)]) InputSlotId = NamedTuple('InputSlotId', [('node_id', NodeId), ('ix', int)]) OutputSlotId = NamedTuple('OutputSlotId', [('node_id', NodeId), ('ix', int)]) node_names = {NodeId(0): 'x', NodeId(1): 'y', NodeId(2): 'z'} node_slot_ns = {NodeId(0): (1, 2), NodeId(1): (2, 0), NodeId(2): (0, 1)}