Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed converters and the static interface and added an r static examp…
…le for Jade
- Loading branch information
1 parent
ee75cd5
commit 5c3603f
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
examples/undocumented/r_static/graphical/converter_jade_bss.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Blind Source Separation using the Jade Algorithm with Shogun | ||
# | ||
# Based on the example from scikit-learn | ||
# http://scikit-learn.org/ | ||
# | ||
# Kevin Hughes 2013 | ||
|
||
library('sg') | ||
|
||
# Generate sample data | ||
n_samples <- 2000 | ||
time <- seq(0,10,length=n_samples) | ||
|
||
# Source Signals | ||
S <- matrix(0,2,n_samples) | ||
S[1,] <- sin(2*time) | ||
S[2,] <- sign(sin(3*time)) | ||
S <- S + 0.2*matrix(runif(2*n_samples),2,n_samples) | ||
|
||
# Standardize data | ||
S <- S * (1/apply(S,1,sd)) | ||
|
||
# Mixing Matrix | ||
A <- rbind(c(1,0.5),c(0.5,1)) | ||
|
||
# Mix Signals | ||
X <- A %*% S | ||
mixed_signals <- matrix(X,2,n_samples) | ||
|
||
# Separating | ||
sg('set_converter', 'jade') | ||
sg('set_features', 'TRAIN', mixed_signals) | ||
S_ <- sg('apply_converter') | ||
|
||
# Plot | ||
par(mfcol=c(3,1)); | ||
|
||
plot(time, S[1,], type="l", col='blue', main="True Sources", ylab="", xlab="") | ||
lines(time, S[2,], type="l", col='green') | ||
|
||
plot(time, X[1,], type="l", col='blue', main="Mixed Sources", ylab="", xlab="") | ||
lines(time, X[2,], type="l", col='green') | ||
|
||
plot(time, S_[1,], type="l", col='blue', main="Estimated Sources", ylab="", xlab="") | ||
lines(time, S_[2,], type="l", col='green') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters