How to use _reset_class method in tempest

Best Python code snippet using tempest_python

SplineInterpolationMethod.py

Source:SplineInterpolationMethod.py Github

copy

Full Screen

...17 xe=bbox[1], s=s)18 if data[-1] == 1:19 data = self._reset_nest(data)20 self._data = data21 self._reset_class()22 @staticmethod23 def validate_input(x, y, w, bbox, k, s, ext, check_finite):24 x, y, bbox = np.asarray(x), np.asarray(y), np.asarray(bbox)25 if w is not None:26 w = np.asarray(w)27 if check_finite:28 w_finite = np.isfinite(w).all() if w is not None else True29 if (not np.isfinite(x).all() or not np.isfinite(y).all() or30 not w_finite):31 raise ValueError("x and y array must not contain "32 "NaNs or infs.")33 if s is None or s > 0:34 if not np.all(diff(x) >= 0.0):35 raise ValueError("x must be increasing if s > 0")36 else:37 if not np.all(diff(x) > 0.0):38 raise ValueError("x must be strictly increasing if s = 0")39 if x.size != y.size:40 raise ValueError("x and y should have a same length")41 elif w is not None and not x.size == y.size == w.size:42 raise ValueError("x, y, and w should have a same length")43 elif bbox.shape != (2,):44 raise ValueError("bbox shape should be (2,)")45 elif not (1 <= k <= 5):46 raise ValueError("k should be 1 <= k <= 5")47 elif s is not None and not s >= 0.0:48 raise ValueError("s should be s >= 0.0")49 try:50 ext = _extrap_modes[ext]51 except KeyError:52 raise ValueError("Unknown extrapolation mode %s." % ext)53 return x, y, w, bbox, ext54 @classmethod55 def _from_tck(cls, tck, ext=0):56 self = cls.__new__(cls)57 t, c, k = tck58 self._eval_args = tck59 self._data = (None, None, None, None, None, k, None, len(t), t,60 c, None, None, None, None)61 self.ext = ext62 return self63 def _reset_class(self):64 data = self._data65 n, t, c, k, ier = data[7], data[8], data[9], data[5], data[-1]66 self._eval_args = t[:n], c[:n], k67 if ier == 0:68 pass69 elif ier == -1:70 self._set_class(InterpolatedUnivariateSpline)71 def _set_class(self, cls):72 self._spline_class = cls73 if self.__class__ in (UnivariateSpline, InterpolatedUnivariateSpline):74 self.__class__ = cls75 else:76 pass77 def _reset_nest(self, data, nest=None):78 n = data[10]79 if nest is None:80 k, m = data[5], len(data[0])81 nest = m+k+182 else:83 if not n <= nest:84 raise ValueError("`nest` can only be increased")85 t, c, fpint, nrdata = [np.resize(data[j], nest) for j in86 [8, 9, 11, 12]]87 args = data[:8] + (t, c, n, fpint, nrdata, data[13])88 data = dfitpack.fpcurf1(*args)89 return data90 def set_smoothing_factor(self, s):91 data = self._data92 if data[6] == -1:93 warnings.warn('smoothing factor unchanged for'94 'spline with fixed knots')95 return96 args = data[:6] + (s,) + data[7:]97 data = dfitpack.fpcurf1(*args)98 if data[-1] == 1:99 data = self._reset_nest(data)100 self._data = data101 self._reset_class()102 def __call__(self, x, nu=0, ext=None):103 x = np.asarray(x)104 if x.size == 0:105 return array([])106 if ext is None:107 ext = self.ext108 else:109 try:110 ext = _extrap_modes[ext]111 except KeyError:112 raise ValueError("Unknown extrapolation mode %s." % ext)113 return fitpack.splev(x, self._eval_args, der=nu, ext=ext)114 def get_knots(self):115 data = self._data116 k, n = data[5], data[7]117 return data[8][k:n-k]118 def get_coeffs(self):119 data = self._data120 k, n = data[5], data[7]121 return data[9][:n-k-1]122 def get_residual(self):123 return self._data[10]124 def integral(self, a, b):125 return dfitpack.splint(*(self._eval_args+(a, b)))126 def derivatives(self, x):127 d, ier = dfitpack.spalde(*(self._eval_args+(x,)))128 if not ier == 0:129 raise ValueError("Error code returned by spalde: %s" % ier)130 return d131 def roots(self):132 k = self._data[5]133 if k == 3:134 z, m, ier = dfitpack.sproot(*self._eval_args[:2])135 if not ier == 0:136 raise ValueError("Error code returned by spalde: %s" % ier)137 return z[:m]138 raise NotImplementedError('finding roots unsupported for '139 'non-cubic splines')140 def derivative(self, n=1):141 tck = fitpack.splder(self._eval_args, n)142 # if self.ext is 'const', derivative.ext will be 'zeros'143 ext = 1 if self.ext == 3 else self.ext144 return UnivariateSpline._from_tck(tck, ext=ext)145 def antiderivative(self, n=1):146 tck = fitpack.splantider(self._eval_args, n)147 return UnivariateSpline._from_tck(tck, self.ext)148class InterpolatedUnivariateSpline(UnivariateSpline):149 def __init__(self, x, y, w=None, bbox=[None]*2, k=3,150 ext=0, check_finite=False):151 x, y, w, bbox, self.ext = self.validate_input(x, y, w, bbox, k, None,152 ext, check_finite)153 if not np.all(diff(x) > 0.0):154 raise ValueError('x must be strictly increasing')155 # _data == x,y,w,xb,xe,k,s,n,t,c,fp,fpint,nrdata,ier156 self._data = dfitpack.fpcurf0(x, y, k, w=w, xb=bbox[0],157 xe=bbox[1], s=0)...

Full Screen

Full Screen

factor_test.py

Source:factor_test.py Github

copy

Full Screen

...36 self.portfolio = self.portfolio_cls(self.data_handler, self.events, self.start_date,37 self.initial_capital, self.stock_num)38 self.execution_handler = self.execution_handler_cls(self.events)3940 def _reset_class(self):4142 self.strategy = self.strategy_cls(self.data_handler, self.events, self.stock_num, self.factor, self.layer)43 self.portfolio = self.portfolio_cls(self.data_handler, self.events, self.start_date,44 self.initial_capital, self.stock_num)45 self.execution_handler = self.execution_handler_cls(self.events)4647 def _run_factortest(self, cur_layer):4849 i = 050 while True:51 i += 152 print(i)5354 if self.data_handler.continue_backtest:55 self.data_handler.update_bars_monthly()56 self.portfolio.update_timeindex()57 else:58 break5960 while True:61 try:62 event = self.events.get(False)63 except queue.Empty:64 break65 else:66 if event is not None:67 if event.type == 'MARKET':68 self.strategy.calculate_signals(event, cur_layer)69 elif event.type == 'SIGNAL':70 self.signals += 171 self.portfolio.update_signal(event)72 elif event.type == 'ORDER':73 self.orders += 174 self.execution_handler.execute_order(event)75 elif event.type == 'FILL':76 self.fills += 177 self.portfolio.update_fill(event)7879 if self.events.empty() and self.strategy.transferring == True:80 self.events.put(MarketEvent())8182 time.sleep(self.heartbeat)8384 def run_trading(self):8586 for cur_layer in range(self.layer):87 self._run_factortest(cur_layer)88 self._output_performance()89 my_plot = plot_performance(self.portfolio.equity_curve,90 self.data_handler.symbol_data[self.symbol_list[0]],91 self.execution_handler.execution_records)92 my_plot.plot_equity_curve()93 self.data_handler.reset_latest_data()94 self._reset_class()95 self.data_handler.continue_backtest = True9697 def factor_equity_curve(self):9899 return self.portfolio.equity_curve['equity_curve']100101 '''def run_trading(self):102103 self._run_factortest()104 self._output_performance()105 my_plot = plot_performance(self.portfolio.equity_curve,106 self.data_handler.symbol_data[self.symbol_list[0]],107 self.execution_handler.execution_records)108 my_plot.plot_equity_curve()'''

Full Screen

Full Screen

test_routine.py

Source:test_routine.py Github

copy

Full Screen

2'''3import torch.optim as optim4from cortex.plugins import ModelPlugin5def test_routine(model_class, arguments, data_class):6 ModelPlugin._reset_class()7 kwargs = {arguments['arg1']: 11, arguments['arg2']: 13}8 data = data_class(11)9 model = model_class(contract=dict(inputs=dict(A='test')))10 model._data = data11 model.kwargs.update(**kwargs)12 model.build()13 model.eval_step()14 print('Training nets: ', model._training_nets)15 assert 'net' in list(model._training_nets.values())[0]16 params = list(model.nets.net.parameters())17 op = optim.SGD(params, lr=0.0001)18 model._optimizers = dict(net=op)19 A = model.inputs('A')20 model.routine(A)21 model._reset_epoch()22 model.train_step()23 model.train_step()24 model.train_step()25 print('Results:', model._all_epoch_results)26 print('Losses:', model._all_epoch_losses)27 print('Times:', model._all_epoch_times)28 assert len(list(model._all_epoch_results.values())[0]) == 329 assert len(list(model._all_epoch_losses.values())[0]) == 330 assert len(list(model._all_epoch_times.values())[0]) == 331def test_routine_with_submodels(model_with_submodel):32 model = model_with_submodel33 model.build()34 params = list(model.nets.net.parameters())35 op = optim.SGD(params, lr=0.0001)36 params2 = list(model.nets.net2.parameters())37 op2 = optim.SGD(params2, lr=0.001)38 model._optimizers = dict(net=op, net2=op2)39 model.submodel._optimizers = dict(net=op, net2=op2)40 assert model._get_training_nets() == []41 model.train_step()42 assert model._get_training_nets() == ['net', 'net2']43 model.train_step()44 model.train_step()45def test_routine_with_submodels_2(model_class_with_submodel_2, data_class):46 ModelPlugin._reset_class()47 kwargs = {'d': 11, 'c': 13}48 data = data_class(11)49 contract = dict(inputs=dict(B='test'))50 sub_contract = dict(51 kwargs=dict(a='d'),52 nets=dict(net='net2'),53 inputs=dict(A='test')54 )55 sub_contract2 = dict(56 kwargs=dict(a='d'),57 nets=dict(net='net3'),58 inputs=dict(A='test')59 )60 model = model_class_with_submodel_2(sub_contract1=sub_contract,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful