Construct the complete curve from one segment of it

I wish to construct the complete curve from one available segment of it. For example, d1(:,2) is the complete curve; how to construct this full curve from one segment of it i.e. d1(130:270,2)? Again if I have two datasets namely complete d1 and a segment of d2 such as d2(130:270,2). Is it possible to construct the complete curve of d2 from its segment d2(130:270,2)??
Please help.

답변 (3개)

John D'Errico
John D'Errico 2022년 12월 27일
편집: John D'Errico 2022년 12월 27일
load d1.mat
x = d1(:,1);
y = d1(:,2);
k = 130:270;
plot(x,y,'-b',x(k),y(k),'ro')
Seriouisly, you want to reconstruct the ENTIRE curve only by knowing the small piece in red?
Sorry, but completely impossible. Anything you would try to do to reconstruct the rest of the curve is a MASSIVE extrapolation. The predictions out there would be virtually random numbers. Extrapolation in general is difficult, and often impossible to do intelligenty. Extrapolate that far out from that little data is literally impossible to do well.

댓글 수: 6

Josh
Josh 2022년 12월 27일
Thanks for the kind response John. If you affirm that it's imposible, then what are the alternative possibilities or out-of-box solutions? Will extending the datapoints of the segment on both sides help? d2 is also a similar curve as d1. If we train a model with segment-d1 as input and entire-d1 as output, can we predict the entire-d2 curve from segment-d2 as input to the model. Please help.
@Josh yes it's impossible. You can extrapolate if you make some assumptions that you'd be happy with. Can you draw what you think you'd like the curve to look like outside of the known, red region?
Josh
Josh 2022년 12월 27일
편집: Josh 2022년 12월 27일
@Image Analyst The predicted entire curve need to be same as the original curve as the above-illustrated figure.
John D'Errico
John D'Errico 2022년 12월 27일
편집: John D'Errico 2022년 12월 27일
Solutions? You are still asking for the mathematically impossible. Wanting magic to happen is not sufficient.
IF you knew the mathematical form of thaat relation, then you MIGHT be able to do something. The point is, suppose you have some good mathematical reasoning to know what the form of that function is. So you absolutely know the shape of that curve. The more information you have about the shape of the curve, the better a chance you have of reconstructing a valid extrapolant.
However, you have shown no arguments for any model that describes this shape. ll you have said is that the curve should look like the big curve. But you have not told us what is the model.
Lacking that, asking to do what you want to do is just wanting magic to happen. Do you happen to have a magic wand? And since my mathematical magic wand broke just the other day, I could not really help you.
Sigh. Let me give you an example.
Suppose I show you just a short segment of a curve, and then you can decide which curve represents the extrapolant to complete the curve.
Clearly, that is a very simple set of points. But what would that curve look like when extrapolated? Is it the red or the blue curve?
The two are virtually identical on the interval [0,10], where the data lives. The data on the short interval looks fairly well behaved. But it is impossible to know which of those curves represents truth.
IF you KNEW something important about the true curve, that can help. For example, if you knew the asymptotic behavior of the curve as X goes to inf and as X goes to -inf, you might have some chance of guessing which of those curves is correct. In this case, I am giving you TWO choices, one of which happens to be correct. But even then, trying to extrapolate the exact curve shape from a limited set of points will be nearly impossible.
Sorry. You can't have what you want. If you don't believe me, then perhaps you can believe some guy named Mark (Twain).
"In the space of one hundred and seventy six years the Lower Mississippi has shortened itself two hundred and forty-two miles. That is an average of a trifle over a mile and a third per year. Therefore, any calm person, who is not blind or idiotic, can see that in the Old Oölitic Silurian Period, just a million years ago next November, the Lower Mississippi was upwards of one million three hundred thousand miles long, and stuck out over the Gulf of Mexico like a fishing-pole. And by the same token any person can see that seven hundred and forty-two years from now the Lower Mississippi will be only a mile and three-quarters long, and Cairo [Illinois] and New Orleans will have joined their streets together and be plodding comfortably along under a single mayor and a mutual board of aldermen. There is something fascinating about science. One gets such wholesale returns of conjecture out of such a trifling investment of fact."
The quote comes from Life on the Mississippi, 1884.
Josh
Josh 2022년 12월 28일
편집: Josh 2022년 12월 28일
@John D'Errico Thanks for the response.Your sense of humor is quite relieving in this difficult scenario. Appreciate for that. Also I see your point what you are trying to convey.I do not have any model or mathematical relation.Perhaps the magic wand is the mathematical relation or function that may represent this curve.If that function is found, then the problem is resolved.Can the Lorentzian or Gaussian or combination of both functions be used?
Another approach may be to develop an ML model with segment-d1,segment-d2, segment-d3 as input and entire-d1, entire-d2, entire-d3 as respective outputs. Thereafter predict entire-d4 from segment-d4. Is it feasible? Please help.
The magic wand would (at least partially) indeed be knowing the complete relationship. But guessing it MIGHT be gaussian or lorentizian is not knowing. Just as in my example, you cannot infer the shape of the entire curve from a small segment of that curve.
And even if you know the basic overall shape, you still cannot easily infer the extrapolated behavior, because all of your numbers are represented as double precision values. That means that tiny changes in the least significant bits of those numbers would be needed to infer the shape of that curve far out along the axis.
So I'm sorry, but no. As much as you want to do this, you cannot do so.
I'm not at all sure what you mean by some sort of piecewise representation. But again, you cannot infer from a small piece what the shape of the whole is.
Perhaps I could suggest the old story about the blind wise men and the elephant? One feels the tail, and decides the elephant is like rope. Another feels the leg, and thinks the elephant is like a tree. Another feels a tusk, or the trunk, or the ear, and each infers something completely different. You cannot infer the complete attributes of a large thing, merely by looking at a small part.
Finally, perhaps you are asking how to use something like a spline, without really understanding what is a spline. And, yes, a spline does allow you to approximate a complete curve using segments. But that does not mean one segment can in any way be extrapolated out to the whole, without using the entire curve to constrauct the spline.
load d1.mat
x = d1(:,1);
y = d1(:,2);
spl = spline(x,y);
fnplt(spl)
So spl is a cubic spline, composed of actually a huge number of tiny segments of cubic polynomials. Each was construtec from the curve I passed into spline. But they were not constructed separately. Only by having the ENTIRE curve to build that spline could the curve be reconstructed. Had I tried to use only the points from a small sub-domain, and then extrapolate it, I would get complete nonsense.

댓글을 달려면 로그인하십시오.

You can assume it's a polynomial, but that data does not fit a polynomial well.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
fileName = 'd1.mat';
s = load(fileName);
x = s.d1(:,1);
y = s.d1(:,2);
k = 130:270;
subplot(2, 1, 1);
plot(x,y,'-b', 'lineWidth', 2);
hold on;
plot(x(k),y(k),'r-', 'LineWidth', 5)
grid on;
title('Original Data', 'fontSize', fontSize)
legend('Full Curve', 'Training Data', 'Location', 'south')
% Assume we have a nth order polynomial.
xTrain = x(k);
yTrain = y(k);
polynomialOrder = 6; % Whatever you want.
coefficients = polyfit(xTrain, yTrain, polynomialOrder)
coefficients = 1×7
-1.67521364003749e-09 2.01447120219391e-07 -9.87020743066138e-06 0.000251820317381273 -0.00352965109727797 0.025856117987483 0.585520506591492
xFit = x;
yFit = polyval(coefficients, xFit);
subplot(2, 1, 2);
plot(xFit, yFit,'r-', 'LineWidth', 2);
grid on;
caption = sprintf('Data fitted to a polynomial of order %d', polynomialOrder);
title(caption, 'fontSize', fontSize)

댓글 수: 1

Josh
Josh 2022년 12월 27일
편집: Josh 2022년 12월 27일
@Image Analyst Appreciate your kind response, and the predicited curve does not signify the real nature of the original curve.May you try some alternative way or suggest who may help me.

댓글을 달려면 로그인하십시오.

Steven Lord
Steven Lord 2022년 12월 28일
이동: Image Analyst 2022년 12월 28일
Let's say I give you five points on a curve. Can you tell me what curve I sampled to get those points?
x = -2:2;
y = [0 0 0 0 0];
plot(x, y, 'o')
sampleX = linspace(-2, 2, 100);
Is this this curve? Note that it goes straight through the points represented by x and y.
figure
plot(x, y, 'o', sampleX, zeros(size(sampleX)), '+-')
title("y = 0")
How about this one? It too goes through those points.
figure
plot(x, y, 'o', sampleX, sinpi(sampleX), '+-')
title("y = sin(pi*x)")
Or this one?
figure
y2 = (x(1)-sampleX).*(x(2)-sampleX).*(x(3)-sampleX).*(x(4)-sampleX).*(x(5)-sampleX);
plot(x, y, 'o', sampleX, y2, '+-')
t = sprintf("(%d-x).*", x)
t = "(-2-x).*(-1-x).*(0-x).*(1-x).*(2-x).*"
title("y = " + extractBefore(t, strlength(t)-1))
Without additional information there is no absolutely way to tell which of those curves (or any of an infinite number of other possibilities) is the correct one I sampled to get those five points.
So what additional information do you have about your curve beyond the raw data points?

댓글 수: 2

Josh
Josh 2022년 12월 28일
이동: Image Analyst 2022년 12월 28일
@Steven Lord Thanks Steven for the kind response. Appreciate for letting me understand your point. As we have the original curve so we can check if we are predicting it correct or not.I do not have any model or mathematical relation.Perhaps the solution is the mathematical relation or function that may represent this curve. If that function is found, then the problem is resolved.Another approach may be to develop an ML model with segment-d1, segment-d2, segment-d3 as input and entire-d1, entire-d2, entire-d3 as respective outputs. Thereafter predict entire-d4 from segment-d4.Is that possible?
No, it is not possible to accurately guess what's outside the training range if you make no assumptions. Three of us have told you that now. It doesn't matter that you know what's there -- if that is not used in the training and prediction then it is of absolutely no help, except to let you know that whatever you came up with is wrong. I mean you could have hundreds of "true" plots outside of the training region, and if all you have is the training region, how could you possibly know which one was the "true" one? You can't. It's impossible.
But your signal looks like some kind of smooth function that follows some mathematical formula. If you knew that formula, even the form of it, not necessarily the coefficients of the parameters, then we could use something like fitnlm to find the coefficients and the best fitting formula.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2022년 12월 27일

편집:

2022년 12월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by