Python numpy.longfloat() Examples

The following are 7 code examples for showing how to use numpy.longfloat(). 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: indra   Author: sorgerlab   File: test_pathfinding.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def _setup_unsigned_graph():
    edges, signed_edges, edge_beliefs, all_ns = _digraph_setup()
    dg = nx.DiGraph()
    dg.add_edges_from(edges)

    # Add belief
    for e in dg.edges:
        dg.edges[e]['belief'] = edge_beliefs[e]
        dg.edges[e]['weight'] = -np.log(edge_beliefs[e], dtype=np.longfloat)

    # Add namespaces
    nodes1, nodes2 = list(zip(*edges))
    nodes = set(nodes1).union(nodes2)
    for node in nodes:
        ns = node[0]
        _id = node[1]
        dg.nodes[node]['ns'] = ns
        dg.nodes[node]['id'] = _id
    return dg, all_ns 
Example 2
Project: indra   Author: sorgerlab   File: test_indranet_assembler.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_to_digraph():
    ia = IndraNetAssembler([ab1, ab2, ab3, ab4, bc1, bc2, bc3, bc4])
    df = ia.make_df()
    net = IndraNet.from_df(df)
    assert len(net.nodes) == 3
    assert len(net.edges) == 8
    digraph = net.to_digraph(weight_mapping=_weight_mapping)
    assert len(digraph.nodes) == 3
    assert len(digraph.edges) == 2
    assert set([
        stmt['stmt_type'] for stmt in digraph['a']['b']['statements']]) == {
            'Activation', 'Phosphorylation', 'Inhibition', 'IncreaseAmount'}
    assert all(digraph.edges[e].get('belief', False) for e in digraph.edges)
    assert all(isinstance(digraph.edges[e]['belief'],
                          (float, np.longfloat)) for e in digraph.edges)
    assert all(digraph.edges[e].get('weight', False) for e in digraph.edges)
    assert all(isinstance(digraph.edges[e]['weight'],
                          (float, np.longfloat)) for e in digraph.edges)
    digraph_from_df = IndraNet.digraph_from_df(df)
    assert nx.is_isomorphic(digraph, digraph_from_df) 
Example 3
Project: Computable   Author: ktraunmueller   File: test_regression.py    License: MIT License 5 votes vote down vote up
def test_arange_endian(self,level=rlevel):
        """Ticket #111"""
        ref = np.arange(10)
        x = np.arange(10, dtype='<f8')
        assert_array_equal(ref, x)
        x = np.arange(10, dtype='>f8')
        assert_array_equal(ref, x)

#    Longfloat support is not consistent enough across
#     platforms for this test to be meaningful.
#    def test_longfloat_repr(self,level=rlevel):
#        """Ticket #112"""
#        if np.longfloat(0).itemsize > 8:
#            a = np.exp(np.array([1000],dtype=np.longfloat))
#            assert_(str(a)[1:9] == str(a[0])[:8]) 
Example 4
Project: indra   Author: sorgerlab   File: test_indranet_assembler.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_to_signed_graph():
    ia = IndraNetAssembler([ab1, ab2, ab3, ab4, bc1, bc2, bc3, bc4])
    df = ia.make_df()
    net = IndraNet.from_df(df)
    signed_graph = net.to_signed_graph(
        sign_dict=default_sign_dict,
        weight_mapping=_weight_mapping)
    assert len(signed_graph.nodes) == 3
    assert len(signed_graph.edges) == 4
    assert set([stmt['stmt_type'] for stmt in
                signed_graph['a']['b'][0]['statements']]) == {
                    'Activation', 'IncreaseAmount'}
    assert set([stmt['stmt_type'] for stmt in
                signed_graph['a']['b'][1]['statements']]) == {'Inhibition'}
    assert set([stmt['stmt_type'] for stmt in
                signed_graph['b']['c'][0]['statements']]) == {
                    'Activation', 'IncreaseAmount'}
    assert set([stmt['stmt_type'] for stmt in
                signed_graph['b']['c'][1]['statements']]) == {
                    'Inhibition', 'DecreaseAmount'}
    assert all(signed_graph.edges[e].get('belief', False) for e in
               signed_graph.edges)
    assert all(isinstance(signed_graph.edges[e]['belief'],
                          (float, np.longfloat)) for e in signed_graph.edges)
    assert all(signed_graph.edges[e].get('weight', False) for e in
               signed_graph.edges)
    assert all(isinstance(signed_graph.edges[e]['weight'],
                          (float, np.longfloat)) for e in signed_graph.edges) 
Example 5
Project: indra   Author: sorgerlab   File: net.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _complementary_belief(G, edge):
    # Aggregate belief score: 1-prod(1-belief_i)
    np.seterr(all='raise')
    NP_PRECISION = 10 ** -np.finfo(np.longfloat).precision  # Numpy precision
    belief_list = [s['belief'] for s in G.edges[edge]['statements']]
    try:
        ag_belief = np.longfloat(1.0) - np.prod(np.fromiter(
            map(lambda belief: np.longfloat(1.0) - belief, belief_list),
            dtype=np.longfloat))
    except FloatingPointError as err:
        logger.warning('%s: Resetting ag_belief to 10*np.longfloat precision '
                       '(%.0e)' % (err, Decimal(NP_PRECISION * 10)))
        ag_belief = NP_PRECISION * 10
    return ag_belief 
Example 6
Project: ImageFusion   Author: pfchai   File: test_regression.py    License: MIT License 5 votes vote down vote up
def test_arange_endian(self,level=rlevel):
        """Ticket #111"""
        ref = np.arange(10)
        x = np.arange(10, dtype='<f8')
        assert_array_equal(ref, x)
        x = np.arange(10, dtype='>f8')
        assert_array_equal(ref, x)

#    Longfloat support is not consistent enough across
#     platforms for this test to be meaningful.
#    def test_longfloat_repr(self,level=rlevel):
#        """Ticket #112"""
#        if np.longfloat(0).itemsize > 8:
#            a = np.exp(np.array([1000],dtype=np.longfloat))
#            assert_(str(a)[1:9] == str(a[0])[:8]) 
Example 7
Project: AiLearning   Author: apachecn   File: activators.py    License: GNU General Public License v3.0 5 votes vote down vote up
def forward(self, weighted_input):
        return np.longfloat(1.0 / (1.0 + np.exp(-weighted_input)))