Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rli
pbdlib-python
Commits
685191e4
Commit
685191e4
authored
Mar 11, 2019
by
Emmanuel PIGNAT
Browse files
adding linear conditional for transforming into mixture of experts
parent
229f58be
Changes
2
Hide whitespace changes
Inline
Side-by-side
pbdlib/model.py
View file @
685191e4
...
...
@@ -244,6 +244,25 @@ class Model(object):
return
np
.
sum
(
xs
,
axis
=
0
)
def
get_linear_conditional
(
self
,
dim_in
,
dim_out
):
mu_in
,
sigma_in
=
self
.
get_marginal
(
dim_in
)
mu_out
,
sigma_out
=
self
.
get_marginal
(
dim_out
)
# get marginal distribution of x_out
# get conditional distribution of x_out given x_in for each states p(x_out|x_in, k)
_
,
sigma_in_out
=
self
.
get_marginal
(
dim_in
,
dim_out
)
inv_sigma_in_in
=
np
.
linalg
.
inv
(
sigma_in
)
inv_sigma_out_in
=
np
.
einsum
(
'aji,ajk->aik'
,
sigma_in_out
,
inv_sigma_in_in
)
As
=
inv_sigma_out_in
bs
=
mu_out
-
np
.
matmul
(
inv_sigma_out_in
,
mu_in
[:,
:,
None
])[:,
:,
0
]
sigma_est
=
(
sigma_out
-
np
.
matmul
(
inv_sigma_out_in
,
sigma_in_out
))
return
As
,
bs
,
sigma_est
def
condition
(
self
,
data_in
,
dim_in
,
dim_out
,
h
=
None
,
return_gmm
=
False
):
"""
...
...
@@ -289,8 +308,9 @@ class Model(object):
sigma_est
+=
[
sigma_out
[
i
]
-
inv_sigma_out_in
[
-
1
].
dot
(
sigma_in_out
[
i
])]
mu_est
,
sigma_est
=
(
np
.
asarray
(
mu_est
),
np
.
asarray
(
sigma_est
))
if
return_gmm
:
return
mu_est
,
sigma_est
return
h
,
mu_est
,
sigma_est
# return np.mean(mu_est, axis=0)
else
:
...
...
pbdlib/plot.py
View file @
685191e4
...
...
@@ -559,7 +559,7 @@ def plot_gaussian(mu, sigma, dim=None, color='r', alpha=0.5, lw=1, markersize=6,
return
center
,
line
def
plot_y_gaussian
(
x
,
mu
,
sigma
,
dim
=
0
,
alpha
=
1.
,
alpha_fill
=
None
,
color
=
'r'
,
lw
=
1.
,
ax
=
None
):
ax
=
None
,
label
=
None
):
"""
:param mu: [n_states]
...
...
@@ -577,7 +577,7 @@ def plot_y_gaussian(x, mu, sigma, dim=0, alpha=1., alpha_fill=None, color='r', l
if
ax
is
None
:
ax
=
plt
ax
.
plot
(
x
,
mu
[:,
dim
],
alpha
=
alpha
,
color
=
color
)
ax
.
plot
(
x
,
mu
[:,
dim
],
alpha
=
alpha
,
color
=
color
,
label
=
label
)
ax
.
fill_between
(
x
,
mu
[:,
dim
]
-
sigma
[:,
dim
,
dim
]
**
0.5
,
mu
[:,
dim
]
+
sigma
[:,
dim
,
dim
]
**
0.5
,
...
...
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