Construct the complete curve from one segment of it

1 回表示 (過去 30 日間)
Josh
Josh 2022 年 12 月 27 日
編集済み: John D'Errico 2022 年 12 月 28 日
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 月 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.
John D'Errico
John D'Errico 2022 年 12 月 28 日
編集済み: John D'Errico 2022 年 12 月 28 日
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.

サインインしてコメントする。


Image Analyst
Image Analyst 2022 年 12 月 27 日
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?
Image Analyst
Image Analyst 2022 年 12 月 28 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by