Best Python code snippet using avocado_python

1# -*- coding: utf-8 -*-2"""3Created on Thu Nov 26 13:07:02 20154@author: rarossi5A structure will fail if subjected to a load greater then its own resistance:6failure := load > resistance7We can safely assume that the load and the resistance are independent.8By means of probability density functions (pdf) and cumulative density9functions (cdf) of the load and of the resistance, is it correct to say that10the probability of failure, can be calculated by the integral of11load_pdf * resistance_cdf ?12Confirmed at13http://stats.stackexchange.com/questions/183743/probability-of-failure14"""15import numpy as np16import scipy as sp17from scipy import stats as ss18from matplotlib import pyplot as plt19# %%20# This below double checks the p_failure calcs.21# Calculate the probability of failure as the integral of the convolution22# of load_pdf and resistance_pdf.23# see http://stats.stackexchange.com/questions/183743/probability-of-failure24# ==> I'm sure this could be done using the numpy convolve function but I25# still don't know how to do it.26def pfail_dblchk(fl, fr, x):27 """fl, fr: pdf functions of load and resistance28 x: domain29 return the probability of failure30 """31 return sp.integrate.quad(32 lambda tau: sp.integrate.cumtrapz(fl(x)*fr(tau+x), dx=x[1]-x[0])[-1],33 x[0]-(x[-1]-x[0]), 0)[0]34# %% #########################################################35def pfail(fl, Fr, x, dx):36 """Probability of failue given load and resistance.37 pfail = integral of load_pdf * resistance_cdf38 fl: pdf function of the load39 Fr: cfd function of the resistance40 x, dx: domain41 """42 return sp.integrate.cumtrapz(fl(x)*Fr(x), dx=dx)[-1]43# %%44def optimize_loc(res_loc, res_scale, load_distro, conf_target, eps):45 """Auxiliary function to be used with the scipy.optimize.bisect function46 to find the location parameters of the resistance distribution that47 matches a required confidence level.48 res_loc, res_scale: locations and scale parameters of the distribution49 load_distro: load distribution (frozen scipy.stats distribution)50 conf_target: confidence level target51 eps: limit integration domain where load and resistance pdfs are > eps"""52 res_distro = ss.gumbel_l(loc=res_loc, scale=res_scale)53 x, dx = np.linspace(54 min(load_distro.ppf(eps), res_distro.ppf(eps)),55 max(load_distro.ppf(1-eps), res_distro.ppf(1-eps)),56 2000, retstep=True)57 confidence = 1.0 - pfail(load_distro.pdf, res_distro.cdf, x, dx)58 return confidence - conf_target59# %%60if __name__ == '__main__':61 # input data62 conf_target = 0.9 # confidence level of non-failure63 load_loc = 100 # location parameter for the load distribution64 load_scale = 5 # scale parameter for the load distribution65 res_scale = 3.5 # scale parameter for the resistance distribution66 eps = 1e-8 # domain = pdf > eps, for load and resistance67 # frozen load distribution68 load_distro = ss.gumbel_r(loc=load_loc, scale=load_scale)69 # finds the location parameter for the resistance distribution that70 # gives the required conf_target71 res_loc = sp.optimize.bisect(optimize_loc, load_loc,72 load_distro.ppf(1-eps),73 args=(res_scale, load_distro,74 conf_target, eps))75 # frozen resistance distribution76 res_distro = ss.gumbel_l(loc=res_loc, scale=res_scale)77 # recalculates the domain and the confidence level78 x, dx = np.linspace(min(load_distro.ppf(eps), res_distro.ppf(eps)),79 max(load_distro.ppf(1-eps), res_distro.ppf(1-eps)),80 200, retstep=True)81 confidence = 1.0 - pfail(load_distro.pdf, res_distro.cdf, x, dx)82 # %% plotting83 plt.plot(x, load_distro.pdf(x), label='load pdf')84 plt.plot(x, res_distro.pdf(x), label='resistance pdf')85 plt.grid()86 plt.legend(loc='best')87 plt.show()88 print('Confidence %.3f%%' % (100*confidence))89 pfailure = pfail_dblchk(load_distro.pdf, res_distro.pdf, x)90 print('Dbl check %.3f%%' % (100*(1-pfailure)))91"""92Tentando resolver integral load_pdf * res_cdf analiticamente...93\\94\\\text{Assuming Gumbel distribution.} \\95f: PDF \\96F: CDF \\97\\\text{The load is likely to be right skewed:}98\\99f_l(x) = \frac{1}{\beta} e^{-(z+e^{-z})} \\100F_l(x) = e^{-e^{-z}} \\101z = \frac{x-\mu}{\beta}102\\\\\text{The resistance is likely to be left skewed:} \\103f_r(x)= \frac{1}{\beta} e^{(z-e^z)} \\104F_r(x) = 1 - e^{-e^z} \\105\\\\\text{The probability of failure is:} \\106p_{fail} = \int_{-\infty}^\infty f_{load}(x) F_{res} (x) dx \\107= \int_{-\infty}^\infty108 \frac{1}{\beta_l} e^{-(z+e^{-z_l})}109 \big( 1 - e^{-e^z_r} \big) dx \\110= \int_{-\infty}^\infty111 \frac{1}{\beta_l} e^{-(\frac{x-\mu_l}{\beta_l}112 +e^{-\frac{x-\mu_l}{\beta_l}})}113 \big( 1 - e^{-e^\frac{x-\mu_r}{\beta_r}} \big) dx...

distro_to_rosinstall.py

Source:distro_to_rosinstall.py

...3import sys4import yaml5from rospkg.distro import load_distro, distro_uri6def translate(distro, translate_dir):7 d = load_distro(distro_uri(distro))8 repo_list = d.get_stacks(True)9 for name, item in repo_list.iteritems():10 if item.vcs_config.type == 'svn':11 rosinstall = [{item.vcs_config.type: \12 {'local-name': item.name,13 'uri': item.vcs_config.anon_dev}}]14 else:15 rosinstall = [{item.vcs_config.type: \16 {'local-name': item.name,17 'uri': item.vcs_config.anon_repo_uri,18 'version': item.vcs_config.dev_branch}}]19 path = os.path.join(translate_dir, "%s.rosinstall" % item.name)20 with open(path, 'w+') as f:21 print("writing to %s" % path)...

## 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.