def test_nonzero_noise(self): from pylocus.simulation import create_noisy_edm noises = np.logspace(-8, -3, 10) self.create_points() for method in self.methods: for noise in noises: noisy_edm = create_noisy_edm(self.pts.edm, noise) eps = noise * 100 Xhat, costs = call_method(noisy_edm, X0=self.X0, tol=self.eps, method=method) err = np.linalg.norm(Xhat - self.pts.points) self.assertTrue( err < eps, 'error {} not smaller than {}'.format(err, eps))
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
#! /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 add_noise(self, noise=1e-6): self.pts.edm = create_noisy_edm(self.pts.edm, noise)