How to use get_fingerprint method in tempest

Best Python code snippet using tempest_python

expressionsApi.py

Source:expressionsApi.py Github

copy

Full Screen

1#!/usr/bin/env python2"""3/*******************************************************************************4 * Copyright (c) cortical.io GmbH. All rights reserved.5 * 6 * This software is confidential and proprietary information.7 * You shall use it only in accordance with the terms of the8 * license agreement you entered into with cortical.io GmbH.9 ******************************************************************************/10"""11from models import *12class ExpressionsApi(object):13 def __init__(self, apiClient):14 self.apiClient = apiClient15 16 def resolveExpression(self, retina_name, body, sparsity=1.0):17 """Resolve an expression18 Args:19 body, ExpressionOperation: The JSON formatted encoded to be evaluated (required)20 retina_name, str: The retina name (required)21 sparsity, float: Sparsify the resulting expression to this percentage (optional)22 Returns: Fingerprint23 """24 resourcePath = '/expressions'25 method = 'POST'26 queryParams = {}27 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}28 postData = None29 queryParams['retina_name'] = retina_name30 queryParams['sparsity'] = sparsity31 postData = body32 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)33 return apiFingerprint.Fingerprint(**response.json())34 35 def getContextsForExpression(self, retina_name, body, get_fingerprint=None, start_index=0, max_results=5, sparsity=1.0):36 """Get semantic contexts for the input expression37 Args:38 body, ExpressionOperation: The JSON encoded expression to be evaluated (required)39 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)40 retina_name, str: The retina name (required)41 start_index, int: The start-index for pagination (optional) (optional)42 max_results, int: Max results per page (optional) (optional)43 sparsity, float: Sparsify the resulting expression to this percentage (optional)44 Returns: Array[Context]45 """46 resourcePath = '/expressions/contexts'47 method = 'POST'48 queryParams = {}49 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}50 postData = None51 queryParams['retina_name'] = retina_name52 queryParams['start_index'] = start_index53 queryParams['max_results'] = max_results54 queryParams['sparsity'] = sparsity55 queryParams['get_fingerprint'] = get_fingerprint56 postData = body57 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)58 return [apiContext.Context(**r) for r in response.json()]59 60 def getSimilarTermsForExpressionContext(self, retina_name, body, context_id=None, pos_type=None, get_fingerprint=None, start_index=0, max_results=10, sparsity=1.0):61 """Get similar terms for the contexts of an expression62 Args:63 body, ExpressionOperation: The JSON encoded expression to be evaluated (required)64 context_id, int: The identifier of a context (optional) (optional)65 pos_type, str: Part of speech (optional) (optional)66 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)67 retina_name, str: The retina name (required)68 start_index, int: The start-index for pagination (optional) (optional)69 max_results, int: Max results per page (optional) (optional)70 sparsity, float: Sparsify the resulting expression to this percentage (optional)71 Returns: Array[Term]72 """73 resourcePath = '/expressions/similar_terms'74 method = 'POST'75 queryParams = {}76 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}77 postData = None78 queryParams['retina_name'] = retina_name79 queryParams['context_id'] = context_id80 queryParams['start_index'] = start_index81 queryParams['max_results'] = max_results82 queryParams['pos_type'] = pos_type83 queryParams['sparsity'] = sparsity84 queryParams['get_fingerprint'] = get_fingerprint85 postData = body86 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)87 return [apiTerm.Term(**r) for r in response.json()]88 89 def resolveBulkExpression(self, retina_name, body, sparsity=1.0):90 """Bulk resolution of expressions91 Args:92 body, ExpressionOperation: The JSON encoded expression to be evaluated (required)93 retina_name, str: The retina name (required)94 sparsity, float: Sparsify the resulting expression to this percentage (optional)95 Returns: Array[Fingerprint]96 """97 resourcePath = '/expressions/bulk'98 method = 'POST'99 queryParams = {}100 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}101 postData = None102 queryParams['retina_name'] = retina_name103 queryParams['sparsity'] = sparsity104 postData = body105 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)106 return [apiFingerprint.Fingerprint(**r) for r in response.json()]107 108 def getContextsForBulkExpression(self, retina_name, body, get_fingerprint=None, start_index=0, max_results=5, sparsity=1.0):109 """Bulk get contexts for input expressions110 Args:111 body, ExpressionOperation: The JSON encoded expression to be evaluated (required)112 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)113 retina_name, str: The retina name (required)114 start_index, int: The start-index for pagination (optional) (optional)115 max_results, int: Max results per page (optional) (optional)116 sparsity, float: Sparsify the resulting expression to this percentage (optional)117 Returns: Array[Context]118 """119 resourcePath = '/expressions/contexts/bulk'120 method = 'POST'121 queryParams = {}122 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}123 postData = None124 queryParams['retina_name'] = retina_name125 queryParams['start_index'] = start_index126 queryParams['max_results'] = max_results127 queryParams['sparsity'] = sparsity128 queryParams['get_fingerprint'] = get_fingerprint129 postData = body130 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)131 return [[apiContext.Context(**c) for c in r] for r in response.json()]132 133 def getSimilarTermsForBulkExpressionContext(self, retina_name, body, context_id=None, pos_type=None, get_fingerprint=None, start_index=0, max_results=10, sparsity=1.0):134 """Bulk get similar terms for input expressions135 Args:136 body, ExpressionOperation: The JSON encoded expression to be evaluated (required)137 context_id, int: The identifier of a context (optional) (optional)138 pos_type, str: Part of speech (optional) (optional)139 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)140 retina_name, str: The retina name (required)141 start_index, int: The start-index for pagination (optional) (optional)142 max_results, int: Max results per page (optional) (optional)143 sparsity, float: Sparsify the resulting expression to this percentage (optional)144 Returns: Array[Term]145 """146 resourcePath = '/expressions/similar_terms/bulk'147 method = 'POST'148 queryParams = {}149 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}150 postData = None151 queryParams['retina_name'] = retina_name152 queryParams['context_id'] = context_id153 queryParams['start_index'] = start_index154 queryParams['max_results'] = max_results155 queryParams['pos_type'] = pos_type156 queryParams['sparsity'] = sparsity157 queryParams['get_fingerprint'] = get_fingerprint158 postData = body159 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)160 return [[apiTerm.Term(**t) for t in r] for r in response.json()]161 162 def getSimilarTermsForSinglePosition(self, retina_name, position, ):163 """Get similar terms for single bit position164 Args:165 position, int: A position in the retina space. (required)166 retina_name, str: The retina name (required)167 Returns: Array[Term]168 """169 resourcePath = '/expressions/similar_terms_bit'170 method = 'GET'171 queryParams = {}172 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}173 postData = None174 queryParams['retina_name'] = retina_name175 queryParams['position'] = position176 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)177 return [apiTerm.Term(**r) for r in response.json()]...

Full Screen

Full Screen

test_arr_estimators.py

Source:test_arr_estimators.py Github

copy

Full Screen

...3import numpy as np4from pytest import approx5from math import log2 as log6def test_fingerprint():7 np.testing.assert_array_equal(get_fingerprint([0, 0, 0, 1]), [0, 1, 0, 1])8 np.testing.assert_array_equal(get_fingerprint([0, 1, 4, 3, 0, 0, 2, 4]), [0, 3, 1, 1])9 t_data0 = np.ceil(beta(1, 1, 500) * 20)10 t_data1 = np.ceil(beta(1, 3, 2000) * 500)11 fp0 = get_fingerprint(t_data0)12 assert sum([i * x for i, x in enumerate(fp0)]) == 50013 fp1 = get_fingerprint(t_data1)14 assert sum([i * x for i, x in enumerate(fp1)]) == 200015# Takes about 3 seconds16def test_unseen():17 np.random.seed(1)18 # Testdata was generated by Matlab implementation19 # data = makeFinger(round(rand([100 1])*10))20 # 0 added to account for different makeFinger python impl21 data = [0, 0, 0, 0, 1, 1, 2, 0, 1, 0, 1, 3, 0, 1, 0, 1]22 hist, p = unseen(data)23 prob_covered = sum([x * y for x, y in zip(hist, p)])24 assert abs(1 - prob_covered) < 1 * 10 ** 925 support_size = sum(hist)26 # value comes from matlab version27 assert abs(support_size - 8.8642) < 1 * 10 ** -328 # Data taken from KPT19 Fig629 N = 10 ** 530 data = np.round(beta(1, 2.5, N) * N)31 f = get_fingerprint(data)32 hist, _ = unseen(f)33 rerr = abs(N - sum(hist)) / N34 assert rerr < 0.1535 print(f"Test 1 relative error {rerr}")36 data = np.round(beta(1, 10, 10 * N) * N)37 f = get_fingerprint(data)38 hist, _ = unseen(f)39 rerr = abs(N - sum(hist)) / N40 assert rerr < 0.541 print(f"Test 2 relative error {rerr}")42# Takes about 30 minutes43def test_unseen_valiant():44 """45 Test based on testing data as described in the paper describing the unseen estimator. This differs from the other46 test, which only considers testdata from KPT19.47 """48 np.random.seed(1)49 def unif(k, n):50 return np.random.random_integers(k, size=n), - k * (1 / k) * log(1 / k)51 def mixunif(k, n):52 return (53 np.random.choice(np.arange(1, k + 1), n, p=[5 / (2 * k) if i < k / 5 else 5 / (8 * k) for i in range(k)]),54 - (k / 5) * (5 / (2 * k)) * log(5 / (2 * k)) - (4 * k / 5) * (5 / (8 * k)) * log(5 / (8 * k)))55 def zipf(k, n):56 s = sum([1 / i for i in range(1, k + 1)])57 p = [(1 / (i + 1)) / s for i in range(k)]58 ent = sum(map(lambda x: -log(x) * x, p))59 return np.random.choice(np.arange(1, k + 1), n, p=p), ent60 def zipf2(k, n):61 s = sum([1 / i ** 0.6 for i in range(1, k + 1)])62 p = [(1 / (i + 1) ** 0.6) / s for i in range(k)]63 ent = sum(map(lambda x: -log(x) * x, p))64 return np.random.choice(np.arange(1, k + 1), n, p=p), ent65 def geom(k, n):66 # Not sure if this is correct or contains one by off error67 p = 1 / k68 ent = (- (1 - p) * log(1 - p) - p * log(p)) / p69 return np.random.geometric(p, n), ent70 def mixgeomzipf(k, n):71 # Not sure if this is how the authors mixed the distributions72 pgeom = [(1 / k) * (1 - 1 / k) ** i for i in range(k // 2)]73 s = sum(range((k + 1) // 2))74 pzipf = [1 / (i + 1) / s for i in range((k + 1) // 2)]75 pgeom.extend(pzipf)76 tprob = sum(pgeom)77 p = list(map(lambda x: x / tprob, pgeom))78 ent = sum(map(lambda x: -log(x) * x, p))79 return np.random.choice(np.arange(1, k + 1), n, p=p), ent80 k = 100081 x0 = int(k ** 0.6)82 x1 = int(k ** 1.25)83 dist = [unif, mixunif, zipf, zipf2, geom, mixgeomzipf]84 for d in dist:85 print(f"Using distribution: {d.__name__}")86 for n in [x0, x1]:87 print(f"n = {n}")88 pred = []89 for _ in range(500):90 samples, entropy = d(k, n)91 fp = get_fingerprint(samples)92 hist, p = unseen(fp)93 e = sum(map(lambda x: - x[0] * x[1] * log(x[1]), zip(hist, p)))94 pred.append((e - entropy) ** 2)95 rmse = np.sqrt(np.mean(np.array(pred)))96 print(f"RMSE: {rmse}")97 if d == geom and n == int(k ** 0.6):98 assert rmse < 1.699 elif n == int(k ** 1.25):100 assert rmse < 0.1101 else:102 assert rmse < 1103def test_jackk_coeffs():104 f = [0, 1, 2, 3, 4, 0, 6, 7, 8, 9, 10, 300, 30298, 10000000]105 d = sum(f)106 m = len(f) - 1107 coeffs = get_jackk_coeffs(f, m)108 j1 = coeffs[0]109 j2 = coeffs[1]110 j3 = coeffs[2]111 j4 = coeffs[3]112 # formulas come from paper113 assert j1[0] == approx(d)114 assert j2[0] == approx(d)115 assert j3[0] == approx(d)116 assert j4[0] == approx(d)117 assert j1[1] == approx((m - 1) / m)118 assert j2[1] == approx((2 * m - 3) / m)119 assert j3[1] == approx((3 * m - 6) / m)120 assert j4[1] == approx((4 * m - 10) / m)121 assert j1[2] == approx(0)122 assert j2[2] == approx(-(m - 2) ** 2 / (m * (m - 1)))123 assert j3[2] == approx(-(3 * m ** 2 - 15 * m + 19) / ((m - 1) * m))124 assert j4[2] == approx(-(6 * m ** 2 - 36 * m + 55) / ((m - 1) * m))125 assert j1[3] == approx(0)126 assert j2[3] == approx(0)127 assert j3[3] == approx((m - 3) ** 3 / ((m - 2) * (m - 1) * m))128 assert j4[3] == approx((4 * m ** 3 - 42 * m ** 2 + 148 * m - 175) / (m * (m - 1) * (m - 2)))129 assert j1[4] == j2[4] == j3[4] == approx(0)130 assert j4[4] == approx(-(m - 4) ** 4 / ((m - 3) * (m - 2) * (m - 1) * m))131def test_jackk():132 np.random.seed(1)133 N = 10 ** 5134 data = np.round(beta(1, 2.5, 5 * 10 ** 4) * N)135 f = get_fingerprint(data)136 d = jackknife_selftune(f, N)137 r_err = abs((d - N) / N)138 assert r_err < 0.10139 print(f"Jack T1 RERR: {r_err}")140 data = np.round(beta(1, 17, 5 * 10 ** 4) * N)141 f = get_fingerprint(data)142 d = jackknife_selftune(f, N)143 r_err = abs((d - N) / N)144 assert r_err < 0.75145 print(f"Jack T2 RERR: {r_err}")146def test_jackknife_burnham():147 # Test uses data from burnham 1979148 fp = [0, 43, 16, 8, 6, 0, 2, 1]149 d = jackknife_selftune(fp, 18)150 assert abs(d - 158) < 1151def test_jackcrash():152 np.random.seed(1)153 data = [73050, 98048, 95043, 90051, 79044, 75051, 75052, 87053, 76050, 85050, 72050, 95043, 80045, 92053,154 95045, 76050, 75051, 84042, 83053, 77053, 88046, 77051, 95046, 95043, 74046, 75051, 83044, 78053,155 75049, 84046, 80043, 77050, 83042, 91042]156 f = get_fingerprint(data)157 d = jackknife_selftune(f, len(data))...

Full Screen

Full Screen

termsApi.py

Source:termsApi.py Github

copy

Full Screen

1#!/usr/bin/env python2"""3/*******************************************************************************4 * Copyright (c) cortical.io GmbH. All rights reserved.5 * 6 * This software is confidential and proprietary information.7 * You shall use it only in accordance with the terms of the8 * license agreement you entered into with cortical.io GmbH.9 ******************************************************************************/10"""11from models import *12class TermsApi(object):13 def __init__(self, apiClient):14 self.apiClient = apiClient15 16 def getTerm(self, retina_name, term=None, get_fingerprint=None, start_index=0, max_results=10):17 """Get term objects18 Args:19 term, str: A term in the retina (optional) (optional)20 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)21 retina_name, str: The retina name (required)22 start_index, int: The start-index for pagination (optional) (optional)23 max_results, int: Max results per page (optional) (optional)24 Returns: Array[Term]25 """26 resourcePath = '/terms'27 method = 'GET'28 queryParams = {}29 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}30 postData = None31 queryParams['retina_name'] = retina_name32 queryParams['term'] = term33 queryParams['start_index'] = start_index34 queryParams['max_results'] = max_results35 queryParams['get_fingerprint'] = get_fingerprint36 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)37 return [apiTerm.Term(**r) for r in response.json()]38 39 def getContextsForTerm(self, retina_name, term, get_fingerprint=None, start_index=0, max_results=5):40 """Get the contexts for a given term41 Args:42 term, str: A term in the retina (required)43 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)44 retina_name, str: The retina name (required)45 start_index, int: The start-index for pagination (optional) (optional)46 max_results, int: Max results per page (optional) (optional)47 Returns: Array[Context]48 """49 resourcePath = '/terms/contexts'50 method = 'GET'51 queryParams = {}52 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}53 postData = None54 queryParams['retina_name'] = retina_name55 queryParams['term'] = term56 queryParams['start_index'] = start_index57 queryParams['max_results'] = max_results58 queryParams['get_fingerprint'] = get_fingerprint59 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)60 return [apiContext.Context(**r) for r in response.json()]61 62 def getSimilarTerms(self, retina_name, term, context_id=None, pos_type=None, get_fingerprint=None, start_index=0, max_results=10):63 """Get the similar terms of a given term64 Args:65 term, str: A term in the retina (required)66 context_id, int: The identifier of a context (optional) (optional)67 pos_type, str: Part of speech (optional) (optional)68 get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)69 retina_name, str: The retina name (required)70 start_index, int: The start-index for pagination (optional) (optional)71 max_results, int: Max results per page (optional) (optional)72 Returns: Array[Term]73 """74 resourcePath = '/terms/similar_terms'75 method = 'GET'76 queryParams = {}77 headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}78 postData = None79 queryParams['retina_name'] = retina_name80 queryParams['term'] = term81 queryParams['context_id'] = context_id82 queryParams['start_index'] = start_index83 queryParams['max_results'] = max_results84 queryParams['pos_type'] = pos_type85 queryParams['get_fingerprint'] = get_fingerprint86 response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)...

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