资源简介
TSNE 降维方法
代码片段和文件信息
#
# tsne.py
#
# Implementation of t-SNE in Python. The implementation was tested on Python
# 2.7.10 and it requires a working installation of NumPy. The implementation
# comes with an example on the MNIST dataset. In order to plot the
# results of this example a working installation of matplotlib is required.
#
# The example can be run by executing: ‘ipython tsne.py‘
#
#
# Created by Laurens van der Maaten on 20-12-08.
# Copyright (c) 2008 Tilburg University. All rights reserved.
import numpy as np
import pylab
def Hbeta(D=np.array([]) beta=1.0):
“““
Compute the perplexity and the P-row for a specific value of the
precision of a Gaussian distribution.
“““
# Compute P-row and corresponding perplexity
P = np.exp(-D.copy() * beta)
sumP = sum(P)
H = np.log(sumP) + beta * np.sum(D * P) / sumP
P = P / sumP
return H P
def x2p(X=np.array([]) tol=1e-5 perplexity=30.0):
“““
Performs a binary search to get P-values in such a way that each
conditional Gaussian has the same perplexity.
“““
# Initialize some variables
print(“Computing pairwise distances...“)
(n d) = X.shape
sum_X = np.sum(np.square(X) 1)
D = np.add(np.add(-2 * np.dot(X X.T) sum_X).T sum_X)
P = np.zeros((n n))
beta = np.ones((n 1))
logU = np.log(perplexity)
# Loop over all datapoints
for i in range(n):
# Print progress
if i % 500 == 0:
print(“Computing P-values for point %d of %d...“ % (i n))
# Compute the Gaussian kernel and entropy for the current precision
betamin = -np.inf
betamax = np.inf
Di = D[i np.concatenate((np.r_[0:i] np.r_[i+1:n]))]
(H thisP) = Hbeta(Di beta[i])
# Evaluate whether the perplexity is within tolerance
Hdiff = H - logU
tries = 0
while np.abs(Hdiff) > tol and tries < 50:
# If not increase or decrease precision
if Hdiff > 0:
betamin = beta[i].copy()
if betamax == np.inf or betamax == -np.inf:
beta[i] = beta[i] * 2.
else:
beta[i] = (beta[i] + betamax) / 2.
else:
betamax = beta[i].copy()
if betamin == np.inf or betamin == -np.inf:
beta[i] = beta[i] / 2.
else:
beta[i] = (beta[i] + betamin) / 2.
# Recompute the values
(H thisP) = Hbeta(Di beta[i])
Hdiff = H - logU
tries += 1
# Set the final row of P
P[i np.concatenate((np.r_[0:i] np.r_[i+1:n]))] = thisP
# Return final P-matrix
print(“Mean value of sigma: %f“ % np.mean(np.sqrt(1 / beta)))
return P
def pca(X=np.array([]) no_dims=50):
“““
Runs PCA on the NxD array X in order to reduce its dimensionality to
no_dims dimensions.
“““
print(“Preprocessing the data using P
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-09 17:13 tsne_python\
文件 42500 2008-12-30 18:13 tsne_python\mnist2500_labels.txt
目录 0 2019-03-18 14:46 __MACOSX\
目录 0 2019-03-18 14:46 __MACOSX\tsne_python\
文件 268 2008-12-30 18:13 __MACOSX\tsne_python\._mnist2500_labels.txt
文件 31362500 2008-12-30 18:13 tsne_python\mnist2500_X.txt
文件 268 2008-12-30 18:13 __MACOSX\tsne_python\._mnist2500_X.txt
文件 5807 2017-12-15 22:27 tsne_python\tsne.py
文件 549 2017-12-15 22:27 __MACOSX\tsne_python\._tsne.py
文件 212 2019-01-09 17:13 __MACOSX\._tsne_python
- 上一篇:Epicor10中Adapter使用封装
- 下一篇:基于dsp的胎心率测量
相关资源
- 航空公司预测乘客数量--测试过小
- 广工人工智能——决策树实验报告.
- 国科大高级人工智能18-19回忆版
- 深度学习方法在图像处理中的应用与
- 人工智能原理及其应用(王万森)第
- 人工智能线性代数基础
- cudart64_101.zip
- 人工智能课程
- 人工智能导论大作业(学长版)
- 人工智能 猴子摘香蕉
- 人工智能四子棋对抗AI
- 人工智能 水壶问题的求解.rar
- 人工智能 基于归结原理的推理系统
- 人工智能基础教程 12硬币问题.rar
- 八数码Astar算法js实现-人工智能大作业
- 物联网与人工智能
- 大数据云计算物联网人工智能四者的
- 人工智能产品经理最佳实践教程
- 信号与数据处理中的低秩模型——理
- 序列优化算法改写
- 什么是极限学习机
- 人工智能大作业pacman满分代码
- ESN和CRJ网络
- 逻辑回归实战代码
- 浅析机器学习的研究与应用
- 基于BP神经网络的企业核心竞争力评价
- 人工智能-知识图谱-实战.docx
- 人工智能实验报告2份 Prolog语言编程练
- 人工智能及其应用课后答案
- A*算法实现迷宫问题
评论
共有 条评论