From cb739f625921e7fc19113d6d758e27ac69eac24b Mon Sep 17 00:00:00 2001 From: RĂ©mi Flamary Date: Tue, 20 Mar 2018 15:05:57 +0100 Subject: add linear mapping function --- examples/plot_otda_linear_mapping.py | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/plot_otda_linear_mapping.py (limited to 'examples/plot_otda_linear_mapping.py') diff --git a/examples/plot_otda_linear_mapping.py b/examples/plot_otda_linear_mapping.py new file mode 100644 index 0000000..eff2648 --- /dev/null +++ b/examples/plot_otda_linear_mapping.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 20 14:31:15 2018 + +@author: rflamary +""" + +import numpy as np +import pylab as pl +import ot + + + +#%% + + +n=1000 +d=2 +sigma=.1 + +angles=np.random.rand(n,1)*2*np.pi +xs=np.concatenate((np.sin(angles),np.cos(angles)),axis=1)+sigma*np.random.randn(n,2) + +xs[:n//2,1]+=2 + +anglet=np.random.rand(n,1)*2*np.pi +xt=np.concatenate((np.sin(anglet),np.cos(anglet)),axis=1)+sigma*np.random.randn(n,2) +xt[:n//2,1]+=2 + + +A=np.array([[1.5,.7],[.7,1.5]]) +b=np.array([[4,2]]) +xt=xt.dot(A)+b + +#%% + +pl.figure(1,(5,5)) +pl.plot(xs[:,0],xs[:,1],'+') +pl.plot(xt[:,0],xt[:,1],'o') + +#%% + +Ae,be=ot.da.OT_mapping_linear(xs,xt) + +xst=xs.dot(Ae)+be + +##%% + +pl.figure(1,(5,5)) +pl.clf() +pl.plot(xs[:,0],xs[:,1],'+') +pl.plot(xt[:,0],xt[:,1],'o') +pl.plot(xst[:,0],xst[:,1],'+') \ No newline at end of file -- cgit v1.2.3