Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Make function injective

Subject: Make function injective

From: Armin Mueller

Date: 21 Nov, 2010 20:15:45

Message: 1 of 5

Dear NG,

I would like to calculate the inverse function of a (measured) curve
which should be strictly decreasing. However, the data is noisy and not
100% perfect.

To fix the curve, I've written some lines of code that drop all points
that are increasing or level. However, I have the dim feeling that the
code could be shorter and more elegant. Any idea how?

Thanks,
Armin


% Fix curve to be injective
function isinj = injective(curve)

if any(diff(curve(isfinite(curve)))>0)
   warning('Curve not monotonically decreasing')
elseif any(diff(curve(isfinite(curve)))>=0)
   warning('Curve not strictly decreasing')
end

isinj = false(size(curve));
last = Inf;

for idx = 1:length(curve)
   if isfinite(curve(idx)) && curve(idx)<last
     isinj(idx) = true;
     last = curve(idx);
   end
end

return

% Test cases

injective([4 3 2 1 0]) % OK, strictly decreasing
% ans = 1 1 1 1 1
injective([4 3 3 2 0]) % monotonically decreasing
% ans = 1 1 0 1 1
injective([4 1 2 2 0]) % bad
% ans = 1 1 0 0 1

Subject: Make function injective

From: Roger Stafford

Date: 21 Nov, 2010 21:43:03

Message: 2 of 5

Armin Mueller <arm.in@web.de> wrote in message <icbulh$440$1@news2.rz.uni-karlsruhe.de>...
> Dear NG,
>
> I would like to calculate the inverse function of a (measured) curve
> which should be strictly decreasing. However, the data is noisy and not
> 100% perfect.
>
> To fix the curve, I've written some lines of code that drop all points
> that are increasing or level. However, I have the dim feeling that the
> code could be shorter and more elegant. Any idea how?
> .......
- - - - - - - - - - -
  Why not do a sort with the decreasing option on 'curve'? If its deviation from non-increasing monotonicity is due only to small noise effects, the swapping of 'curve' values due to the sorting would all occur in local regions and the over-all curve's characteristics would be essentially preserved. This way you would not have to drop any points at all.

  Such a procedure may seem heretical because it violates the sanctity of the curve's ordinate and abscissa value pairings, but that really is no more fundamental a change than the disturbance produced by noise, assuming that the theoretical noise-free curve is indeed monotone.

  This does not necessarily produce a strictly decreasing result. For that you would have to play further tricks on the curve values. I can think of a few but I'll let you ponder the matter.

  Another notion would be to apply some sort of smoothing filter to the curve values which would hopefully render it monotone if done properly. The choice of appropriate filter would of course depend on the nature of the noise.

Roger Stafford

Subject: Make function injective

From: John D'Errico

Date: 21 Nov, 2010 22:16:04

Message: 3 of 5

Armin Mueller <arm.in@web.de> wrote in message <icbulh$440$1@news2.rz.uni-karlsruhe.de>...
> Dear NG,
>
> I would like to calculate the inverse function of a (measured) curve
> which should be strictly decreasing. However, the data is noisy and not
> 100% perfect.
>
> To fix the curve, I've written some lines of code that drop all points
> that are increasing or level. However, I have the dim feeling that the
> code could be shorter and more elegant. Any idea how?

For noisy data, use a smoothing tool that can handle
a monotonicity constraint. This capability is available
in my SLM tools. Find them here:

http://www.mathworks.com/matlabcentral/fileexchange/24443

SLM allows you to build curve fits using a huge variety
of constraints.

John

Subject: Make function injective

From: Armin Mueller

Date: 22 Nov, 2010 20:14:51

Message: 4 of 5

Roger Stafford wrote:

> Why not do a sort with the decreasing option on 'curve'? If its
> deviation from non-increasing monotonicity is due only to small noise
> effects, the swapping of 'curve' values due to the sorting would all
> occur in local regions [...]

Dear Roger,

your idea sounds most interesting! I have to try it with my data. Data
rate is low, there are only about 20 to 30 samples. If there is a spike,
swapping two values could possibly interfere more than just ignoring the
spike.

> This does not necessarily produce a strictly decreasing result. [...]

Yep.

Cheers
Armin

Subject: Make function injective

From: Armin Mueller

Date: 22 Nov, 2010 20:17:34

Message: 5 of 5

John D'Errico wrote:

> [...] SLM allows you to build curve fits using a huge variety of
> constraints.

Dear John,

this is definitely the big iron. I've already wondered what I should to
in the evening :-)

Cheers,
Armin

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us