Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using variable name I in C code #226

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ classifiers =

[options]
install_requires =
numpy >= 1.24
numpy >= 1.24, < 2.0
scipy >= 1.10
igraph >= 0.11
h5netcdf >= 1.1 ; python_version >= "3.9"
Expand Down
16 changes: 8 additions & 8 deletions src/pyunicorn/core/_ext/src_numerics.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ double _vertex_current_flow_betweenness_fast(int N, double Is, double It,
int t=0;
int s=0;
int j=0;
double I=0;
double J=0;

for(t=0;t<N;t++){
for(s=0; s<t; s++){
I = 0.0;
J = 0.0;
if(i == t || i == s){
continue;
}
else{
for(j=0;j<N;j++){
I += admittance[i*N+j]*
J += admittance[i*N+j]*
fabs( Is*(R[i*N+s]-R[j*N+s])+
It*(R[j*N+t]-R[i*N+t])
) / 2.0;
} // for j
}
VCFB += 2.0*I/(N*(N-1));
VCFB += 2.0*J/(N*(N-1));
} // for s
} // for t

Expand All @@ -149,19 +149,19 @@ void _edge_current_flow_betweenness_fast(int N, double Is, double It,
int j=0;
int t=0;
int s=0;
double I = 0.0;
double J = 0.0;

for(i=0; i<N; i++){
for(j=0;j<N;j++){
I = 0.0;
J = 0.0;
for(t=0;t<N;t++){
for(s=0; s<t; s++){
I += admittance[i*N+j]*\
J += admittance[i*N+j]*\
fabs(Is*(R[i*N+s]-R[j*N+s])+
It*(R[j*N+t]-R[i*N+t]));
} //for s
} // for t
ECFB[i*N+j] += (float) (2.* I/(N*(N-1)));
ECFB[i*N+j] += (float) (2.* J/(N*(N-1)));
} // for j
} // for i
}
46 changes: 45 additions & 1 deletion tests/test_timeseries/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from numpy.testing import assert_array_almost_equal

from pyunicorn.timeseries import CrossRecurrencePlot, \
InterSystemRecurrenceNetwork, Surrogates, VisibilityGraph
RecurrenceNetwork, InterSystemRecurrenceNetwork, \
Surrogates, VisibilityGraph
from pyunicorn.core.data import Data
from pyunicorn.core._ext.types import DFIELD

Expand Down Expand Up @@ -69,6 +70,49 @@ def testCrossRecurrencePlot(thresh, rr, metric: str):
assert CR1.dtype == np.int8


# -----------------------------------------------------------------------------
# recurrence_network
# -----------------------------------------------------------------------------

@pytest.mark.parametrize("thresh, rr",
[(.2, None), (None, .2)], ids=str)
def testRecurrenceNetwork(thresh, rr, metric: str):
# create two instances of the same test dataset
tdata1 = create_test_data()
tdata2 = create_test_data()
# create RecurrenceNetwork for both
rn1 = RecurrenceNetwork(
tdata1, threshold=thresh, recurrence_rate=rr, metric=metric)
rn2 = RecurrenceNetwork(
tdata2, threshold=thresh, recurrence_rate=rr, metric=metric)
# get respective adjacency matrices
A1 = rn1.adjacency
A2 = rn2.adjacency

assert np.array_equal(A1, A2)
assert A1.shape == A2.shape
assert A1.shape == (len(tdata1), len(tdata1))
assert A1.dtype == A2.dtype
assert A1.dtype == np.int16


def testRecurrenceNetwork_setters():
tdata = create_test_data()
rn = RecurrenceNetwork(tdata, threshold=.2)
# recalculate with different fixed threshold
rn.set_fixed_threshold(.3)
assert rn.adjacency.shape == (len(tdata), len(tdata))
# recalculate with fixed threshold in units of the ts' std
rn.set_fixed_threshold_std(.3)
assert rn.adjacency.shape == (len(tdata), len(tdata))
# recalculate with fixed recurrence rate
rn.set_fixed_recurrence_rate(.2)
assert rn.adjacency.shape == (len(tdata), len(tdata))
# recalculate with fixed local recurrence rate
rn.set_fixed_local_recurrence_rate(.2)
assert rn.adjacency.shape == (len(tdata), len(tdata))


# -----------------------------------------------------------------------------
# inter_system_recurrence_network
# -----------------------------------------------------------------------------
Expand Down