Python numpy.logspace() Examples
The following are 30 code examples for showing how to use numpy.logspace(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: EXOSIMS Author: dsavransky File: test_PlanetPopulation.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_dist_sma(self): """ Test that smas outside of the range have zero probability """ for mod in self.allmods: if 'dist_sma' in mod.__dict__: with RedirectStreams(stdout=self.dev_null): pp = mod(**self.spec) a = np.logspace(np.log10(pp.arange[0].to('AU').value/10.),np.log10(pp.arange[1].to('AU').value*10.),100) fa = pp.dist_sma(a) self.assertTrue(np.all(fa[a < pp.arange[0].to('AU').value] == 0),'dist_sma high bound failed for %s'%mod.__name__) self.assertTrue(np.all(fa[a > pp.arange[1].to('AU').value] == 0),'dist_sma low bound failed for %s'%mod.__name__) self.assertTrue(np.all(fa[(a >= pp.arange[0].to('AU').value) & (a <= pp.arange[1].to('AU').value)] >= 0.),'dist_sma generates negative densities within range for %s'%mod.__name__)
Example 2
Project: EXOSIMS Author: dsavransky File: test_PlanetPopulation.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_dist_radius(self): """ Test that radii outside of the range have zero probability """ for mod in self.allmods: if 'dist_radius' in mod.__dict__: with RedirectStreams(stdout=self.dev_null): pp = mod(**self.spec) Rp = np.logspace(np.log10(pp.Rprange[0].to('earthRad').value/10.),np.log10(pp.Rprange[1].to('earthRad').value*100.),100) fr = pp.dist_radius(Rp) self.assertTrue(np.all(fr[Rp < pp.Rprange[0].to('earthRad').value] == 0),'dist_radius high bound failed for %s'%mod.__name__) self.assertTrue(np.all(fr[Rp > pp.Rprange[1].to('earthRad').value] == 0),'dist_radius high bound failed for %s'%mod.__name__) self.assertTrue(np.all(fr[(Rp >= pp.Rprange[0].to('earthRad').value) & (Rp <= pp.Rprange[1].to('earthRad').value)] > 0),'dist_radius generates zero probabilities within range for %s'%mod.__name__)
Example 3
Project: EXOSIMS Author: dsavransky File: test_PlanetPopulation.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_dist_mass(self): """ Test that masses outside of the range have zero probability """ for mod in self.allmods: if 'dist_mass' in mod.__dict__: with RedirectStreams(stdout=self.dev_null): pp = mod(**self.spec) Mp = np.logspace(np.log10(pp.Mprange[0].value/10.),np.log10(pp.Mprange[1].value*100.),100) fr = pp.dist_mass(Mp) self.assertTrue(np.all(fr[Mp < pp.Mprange[0].value] == 0),'dist_mass high bound failed for %s'%mod.__name__) self.assertTrue(np.all(fr[Mp > pp.Mprange[1].value] == 0),'dist_mass high bound failed for %s'%mod.__name__) self.assertTrue(np.all(fr[(Mp >= pp.Mprange[0].value) & (Mp <= pp.Mprange[1].value)] > 0))
Example 4
Project: EXOSIMS Author: dsavransky File: test_PlanetPopulation.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_dist_sma_radius(self): """ Test that sma and radius values outside of the range have zero probability """ for mod in self.allmods: if 'dist_sma_radius' in mod.__dict__: with RedirectStreams(stdout=self.dev_null): pp = mod(**self.spec) a = np.logspace(np.log10(pp.arange[0].value/10.),np.log10(pp.arange[1].value*100),100) Rp = np.logspace(np.log10(pp.Rprange[0].value/10.),np.log10(pp.Rprange[1].value*100),100) aa, RR = np.meshgrid(a,Rp) fr = pp.dist_sma_radius(aa,RR) self.assertTrue(np.all(fr[aa < pp.arange[0].value] == 0),'dist_sma_radius low bound failed on sma for %s'%mod.__name__) self.assertTrue(np.all(fr[aa > pp.arange[1].value] == 0),'dist_sma_radius high bound failed on sma for %s'%mod.__name__) self.assertTrue(np.all(fr[RR < pp.Rprange[0].value] == 0),'dist_sma_radius low bound failed on radius for %s'%mod.__name__) self.assertTrue(np.all(fr[RR > pp.Rprange[1].value] == 0),'dist_sma_radius high bound failed on radius for %s'%mod.__name__) self.assertTrue(np.all(fr[(aa > pp.arange[0].value) & (aa < pp.arange[1].value) & (RR > pp.Rprange[0].value) & (RR < pp.Rprange[1].value)] > 0),'dist_sma_radius is improper pdf for %s'%mod.__name__)
Example 5
Project: python-control Author: python-control File: margin_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_nocross(self): # what happens when no gain/phase crossover? s = TransferFunction([1, 0], [1]) h1 = 1/(1+s) h2 = 3*(10+s)/(2+s) h3 = 0.01*(10-s)/(2+s)/(1+s) gm, pm, wm, wg, wp, ws = stability_margins(h1) assert_array_almost_equal( [gm, pm, wg, wp], [float('Inf'), float('Inf'), float('NaN'), float('NaN')]) gm, pm, wm, wg, wp, ws = stability_margins(h2) self.assertEqual(pm, float('Inf')) gm, pm, wm, wg, wp, ws = stability_margins(h3) self.assertTrue(np.isnan(wp)) omega = np.logspace(-2,2, 100) out1b = stability_margins(FRD(h1, omega)) out2b = stability_margins(FRD(h2, omega)) out3b = stability_margins(FRD(h3, omega))
Example 6
Project: python-control Author: python-control File: bdalg_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_feedback_args(self): # Added 25 May 2019 to cover missing exception handling in feedback() # If first argument is not LTI or convertable, generate an exception args = ([1], self.sys2) self.assertRaises(TypeError, ctrl.feedback, *args) # If second argument is not LTI or convertable, generate an exception args = (self.sys1, np.array([1])) self.assertRaises(TypeError, ctrl.feedback, *args) # Convert first argument to FRD, if needed h = TransferFunction([1], [1, 2, 2]) omega = np.logspace(-1, 2, 10) frd = ctrl.FRD(h, omega) sys = ctrl.feedback(1, frd) self.assertTrue(isinstance(sys, ctrl.FRD))
Example 7
Project: python-control Author: python-control File: frd_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def testMIMOSmooth(self): sys = StateSpace([[-0.5, 0.0], [0.0, -1.0]], [[1.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]) sys2 = np.matrix([[1, 0, 0], [0, 1, 0]]) * sys omega = np.logspace(-1, 2, 10) f1 = FRD(sys, omega, smooth=True) f2 = FRD(sys2, omega, smooth=True) np.testing.assert_array_almost_equal( (f1*f2).freqresp([0.1, 1.0, 10])[0], (sys*sys2).freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( (f1*f2).freqresp([0.1, 1.0, 10])[1], (sys*sys2).freqresp([0.1, 1.0, 10])[1]) np.testing.assert_array_almost_equal( (f1*f2).freqresp([0.1, 1.0, 10])[2], (sys*sys2).freqresp([0.1, 1.0, 10])[2])
Example 8
Project: python-control Author: python-control File: frd_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_size_mismatch(self): sys1 = FRD(ct.rss(2, 2, 2), np.logspace(-1, 1, 10)) # Different number of inputs sys2 = FRD(ct.rss(3, 1, 2), np.logspace(-1, 1, 10)) self.assertRaises(ValueError, FRD.__add__, sys1, sys2) # Different number of outputs sys2 = FRD(ct.rss(3, 2, 1), np.logspace(-1, 1, 10)) self.assertRaises(ValueError, FRD.__add__, sys1, sys2) # Inputs and outputs don't match self.assertRaises(ValueError, FRD.__mul__, sys2, sys1) # Feedback mismatch self.assertRaises(ValueError, FRD.feedback, sys2, sys1)
Example 9
Project: python-control Author: python-control File: frd_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_evalfr_deprecated(self): sys_tf = ct.tf([1], [1, 2, 1]) frd_tf = FRD(sys_tf, np.logspace(-1, 1, 3)) # Deprecated version of the call (should generate warning) import warnings with warnings.catch_warnings(): # Make warnings generate an exception warnings.simplefilter('error') # Make sure that we get a pending deprecation warning self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.) # FRD.evalfr() is being deprecated import warnings with warnings.catch_warnings(): # Make warnings generate an exception warnings.simplefilter('error') # Make sure that we get a pending deprecation warning self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.)
Example 10
Project: python-control Author: python-control File: config_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_custom_bode_default(self): ct.config.defaults['bode.dB'] = True ct.config.defaults['bode.deg'] = True ct.config.defaults['bode.Hz'] = True # Generate a Bode plot plt.figure() omega = np.logspace(-3, 3, 100) ct.bode_plot(self.sys, omega, dB=True) mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data() np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3) # Override defaults plt.figure() ct.bode_plot(self.sys, omega, Hz=True, deg=False, dB=True) mag_x, mag_y = (((plt.gcf().axes[0]).get_lines())[0]).get_data() phase_x, phase_y = (((plt.gcf().axes[1]).get_lines())[0]).get_data() np.testing.assert_almost_equal(mag_x[0], 0.001 / (2*pi), decimal=6) np.testing.assert_almost_equal(mag_y[0], 20*log10(10), decimal=3) np.testing.assert_almost_equal(phase_y[-1], -pi, decimal=2) ct.reset_defaults()
Example 11
Project: celer Author: mathurinm File: test_lasso.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_celer_path(sparse_X, alphas, pb): """Test Lasso path convergence.""" X, y = build_dataset(n_samples=30, n_features=50, sparse_X=sparse_X) if pb == "logreg": y = np.sign(y) n_samples = X.shape[0] if alphas is not None: alpha_max = np.max(np.abs(X.T.dot(y))) / n_samples n_alphas = 10 alphas = alpha_max * np.logspace(0, -2, n_alphas) tol = 1e-6 alphas, coefs, gaps, thetas, n_iters = celer_path( X, y, pb, alphas=alphas, tol=tol, return_thetas=True, verbose=1, return_n_iter=True) np.testing.assert_array_less(gaps, tol) # hack because array_less wants strict inequality np.testing.assert_array_less(0.99, n_iters)
Example 12
Project: celer Author: mathurinm File: test_lasso.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_warm_start(): """Test Lasso path convergence.""" X, y = build_dataset( n_samples=100, n_features=100, sparse_X=True) n_samples, n_features = X.shape alpha_max = np.max(np.abs(X.T.dot(y))) / n_samples n_alphas = 10 alphas = alpha_max * np.logspace(0, -2, n_alphas) reg1 = Lasso(tol=1e-6, warm_start=True, p0=10) reg1.coef_ = np.zeros(n_features) for alpha in alphas: reg1.set_params(alpha=alpha) reg1.fit(X, y) # refitting with warm start should take less than 2 iters: reg1.fit(X, y) # hack because assert_array_less does strict comparison... np.testing.assert_array_less(reg1.n_iter_, 2.01)
Example 13
Project: gmpe-smtk Author: GEMScienceTools File: configure.py License: GNU Affero General Public License v3.0 | 6 votes |
def _define_line_spacing(self, maximum_distance, spacing, as_log=False): """ The user may wish to define the line spacing in either log or linear space """ nvals = int(maximum_distance / spacing) + 1 if as_log: spacings = np.logspace(-3., np.log10(maximum_distance), nvals) spacings[0] = 0.0 else: spacings = np.linspace(0.0, maximum_distance, nvals) if spacings[-1] < (maximum_distance - 1.0E-7): spacings = np.hstack([spacings, maximum_distance]) return spacings
Example 14
Project: LSDMappingTools Author: LSDtopotools File: LSDMap_HillslopeMorphology.py License: MIT License | 6 votes |
def PlotEStarRStarTheoretical(): """ This makes the theoretical E* vs R* plot. It prints to the current open figure. SMM Note: This would be better if it used a supploed figure. Can the default be get_clf()? MDH """ # Calculate analytical relationship EStar = np.logspace(-1,3,1000) RStar = CalculateRStar(EStar) # Plot with open figure plt.plot(EStar,RStar,'k--') #-------------------------------------------------------------------------------# # PLOTTING FUNCTIONS #-------------------------------------------------------------------------------# # SMM: Checked and working 13/06/2018
Example 15
Project: stability-selection Author: scikit-learn-contrib File: stability_selection.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, base_estimator=LogisticRegression(penalty='l1'), lambda_name='C', lambda_grid=np.logspace(-5, -2, 25), n_bootstrap_iterations=100, sample_fraction=0.5, threshold=0.6, bootstrap_func=bootstrap_without_replacement, bootstrap_threshold=None, verbose=0, n_jobs=1, pre_dispatch='2*n_jobs', random_state=None): self.base_estimator = base_estimator self.lambda_name = lambda_name self.lambda_grid = lambda_grid self.n_bootstrap_iterations = n_bootstrap_iterations self.sample_fraction = sample_fraction self.threshold = threshold self.bootstrap_func = bootstrap_func self.bootstrap_threshold = bootstrap_threshold self.verbose = verbose self.n_jobs = n_jobs self.pre_dispatch = pre_dispatch self.random_state = random_state
Example 16
Project: stability-selection Author: scikit-learn-contrib File: test_stability_selection.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_stability_selection_regression(): n, p, k = 500, 1000, 5 X, y, important_betas = _generate_dummy_regression_data(n=n, k=k) base_estimator = Pipeline([ ('scaler', StandardScaler()), ('model', Lasso()) ]) lambdas_grid = np.logspace(-1, 1, num=10) selector = StabilitySelection(base_estimator=base_estimator, lambda_name='model__alpha', lambda_grid=lambdas_grid) selector.fit(X, y) chosen_betas = selector.get_support(indices=True) assert_almost_equal(important_betas, chosen_betas)
Example 17
Project: stability-selection Author: scikit-learn-contrib File: test_stability_selection.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_with_complementary_pairs_bootstrap(): n, p, k = 500, 1000, 5 X, y, important_betas = _generate_dummy_regression_data(n=n, k=k) base_estimator = Pipeline([ ('scaler', StandardScaler()), ('model', Lasso()) ]) lambdas_grid = np.logspace(-1, 1, num=10) selector = StabilitySelection(base_estimator=base_estimator, lambda_name='model__alpha', lambda_grid=lambdas_grid, bootstrap_func='complementary_pairs') selector.fit(X, y) chosen_betas = selector.get_support(indices=True) assert_almost_equal(important_betas, chosen_betas)
Example 18
Project: stability-selection Author: scikit-learn-contrib File: test_stability_selection.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_different_shape(): n, p, k = 100, 200, 5 X, y, important_betas = _generate_dummy_regression_data(n=n, k=k) base_estimator = Pipeline([ ('scaler', StandardScaler()), ('model', Lasso()) ]) lambdas_grid = np.logspace(-1, 1, num=10) selector = StabilitySelection(base_estimator=base_estimator, lambda_name='model__alpha', lambda_grid=lambdas_grid) selector.fit(X, y) selector.transform(X[:, :-2])
Example 19
Project: stability-selection Author: scikit-learn-contrib File: test_stability_selection.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_no_features(): n, p, k = 100, 200, 0 X, y, important_betas = _generate_dummy_regression_data(n=n, k=k) base_estimator = Pipeline([ ('scaler', StandardScaler()), ('model', Lasso()) ]) lambdas_grid = np.logspace(-1, 1, num=10) selector = StabilitySelection(base_estimator=base_estimator, lambda_name='model__alpha', lambda_grid=lambdas_grid) selector.fit(X, y) assert_almost_equal(selector.transform(X), np.empty(0).reshape((X.shape[0], 0)))
Example 20
Project: stability-selection Author: scikit-learn-contrib File: test_stability_selection.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_stability_plot(): n, p, k = 500, 200, 5 X, y, important_betas = _generate_dummy_regression_data(n=n, k=k) base_estimator = Pipeline([ ('scaler', StandardScaler()), ('model', Lasso()) ]) lambdas_grid = np.logspace(-1, 1, num=10) selector = StabilitySelection(base_estimator=base_estimator, lambda_name='model__alpha', lambda_grid=lambdas_grid) selector.fit(X, y) plot_stability_path(selector, threshold_highlight=0.5)
Example 21
Project: imitation Author: HumanCompatibleAI File: parallel.py License: MIT License | 6 votes |
def example_gail_easy(): sacred_ex_name = "train_adversarial" run_name = "example-gail-easy" n_seeds = 1 search_space = { "named_configs": tune.grid_search([[env] for env in EASY_ENVS]), "config_updates": { "init_trainer_kwargs": { "init_rl_kwargs": { "learning_rate": tune.grid_search(np.logspace(3e-6, 1e-1, num=3)), "nminibatches": tune.grid_search([16, 32, 64]), }, }, }, } base_config_updates = { "init_tensorboard": True, "init_trainer_kwargs": {"use_gail": True}, }
Example 22
Project: transferlearning Author: jindongwang File: proxy_a_distance.py License: MIT License | 5 votes |
def proxy_a_distance(source_X, target_X, verbose=False): """ Compute the Proxy-A-Distance of a source/target representation """ nb_source = np.shape(source_X)[0] nb_target = np.shape(target_X)[0] if verbose: print('PAD on', (nb_source, nb_target), 'examples') C_list = np.logspace(-5, 4, 10) half_source, half_target = int(nb_source/2), int(nb_target/2) train_X = np.vstack((source_X[0:half_source, :], target_X[0:half_target, :])) train_Y = np.hstack((np.zeros(half_source, dtype=int), np.ones(half_target, dtype=int))) test_X = np.vstack((source_X[half_source:, :], target_X[half_target:, :])) test_Y = np.hstack((np.zeros(nb_source - half_source, dtype=int), np.ones(nb_target - half_target, dtype=int))) best_risk = 1.0 for C in C_list: clf = svm.SVC(C=C, kernel='linear', verbose=False) clf.fit(train_X, train_Y) train_risk = np.mean(clf.predict(train_X) != train_Y) test_risk = np.mean(clf.predict(test_X) != test_Y) if verbose: print('[ PAD C = %f ] train risk: %f test risk: %f' % (C, train_risk, test_risk)) if test_risk > .5: test_risk = 1. - test_risk best_risk = min(best_risk, test_risk) return 2 * (1. - 2 * best_risk)
Example 23
Project: fast-MPN-COV Author: jiangtaoxie File: main.py License: MIT License | 5 votes |
def log(self, params, total_epoch): params = params[0] left_range = params[0] right_range = params[1] np_lr = np.logspace(left_range, right_range, total_epoch) lr_factor = [1] lr = [np_lr[0]] for epoch in range(1, total_epoch): lr.append(np_lr[epoch]) lr_factor.append(np_lr[epoch]/np_lr[epoch-1]) if lr[0] != args.lr: args.lr = lr[0] return lr_factor, lr
Example 24
Project: EXOSIMS Author: dsavransky File: test_BrownvGarrett.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_target_completeness_def(self): """ Compare calculated completenesses for multiple targets under default population settings. """ with RedirectStreams(stdout=self.dev_null): TL = TargetList(ntargs=100,**copy.deepcopy(self.spec)) mode = list(filter(lambda mode: mode['detectionMode'] == True, TL.OpticalSystem.observingModes))[0] IWA = mode['IWA'] OWA = mode['OWA'] rrange = TL.PlanetPopulation.rrange maxd = (rrange[1]/np.tan(IWA)).to(u.pc).value mind = (rrange[0]/np.tan(OWA)).to(u.pc).value #want distances to span from outer edge below IWA to inner edge above OWA TL.dist = np.logspace(np.log10(mind/10.),np.log10(maxd*10.),TL.nStars)*u.pc Brown = EXOSIMS.Completeness.BrownCompleteness.BrownCompleteness(**copy.deepcopy(self.spec)) Garrett = EXOSIMS.Completeness.GarrettCompleteness.GarrettCompleteness(**copy.deepcopy(self.spec)) cBrown = Brown.target_completeness(TL) cGarrett = Garrett.target_completeness(TL) np.testing.assert_allclose(cGarrett,cBrown,rtol=0.1,atol=1e-6) # test when scaleOrbits == True TL.L = np.exp(np.random.uniform(low=np.log(0.1), high=np.log(10.), size=TL.nStars)) Brown.PlanetPopulation.scaleOrbits = True Garrett.PlanetPopulation.scaleOrbits = True cBrown = Brown.target_completeness(TL) cGarrett = Garrett.target_completeness(TL) cGarrett = cGarrett[cBrown != 0 ] cBrown = cBrown[cBrown != 0] meandiff = np.mean(np.abs(cGarrett - cBrown)/cBrown) self.assertLessEqual(meandiff,0.1)
Example 25
Project: EXOSIMS Author: dsavransky File: statsFun.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def eqLogSample(f, numTest, xMin, xMax, bins=10): out = np.array([]) bounds = np.logspace(np.log10(xMin),np.log10(xMax),bins+1) for j in np.arange(1,bins+1): out = np.concatenate((out,simpSample(f,numTest/bins,bounds[j-1],bounds[j]))) return out
Example 26
Project: simnibs Author: simnibs File: adaptive.py License: GNU General Public License v3.0 | 5 votes |
def __init__(self, pdftype, pdfshape, limits, order, order_max, interaction_order, grid, regularization_factors=np.logspace(-5, 3, 9)): super().__init__(pdftype, pdfshape, limits, order, order_max, interaction_order, grid) self.regularization_factors = regularization_factors
Example 27
Project: python-control Author: python-control File: margin_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_stability_margins(self): omega = np.logspace(-2, 2, 2000) for sys,rgm,rwgm,rpm,rwpm in self.tsys: print(sys) out = np.array(stability_margins(sys)) gm, pm, sm, wg, wp, ws = out outf = np.array(stability_margins(FRD(sys, omega))) print(out,'\n', outf) #print(out != np.array(None)) assert_array_almost_equal( out, outf, 2) # final one with fixed values assert_array_almost_equal( [gm, pm, sm, wg, wp, ws], self.stability_margins4, 3)
Example 28
Project: python-control Author: python-control File: margin_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_mag_phase_omega(self): # test for bug reported in gh-58 sys = TransferFunction(15, [1, 6, 11, 6]) out = stability_margins(sys) omega = np.logspace(-2,2,1000) mag, phase, omega = sys.freqresp(omega) #print( mag, phase, omega) out2 = stability_margins((mag, phase*180/np.pi, omega)) ind = [0,1,3,4] # indices of gm, pm, wg, wp -- ignore sm marg1 = np.array(out)[ind] marg2 = np.array(out2)[ind] assert_array_almost_equal(marg1, marg2, 4)
Example 29
Project: python-control Author: python-control File: frd_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def testOperatorsTf(self): # get two SISO transfer functions h1 = TransferFunction([1], [1, 2, 2]) h2 = TransferFunction([1], [0.1, 1]) omega = np.logspace(-1, 2, 10) f1 = FRD(h1, omega) f2 = FRD(h2, omega) f2 # reference to avoid pyflakes error np.testing.assert_array_almost_equal( (f1 + h2).freqresp([0.1, 1.0, 10])[0], (h1 + h2).freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( (f1 + h2).freqresp([0.1, 1.0, 10])[1], (h1 + h2).freqresp([0.1, 1.0, 10])[1]) np.testing.assert_array_almost_equal( (f1 - h2).freqresp([0.1, 1.0, 10])[0], (h1 - h2).freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( (f1 - h2).freqresp([0.1, 1.0, 10])[1], (h1 - h2).freqresp([0.1, 1.0, 10])[1]) # multiplication and division np.testing.assert_array_almost_equal( (f1 * h2).freqresp([0.1, 1.0, 10])[1], (h1 * h2).freqresp([0.1, 1.0, 10])[1]) np.testing.assert_array_almost_equal( (f1 / h2).freqresp([0.1, 1.0, 10])[1], (h1 / h2).freqresp([0.1, 1.0, 10])[1]) # the reverse does not work
Example 30
Project: python-control Author: python-control File: frd_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def testbdalg(self): # get two SISO transfer functions h1 = TransferFunction([1], [1, 2, 2]) h2 = TransferFunction([1], [0.1, 1]) omega = np.logspace(-1, 2, 10) f1 = FRD(h1, omega) f2 = FRD(h2, omega) np.testing.assert_array_almost_equal( (bdalg.series(f1, f2)).freqresp([0.1, 1.0, 10])[0], (bdalg.series(h1, h2)).freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( (bdalg.parallel(f1, f2)).freqresp([0.1, 1.0, 10])[0], (bdalg.parallel(h1, h2)).freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( (bdalg.feedback(f1, f2)).freqresp([0.1, 1.0, 10])[0], (bdalg.feedback(h1, h2)).freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( (bdalg.negate(f1)).freqresp([0.1, 1.0, 10])[0], (bdalg.negate(h1)).freqresp([0.1, 1.0, 10])[0]) # append() and connect() not implemented for FRD objects # np.testing.assert_array_almost_equal( # (bdalg.append(f1, f2)).freqresp([0.1, 1.0, 10])[0], # (bdalg.append(h1, h2)).freqresp([0.1, 1.0, 10])[0]) # # f3 = bdalg.append(f1, f2, f2) # h3 = bdalg.append(h1, h2, h2) # Q = np.mat([ [1, 2], [2, -1] ]) # np.testing.assert_array_almost_equal( # (bdalg.connect(f3, Q, [2], [1])).freqresp([0.1, 1.0, 10])[0], # (bdalg.connect(h3, Q, [2], [1])).freqresp([0.1, 1.0, 10])[0])