Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
condynet
PyPSD
Commits
f4465c69
Commit
f4465c69
authored
Mar 06, 2017
by
Frank Hellmann
Browse files
Added classical model for test purposes
parent
3f9b89b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
PSD/__init__.py
0 → 100644
View file @
f4465c69
PSD/classic_model.py
0 → 100644
View file @
f4465c69
from
__future__
import
absolute_import
,
print_function
,
division
,
unicode_literals
import
numpy
as
np
import
networkx
as
nx
import
scipy.sparse
as
sps
def
define_oscillator_rhs
(
dim
):
nn
=
dim
//
2
def
right_hand_side
(
y
,
t
,
coupling
,
infeed
,
droop
):
phases
=
np
.
exp
(
1.j
*
y
[:
nn
])
return
np
.
append
(
y
[
nn
:],
infeed
-
droop
*
y
[
nn
:]
-
np
.
imag
(
phases
*
coupling
.
dot
(
phases
).
conjugate
()))
return
right_hand_side
def
find_fixpoint
(
self
,
args
,
fp_guess
=
None
):
from
scipy.optimize
import
root
if
fp_guess
is
None
:
fp_guess
=
np
.
zeros
(
self
.
size_of_system
*
2
,
dtype
=
np
.
float64
)
res
=
root
(
lambda
x
:
self
.
_rhs
(
x
,
0.
,
*
args
),
fp_guess
)
if
res
.
success
:
return
res
.
x
else
:
print
(
"Failed to find fix point"
)
return
None
def
calculate_rhs_args
(
G
):
coupling
=
8.
*
sps
.
csr_matrix
(
nx
.
adj_matrix
(
G
))
size
=
len
(
G
)
droop
=
0.1
infeed
=
np
.
ones
(
size
,
dtype
=
np
.
float64
)
infeed
[:
size
//
2
]
=
-
1.
infeed
[
-
1
]
-=
np
.
sum
(
infeed
)
return
coupling
,
infeed
,
droop
,
size
def
define_rc_gen
(
G
,
brp
):
coupling
,
infeed
,
droop
,
size
=
calculate_rhs_args
(
G
)
num_batch_inv
=
1.
/
brp
.
number_of_batches
def
gen
(
batch
,
run
):
ic
=
np
.
random
.
random
(
brp
.
system_dimension
)
-
0.5
ic
[:
size
]
*=
2.
*
np
.
pi
ic
[
size
:]
*=
1.0
return
ic
,
(
batch
*
num_batch_inv
*
coupling
,
infeed
,
droop
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment