[090c8c]: / src / __pycache__ / utils.cpython-39.pyc

Download this file

25 lines (25 with data), 2.6 kB

a

i6┬aR	Ń@sîdZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
ddl	mZmZdd
däZdd
äZdddäZdddäZdddäZdS)zL
Authors: Pinar Demetci, Rebecca Santorella
12 February 2020
Utils for SCOT
ÚN)┌dijkstra)┌
csr_matrix)┌kneighbors_graph)┌StandardScaler┌	normalize)┌NearestNeighbors┌KNeighborsClassifier┌l2TcCs0|dvsJdâé|dkrd}nd}t|||dŹS)z┬
	Default norm used is l2-norm. Other options: "l1", and "max"
	If bySample==True, then we independently normalize each sample. If bySample==False, then we independently normalize each feature
	)┌l1r	┌maxz;Norm argument has to be either one of 'max', 'l1', or 'l2'.TÚr)┌norm┌axis)r)┌datar
┌bySampleręr˙7/Users/pinardemetci/Documents/newSCOT/SCOT/src/utils.py┌unit_normalizes
rcCstâ}|á|í}|S)N)r┌
fit_transform)r┌scalerZ
scaledDatarrr┌zscore_standardizes
r┌	euclediancCs tjjj|||dŹ}||áíS)N)┌metric)┌sp┌spatial┌distance┌cdistr)rrZCdatarrr┌get_spatial_distance_matrix!sr┌connectivity┌correlationcCsv|dvsJdâé|dkrd}nd}t|||||dŹ}tt|âdddŹ}tá||tjkí}||||k<||áí}|S)z,
	Compute graph distance matrices on data 
	)rrzENorm argument has to be either one of 'connectivity', or 'distance'. rTF)┌moder┌include_self)┌csgraph┌directed┌return_predecessors)rrr┌np┌nanmax┌infr)rZ
num_neighborsr rr!Z
graph_dataZshortestPath_dataZshortestPath_maxrrr┌get_graph_distance_matrix%sr(FcCsH|dkr(|j|ádíj}tá||í}n||ádíj}tá||í}|S)zŞ
	Given: data in the target space, data in the source space, a coupling matrix learned via Gromow-Wasserstein OT
	Returns: source (target) matrix transported onto the target (source)
	Frr)┌T┌sumr%┌matmul)┌source┌targetZcouplingMatrixZtransposeCoupling┌PZtransported_datarrr┌transport_data7sr/)r	T)r)rr)F)┌__doc__┌numpyr%┌scipyr┌scipy.sparse.csgraphr┌scipy.sparser┌sklearn.neighborsr┌sklearn.preprocessingrrrrrrrr(r/rrrr┌<module>s