资源简介
文件中不用python自带的工具实现了ICA的过程,可以直接使用,并文件中可以直接用图示展示ICA处理前后数据的变化。
代码片段和文件信息
# -*- coding:UTF-8 -*-
#!/usr/bin/env python
# encoding: utf-8
‘‘‘
@author: malingyu
@contact: 1078553270@qq.com
@software:
@file: ICA_Test.py
@time: 2017/8/29 15:02
‘‘‘
#!/usr/bin/env python
#FastICA from ICA book table 8.4
import scipy.io as sio
import math
import random
import matplotlib.pyplot as plt
from numpy import *
import ICA
n_components = 2
def f1(x period = 4):
return 0.5*(x-math.floor(x/period)*period)
def create_data():
#data number
n = 500
#data time
T = [0.1*xi for xi in range(0 n)]
#source
S = array([[sin(xi) for xi in T] [f1(xi) for xi in T]] float32)
#mix matrix
A = array([[0.8 0.2] [-0.3 -0.7]] float32)
return T S dot(A S)
def whiten(X):
#zero mean
X_mean = X.mean(axis=-1)
X -= X_mean[: newaxis]
#whiten
A = dot(X X.transpose())
D E = linalg.eig(A)
# D2 = linalg.inv(array([[D[0] 0.0] [0.0 D[1]]] float32))
# D2[00] = sqrt(D2[00]); D2[11] = sqrt(D2[11])
D2=sqrt(linalg.inv(diag(D)))
V = dot(D2 E.transpose())
return dot(V X) V
def _logcosh(x fun_args=None alpha = 1):
gx = tanh(alpha * x x);
g_x = gx ** 2;
g_x -= 1.;
g_x *= -alpha
return gx g_x.mean(axis=-1)
def do_decorrelation(W):
#black magic
s u = linalg.eigh(dot(W W.T))
return dot(dot(u * (1. / sqrt(s)) u.T) W)
def do_fastica(X):
n m = X.shape; p = float(m); g = _logcosh
#black magic
X *= sqrt(X.shape[1])
#create w
W = ones((nn) float32)
for i in range(n):
for j in range(i):
W[ij] = random.random()
#compute W
maxIter = 1000
for ii in range(maxIter):
# -----------------nandian
gwtx g_wtx = g(dot(W X))
W1 = do_decorrelation(dot(gwtx X.T) / p - g_wtx[: newaxis] * W)
lim = max( abs(abs(diag(dot(W1 W.T))) - 1) )
W = W1
if lim < 0.0001:
break
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论