Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Multi Scale Causality
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FROGE Ewen
Multi Scale Causality
Commits
86362879
Commit
86362879
authored
9 months ago
by
FROGE Ewen
Browse files
Options
Downloads
Patches
Plain Diff
Replace Main.py
parent
d8f5eb2e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TE_filters/Main.py
+111
-6
111 additions, 6 deletions
TE_filters/Main.py
with
111 additions
and
6 deletions
TE_filters/Main.py
+
111
−
6
View file @
86362879
...
...
@@ -53,7 +53,7 @@ results = {}
def
gaussian_kernel
(
scale
,
position
):
size
=
2
*
scale
+
1
x
=
np
.
linspace
(
-
size
//
2
,
size
//
2
,
size
)
x
=
np
.
linspace
(
-
(
size
//
2
)
,
size
//
2
,
size
)
kernel
=
np
.
exp
(
-
0.5
*
(
x
/
scale
)
**
2
)
if
position
==
'
causal
'
:
...
...
@@ -68,6 +68,101 @@ def gaussian_kernel(scale, position):
kernel
/=
kernel
.
sum
()
return
kernel
def
gaussian_HP_kernel
(
scale
,
position
):
size
=
2
*
scale
+
1
x
=
np
.
linspace
(
-
(
size
//
2
),
size
//
2
,
size
)
kernel
=
np
.
exp
(
-
0.5
*
(
x
/
scale
)
**
2
)
if
position
==
'
causal
'
:
kernel
[:
scale
]
=
0
elif
position
==
'
anticausal
'
:
kernel
[
scale
+
1
:]
=
0
elif
position
==
'
symmetric
'
:
pass
kernel
/=
kernel
.
sum
()
delta
=
np
.
zeros
(
size
)
delta
[
scale
]
=
1
kernel
=
delta
-
kernel
return
kernel
def
box_HP_kernel
(
scale
,
position
):
size
=
2
*
scale
+
1
kernel
=
np
.
ones
(
size
)
if
position
==
'
causal
'
:
kernel
[:
scale
]
=
0
elif
position
==
'
anticausal
'
:
kernel
[
scale
+
1
:]
=
0
elif
position
==
'
symmetric
'
:
pass
kernel
/=
kernel
.
sum
()
delta
=
np
.
zeros
(
size
)
delta
[
scale
]
=
1
kernel
=
delta
-
kernel
return
kernel
def
gaussian_BP_kernel
(
scale_high
,
position
,
scale_low
=
None
):
if
scale_low
==
None
:
scale_low
=
2
*
scale_high
size
=
2
*
scale_low
+
1
x
=
np
.
linspace
(
-
(
size
//
2
),
size
//
2
,
size
)
kernel_low
=
np
.
exp
(
-
0.5
*
(
x
/
scale_low
)
**
2
)
kernel_high
=
np
.
exp
(
-
0.5
*
(
x
/
scale_high
)
**
2
)
if
position
==
'
causal
'
:
kernel_low
[:
size
//
2
]
=
0
kernel_high
[:
size
//
2
]
=
0
elif
position
==
'
anticausal
'
:
kernel_low
[
size
//
2
+
1
:]
=
0
kernel_high
[
size
//
2
+
1
:]
=
0
elif
position
==
'
symmetric
'
:
pass
kernel_low
/=
kernel_low
.
sum
()
kernel_high
/=
kernel_high
.
sum
()
kernel
=
kernel_low
-
kernel_high
return
kernel
def
box_BP_kernel
(
scale_high
,
position
,
scale_low
=
None
):
if
scale_low
==
None
:
scale_low
=
2
*
scale_high
size
=
2
*
scale_low
+
1
x
=
np
.
linspace
(
-
(
size
//
2
),
size
//
2
,
size
)
kernel_low
=
np
.
zeros
(
size
)
kernel_low
[
np
.
where
(
np
.
abs
(
x
)
<=
scale_low
)]
=
1
kernel_high
=
np
.
zeros
(
size
)
kernel_high
[
np
.
where
(
np
.
abs
(
x
)
<=
scale_low
)]
=
1
if
position
==
'
causal
'
:
kernel_low
[:
size
//
2
]
=
0
kernel_high
[:
size
//
2
]
=
0
elif
position
==
'
anticausal
'
:
kernel_low
[
size
//
2
+
1
:]
=
0
kernel_high
[
size
//
2
+
1
:]
=
0
elif
position
==
'
symmetric
'
:
pass
kernel_low
/=
kernel_low
.
sum
()
kernel_high
/=
kernel_high
.
sum
()
kernel
=
kernel_low
-
kernel_high
return
kernel
def
increment_kernel
(
scale
,
position
):
if
position
==
'
causal
'
:
kernel
=
np
.
zeros
(
2
*
scale
+
1
)
...
...
@@ -92,7 +187,7 @@ def gabor_kernel(scale, position,omega=None):
if
omega
==
None
:
omega
=
1
/
scale
size
=
2
*
scale
+
1
x
=
np
.
linspace
(
-
size
//
2
,
size
//
2
,
size
)
x
=
np
.
linspace
(
-
(
size
//
2
)
,
size
//
2
,
size
)
if
position
==
'
causal
'
:
...
...
@@ -128,7 +223,10 @@ kernel_functions = {
'
increment
'
:
increment_kernel
,
'
gaussian
'
:
gaussian_kernel
,
'
gabor
'
:
gabor_kernel
,
'
box
'
:
box_kernel
'
box
'
:
box_kernel
,
'
box_HP
'
:
box_HP_kernel
,
'
gaussian_HP
'
:
gaussian_HP_kernel
,
}
kernel_types
=
kernel_functions
.
keys
()
...
...
@@ -207,7 +305,12 @@ for kernel_type in kernel_types:
# %%
# Plotting impulse response for each filter
# Impulse Response Plotting
#kernel_types=['increment','box','gaussian','gabor']
kernel_types
=
[
'
box_HP
'
,
'
gaussian_HP
'
]
#kernel_types=['box_BP','gaussian_BP']
impulse
=
np
.
zeros
(
100
)
impulse
[
len
(
impulse
)
//
2
]
=
1
...
...
@@ -225,10 +328,11 @@ for i, kernel_type in enumerate(kernel_types):
kernel
=
kernel_functions
[
kernel_type
](
scale
,
position
)
impulse_response
=
convolve
(
impulse
,
kernel
,
mode
=
'
same
'
)
ax
.
plot
(
impulse_response
,
label
=
f
'
Scale=
{
scale
}
'
)
ax
.
axhline
(
0
,
color
=
'
black
'
,
linestyle
=
'
--
'
)
# Add horizontal line at 0
ax
.
legend
(
fontsize
=
24
)
plt
.
tight_layout
(
rect
=
[
0
,
0
,
1
,
0.95
])
plt
.
savefig
(
'
/users2/local/e22froge/codes/TE_Filter/Impulse_responses.pdf
'
,
bbox_inches
=
'
tight
'
)
plt
.
savefig
(
'
/users2/local/e22froge/codes/TE_Filter/Impulse_responses
_HP
.pdf
'
,
bbox_inches
=
'
tight
'
)
plt
.
show
()
#%%
...
...
@@ -245,10 +349,11 @@ for i, kernel_type in enumerate(kernel_types):
for
scale
in
scales
:
kernel
=
kernel_functions
[
kernel_type
](
scale
,
position
)
ax
.
plot
(
kernel
,
label
=
f
'
Scale=
{
scale
}
'
)
ax
.
axhline
(
0
,
color
=
'
black
'
,
linestyle
=
'
--
'
)
# Add horizontal line at 0
ax
.
legend
(
fontsize
=
24
)
plt
.
tight_layout
(
rect
=
[
0
,
0
,
1
,
0.95
])
plt
.
savefig
(
'
/users2/local/e22froge/codes/TE_Filter/Kernels.pdf
'
,
bbox_inches
=
'
tight
'
)
plt
.
savefig
(
'
/users2/local/e22froge/codes/TE_Filter/Kernels
_HP
.pdf
'
,
bbox_inches
=
'
tight
'
)
plt
.
show
()
# %%
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment