def test_strange_case(self): xhat = reconstruct_srls(self.edm, self.all_points, W=self.weights) print(xhat[0]) xhat = reconstruct_srls(self.edm, self.all_points, W=self.weights, rescale=False, z=self.all_points[0, 2]) print(xhat[0])
def zero_weights(self, noise=0.1): print('TestSRLS:test_zero_weights({})'.format(noise)) index = np.arange(self.n) other = np.delete(range(self.pts.N), index) edm_noisy = create_noisy_edm(self.pts.edm, noise) # missing anchors N_missing = 2 indices = np.random.choice(other, size=N_missing, replace=False) reduced_points = np.delete(self.pts.points, indices, axis=0) points_missing = create_from_points(reduced_points, PointSet) edm_anchors = np.delete(edm_noisy, indices, axis=0) edm_anchors = np.delete(edm_anchors, indices, axis=1) missing_anchors = reconstruct_srls(edm_anchors, points_missing.points, n=self.n, W=None, print_out=False) # missing distances weights = np.ones(edm_noisy.shape) weights[indices, index] = 0.0 weights[index, indices] = 0.0 missing_distances = reconstruct_srls(edm_noisy, self.pts.points, n=self.n, W=weights) left_distances = np.delete(range(self.pts.N), indices) self.assertTrue( np.linalg.norm(missing_distances[left_distances, :] - missing_anchors) < self.eps, 'anchors moved.') self.assertTrue( np.linalg.norm(missing_distances[index, :] - missing_anchors[index, :]) < self.eps, 'point moved.') if noise == 0.0: error = np.linalg.norm(missing_anchors - points_missing.points) u, s, v = np.linalg.svd(self.pts.points[other, :]) try: self.assertTrue(error < self.eps, 'error {}'.format(error)) except: print( 'failed with anchors (this can be due to unlucky geometry):', points_missing.points) raise
def call_method(self, method=''): print('TestSRLS:call_method') if method == '' or method == 'normal': return reconstruct_srls(self.pts.edm, self.pts.points, W=np.ones(self.pts.edm.shape)) elif method == 'rescale': return reconstruct_srls(self.pts.edm, self.pts.points, W=np.ones(self.pts.edm.shape), rescale=True) elif method == 'fixed' and self.pts.d == 3: return reconstruct_srls(self.pts.edm, self.pts.points, W=np.ones(self.pts.edm.shape), rescale=False, z=self.pts.points[0, 2])
def test_srls_fixed(self): self.create_points(N=10, d=3) zreal = self.pts.points[0, 2] xhat = reconstruct_srls(self.pts.edm, self.pts.points, n=self.n, W=np.ones(self.pts.edm.shape), rescale=False, z=self.pts.points[0, 2]) self.assertEqual(xhat[0, 2], zreal) np.testing.assert_allclose(xhat, self.pts.points)
def test_srls_fixed(self): print('TestSRLS:test_srls_fixed') self.create_points(N=10, d=3) zreal = self.pts.points[0, 2] xhat = reconstruct_srls(self.pts.edm, self.pts.points, W=np.ones(self.pts.edm.shape), rescale=False, z=zreal) if xhat is not None: np.testing.assert_allclose(xhat[0, 2], zreal) np.testing.assert_allclose(xhat, self.pts.points)
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import numpy as np from pylocus.point_set import PointSet from pylocus.algorithms import reconstruct_srls from pylocus.simulation import create_noisy_edm, create_mask, create_weights from pylocus.basics import mse, rmse points = PointSet(N=5, d=2) points.set_points('random') print("point to localize:", points.points[0, :]) print("anchors:", points.points[1:, :]) std = 0.1 edm_noisy = create_noisy_edm(points.edm, noise=std) mask = create_mask(points.N, method='none') weights = create_weights(points.N, method='one') weights = np.multiply(mask, weights) points_estimated = reconstruct_srls(edm_noisy, points.points, W=weights) error = mse(points_estimated[0, :], points.points[0, :]) print("estimated point: {}, original point: {}, mse: {:2.2e}".format( points_estimated[0, :], points.points[0, :], error))
def call_method(self): print('TestSRLS:call_method') return reconstruct_srls(self.pts.edm, self.pts.points, indices=[self.index], W=np.ones(self.pts.edm.shape))