コード例 #1
0
def test_orthomax(whiten_method):
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition()
    s.blind_source_separation(2,
                              algorithm="orthomax",
                              whiten_method=whiten_method)

    s.learning_results.bss_factors[:, 0] *= -1
    s._auto_reverse_bss_component("loadings")
    np.testing.assert_array_less(s.learning_results.bss_factors[:, 0], 0)
    np.testing.assert_array_less(0, s.learning_results.bss_factors[:, 1])
    s._auto_reverse_bss_component("factors")
    np.testing.assert_array_less(0, s.learning_results.bss_factors)

    # Verify that we can change gamma for orthomax method
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition()
    s.blind_source_separation(2, algorithm="orthomax", gamma=2)
コード例 #2
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_num_components_error():
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition()
    s.learning_results.output_dimension = None

    with pytest.raises(
        ValueError, match="No `number_of_components` or `comp_list` provided"
    ):
        s.blind_source_separation(number_of_components=None)
コード例 #3
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_factors_error():
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition()

    factors = s.get_decomposition_factors().data

    with pytest.raises(TypeError, match="`factors` must be a BaseSignal instance"):
        s.blind_source_separation(2, factors=factors)

    factors = BaseSignal(s.get_decomposition_factors().data)

    with pytest.raises(ValueError, match="`factors` must have navigation dimension"):
        s.blind_source_separation(2, factors=factors)
コード例 #4
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_orthomax(whiten_method):
    rng = np.random.RandomState(123)
    S = rng.laplace(size=(3, 500))
    A = rng.random((3, 3))
    s = Signal1D(A @ S)
    s.decomposition()
    s.blind_source_separation(3, algorithm="orthomax", whiten_method=whiten_method)

    W = s.learning_results.unmixing_matrix
    assert amari(W, A) < 0.5

    # Verify that we can change gamma for orthomax method
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition()
    s.blind_source_separation(2, algorithm="orthomax", gamma=2)
コード例 #5
0
def test_get_core_loss_eels_line_scan_signal(add_powerlaw, add_noise):
    s = ad.get_core_loss_eels_line_scan_signal(add_powerlaw, add_noise)
    assert s.metadata.Signal.signal_type == 'EELS'
コード例 #6
0
 def setup_method(self, method):
     s = get_core_loss_eels_line_scan_signal(True)
     self.signal = s
     er = EdgesRange(self.signal)
     self.er = er
コード例 #7
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_algorithm_error():
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition()

    with pytest.raises(ValueError, match="'algorithm' not recognised"):
        s.blind_source_separation(2, algorithm="uniform")
コード例 #8
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_components_list():
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition(output_dimension=3)
    s.blind_source_separation(comp_list=[0, 2])
    assert s.learning_results.unmixing_matrix.shape == (2, 2)
コード例 #9
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_num_components(num_components):
    s = artificial_data.get_core_loss_eels_line_scan_signal()
    s.decomposition(output_dimension=2)
    s.blind_source_separation(number_of_components=num_components)
コード例 #10
0
ファイル: test_bss.py プロジェクト: pc494/hyperspy
def test_no_decomposition_error():
    s = artificial_data.get_core_loss_eels_line_scan_signal()

    with pytest.raises(AttributeError, match="A decomposition must be performed"):
        s.blind_source_separation(2)
コード例 #11
0
def test_plot_eels_labels_nav():
    s = get_core_loss_eels_line_scan_signal(True)
    s.add_elements(['Cr', 'Fe'])
    s.plot(plot_edges=True)
    s.axes_manager.indices = (10, )
    s._plot.close()
コード例 #12
0
def test_plot_eels_labels():
    s = get_core_loss_eels_line_scan_signal(True, random_state=10)
    s.add_elements(['Cr'])
    s.plot(plot_edges=True)
    return s._plot.signal_plot.figure
コード例 #13
0
 def setup_method(self, method):
     s = artificial_data.get_core_loss_eels_line_scan_signal()
     s.decomposition()
     s.blind_source_separation(2)
     self.s = s
コード例 #14
0
def test_get_core_loss_eels_line_scan_signal():
    s = ad.get_core_loss_eels_line_scan_signal()
    assert s.metadata.Signal.signal_type == 'EELS'