mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
*ScatterDraw: Some fixes and improvements
git-svn-id: svn://ultimatepp.org/upp/trunk@8138 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
df3d9191b7
commit
0028e635d0
9 changed files with 1397 additions and 1309 deletions
|
|
@ -29,6 +29,7 @@ void ExplicitEquation::SetNumCoeff(int num) {
|
|||
}
|
||||
|
||||
ExplicitEquation::FitError ExplicitEquation::Fit(DataSource &series, double &r2) {
|
||||
r2 = 0;
|
||||
if (series.IsExplicit() || series.IsParam())
|
||||
return InadequateDataSource;
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ ExplicitEquation::FitError ExplicitEquation::Fit(DataSource &series, double &r2)
|
|||
return ExplicitEquation::ImproperInputParameters;
|
||||
if (ret == LevenbergMarquardtSpace::TooManyFunctionEvaluation)
|
||||
return TooManyFunctionEvaluation;
|
||||
|
||||
|
||||
double mean = series.AvgY();
|
||||
double sse = 0, sst = 0;
|
||||
for (int64 i = 0; i < series.GetCount(); ++i) {
|
||||
|
|
@ -123,10 +124,14 @@ String FourierEquation::GetEquation(int numDigits) {
|
|||
|
||||
|
||||
EvalExpr::EvalExpr() {
|
||||
noCase = false;
|
||||
|
||||
constants.Add("PI", M_PI);
|
||||
constants.Add("M_PI", M_PI);
|
||||
constants.Add("e", exp(1.0));
|
||||
functions.Add("abs", fabs);
|
||||
functions.Add("ceil", ceil);
|
||||
functions.Add("floor", floor);
|
||||
functions.Add("sqrt", sqrt);
|
||||
functions.Add("sin", sin);
|
||||
functions.Add("cos", cos);
|
||||
|
|
@ -139,15 +144,6 @@ EvalExpr::EvalExpr() {
|
|||
functions.Add("tanh", tanh);
|
||||
}
|
||||
|
||||
/*
|
||||
void *EvalExpr::Functions_Get(CParser& p) {
|
||||
for (int i = 0; i < functions.GetCount(); ++i) {
|
||||
if (p.Id(functions.GetKey(i)))
|
||||
return (void *)functions[i];
|
||||
}
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
double EvalExpr::Term(CParser& p) {
|
||||
if(p.IsId()) {
|
||||
String strId = p.ReadId();
|
||||
|
|
@ -157,31 +153,32 @@ double EvalExpr::Term(CParser& p) {
|
|||
p.PassChar(')');
|
||||
return function(x);
|
||||
}
|
||||
if (noCase)
|
||||
strId = ToUpper(strId);
|
||||
double ret = constants.Get(strId, Null);
|
||||
if (IsNull(ret))
|
||||
ret = variables.GetAdd(strId, 0);
|
||||
return ret;
|
||||
}
|
||||
if(p.Char('(')) {
|
||||
} else if(p.Char('(')) {
|
||||
double x = Exp(p);
|
||||
p.PassChar(')');
|
||||
return x;
|
||||
}
|
||||
return p.ReadDouble();
|
||||
} else
|
||||
return p.ReadDouble();
|
||||
}
|
||||
|
||||
double EvalExpr::Mul(CParser& p) {
|
||||
double x = Term(p);
|
||||
for(;;)
|
||||
if(p.Char('*'))
|
||||
x = x * Term(p);
|
||||
x = x * Mul(p);
|
||||
else if(p.Char('/')) {
|
||||
double y = Term(p);
|
||||
double y = Mul(p);
|
||||
if(y == 0)
|
||||
p.ThrowError(t_("Divide by zero"));
|
||||
x = x / y;
|
||||
} else if(p.Char('^'))
|
||||
x = pow(x, Term(p));
|
||||
x = pow(x, Mul(p));
|
||||
else
|
||||
return x;
|
||||
}
|
||||
|
|
@ -220,7 +217,7 @@ double EvalExpr::Eval(String line) {
|
|||
return Exp(p);
|
||||
}
|
||||
catch(CParser::Error e) {
|
||||
DLOG(Format(t_("Error evaluating '%s': %s"), line, e));
|
||||
LOG(Format(t_("Error evaluating '%s': %s"), line, e));
|
||||
return Null;
|
||||
}
|
||||
}
|
||||
|
|
@ -234,6 +231,8 @@ String EvalExpr::TermStr(CParser& p, int numDigits) {
|
|||
p.PassChar(')');
|
||||
return strId + "(" + x + ")";
|
||||
}
|
||||
if (noCase)
|
||||
strId = ToUpper(strId);
|
||||
if (IsNull(numDigits)) {
|
||||
if (constants.Find(strId) < 0)
|
||||
variables.GetAdd(strId, 0);
|
||||
|
|
@ -259,11 +258,11 @@ String EvalExpr::MulStr(CParser& p, int numDigits) {
|
|||
String x = TermStr(p, numDigits);
|
||||
for(;;)
|
||||
if(p.Char('*'))
|
||||
x = x + "*" + TermStr(p, numDigits);
|
||||
x = x + "*" + MulStr(p, numDigits);
|
||||
else if(p.Char('/'))
|
||||
x = x + "/" + TermStr(p, numDigits);
|
||||
x = x + "/" + MulStr(p, numDigits);
|
||||
else if(p.Char('^'))
|
||||
x = x + "^" + TermStr(p, numDigits);
|
||||
x = x + "^" + MulStr(p, numDigits);
|
||||
else
|
||||
return x;
|
||||
}
|
||||
|
|
@ -304,9 +303,24 @@ String EvalExpr::EvalStr(String line, int numDigits) {
|
|||
return ExpStr(p, numDigits);
|
||||
}
|
||||
catch(CParser::Error e) {
|
||||
DLOG(Format(t_("Error evaluating '%s': %s"), line, e));
|
||||
LOG(Format(t_("Error evaluating '%s': %s"), line, e));
|
||||
return Null;
|
||||
}
|
||||
}
|
||||
|
||||
INITBLOCK {
|
||||
ExplicitEquation::Register<LinearEquation>("LinearEquation");
|
||||
ExplicitEquation::Register<PolynomialEquation2>("PolynomialEquation2");
|
||||
ExplicitEquation::Register<PolynomialEquation3>("PolynomialEquation3");
|
||||
ExplicitEquation::Register<PolynomialEquation4>("PolynomialEquation4");
|
||||
ExplicitEquation::Register<PolynomialEquation5>("PolynomialEquation5");
|
||||
ExplicitEquation::Register<SinEquation>("SinEquation");
|
||||
ExplicitEquation::Register<ExponentialEquation>("ExponentialEquation");
|
||||
ExplicitEquation::Register<Rational1Equation>("Rational1Equation");
|
||||
ExplicitEquation::Register<FourierEquation1>("FourierEquation1");
|
||||
ExplicitEquation::Register<FourierEquation2>("FourierEquation2");
|
||||
ExplicitEquation::Register<FourierEquation3>("FourierEquation3");
|
||||
ExplicitEquation::Register<FourierEquation4>("FourierEquation4");
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
@ -28,6 +28,7 @@ public:
|
|||
virtual String GetName() = 0;
|
||||
virtual String GetFullName() {return GetName();}
|
||||
virtual String GetEquation(int numDigits = 3) = 0;
|
||||
virtual inline int64 GetCount() {return Null;}
|
||||
|
||||
void SetNumDigits(int n) {numDigits = n;}
|
||||
int GetNumDigits() {return numDigits;}
|
||||
|
|
@ -37,6 +38,21 @@ public:
|
|||
friend struct Equation_functor;
|
||||
|
||||
const Array<double> &GetCoeff() {return coeff;}
|
||||
|
||||
template<class T>
|
||||
static void Register(const String& name) {
|
||||
classMap().FindAdd(name, __Create<T>);
|
||||
}
|
||||
static void Unregister(const String& name) {
|
||||
int i = NameIndex(name);
|
||||
ASSERT(i >= 0);
|
||||
classMap().Remove(i);
|
||||
}
|
||||
static int NameIndex(const String& name) {return classMap().Find(name);}
|
||||
static int GetEquationCount() {return classMap().GetCount();}
|
||||
static ExplicitEquation* Create(int i) {return classMap()[i]();}
|
||||
|
||||
int GetNumCoeff(int num) {return coeff.GetCount();}
|
||||
|
||||
protected:
|
||||
Array<double> coeff;
|
||||
|
|
@ -49,6 +65,11 @@ protected:
|
|||
void SetCoeff(double c0, double c1) {coeff.Clear(); coeff << c0 << c1;}
|
||||
void SetCoeff(double c0) {coeff.Clear(); coeff << c0;}
|
||||
void SetCoeffVal(int id, double c) {coeff[id] = c;}
|
||||
|
||||
typedef ExplicitEquation* (*CreateFunc)();
|
||||
template<class T>
|
||||
static ExplicitEquation* __Create() {return new T;}
|
||||
static VectorMap<String, CreateFunc>& classMap() {static VectorMap<String, CreateFunc> cMap; return cMap;}
|
||||
};
|
||||
|
||||
class LinearEquation : public ExplicitEquation {
|
||||
|
|
@ -63,7 +84,7 @@ public:
|
|||
return ret;
|
||||
}
|
||||
void SetDegree(int num) {NEVER();}
|
||||
virtual void GuessCoeff(DataSource &series) {coeff[0] = AvgY();}
|
||||
virtual void GuessCoeff(DataSource &series) {coeff[0] = series.AvgY();}
|
||||
};
|
||||
|
||||
class PolynomialEquation : public ExplicitEquation {
|
||||
|
|
@ -74,10 +95,30 @@ public:
|
|||
virtual String GetName() {return t_("Polynomial");}
|
||||
virtual String GetFullName() {return t_("Polynomial") + String(" n = ") + FormatInt(degree);}
|
||||
virtual String GetEquation(int numDigits = 3);
|
||||
virtual void GuessCoeff(DataSource &series) {}
|
||||
virtual void GuessCoeff(DataSource &series) {coeff[0] = series.AvgY();}
|
||||
void SetDegree(int num) {degree = num; SetNumCoeff(num + 1);}
|
||||
};
|
||||
|
||||
class PolynomialEquation2 : public PolynomialEquation {
|
||||
public:
|
||||
PolynomialEquation2() {SetDegree(2);}
|
||||
};
|
||||
|
||||
class PolynomialEquation3 : public PolynomialEquation {
|
||||
public:
|
||||
PolynomialEquation3() {SetDegree(3);}
|
||||
};
|
||||
|
||||
class PolynomialEquation4 : public PolynomialEquation {
|
||||
public:
|
||||
PolynomialEquation4() {SetDegree(4);}
|
||||
};
|
||||
|
||||
class PolynomialEquation5 : public PolynomialEquation {
|
||||
public:
|
||||
PolynomialEquation5() {SetDegree(5);}
|
||||
};
|
||||
|
||||
class SinEquation : public ExplicitEquation {
|
||||
public:
|
||||
SinEquation() {coeff.Clear(); coeff << 0. << 0.1 << 0.1 << 0.1;}
|
||||
|
|
@ -94,8 +135,7 @@ public:
|
|||
void SetDegree(int num) {NEVER();}
|
||||
virtual void GuessCoeff(DataSource &series) {
|
||||
coeff[0] = series.AvgY();
|
||||
double A;
|
||||
coeff[1] = A = series.SinEstim_Amplitude(coeff[0]);
|
||||
coeff[1] = series.SinEstim_Amplitude(coeff[0]);
|
||||
double frequency, phase;
|
||||
if (series.SinEstim_FreqPhase(frequency, phase, coeff[0])) {
|
||||
coeff[2] = frequency;
|
||||
|
|
@ -112,10 +152,30 @@ public:
|
|||
virtual String GetName() {return t_("Fourier");}
|
||||
virtual String GetFullName() {return t_("Fourier") + String(" n = ") + FormatInt(degree);}
|
||||
virtual String GetEquation(int numDigits = 3);
|
||||
virtual void GuessCoeff(DataSource &series) {}
|
||||
virtual void GuessCoeff(DataSource &series) {coeff[0] = series.AvgY();}
|
||||
void SetDegree(int num) {degree = num; SetNumCoeff(2*num + 2);}
|
||||
};
|
||||
|
||||
class FourierEquation1 : public FourierEquation {
|
||||
public:
|
||||
FourierEquation1() {SetDegree(1);}
|
||||
};
|
||||
|
||||
class FourierEquation2 : public FourierEquation {
|
||||
public:
|
||||
FourierEquation2() {SetDegree(2);}
|
||||
};
|
||||
|
||||
class FourierEquation3 : public FourierEquation {
|
||||
public:
|
||||
FourierEquation3() {SetDegree(3);}
|
||||
};
|
||||
|
||||
class FourierEquation4 : public FourierEquation {
|
||||
public:
|
||||
FourierEquation4() {SetDegree(4);}
|
||||
};
|
||||
|
||||
class ExponentialEquation : public ExplicitEquation {
|
||||
public:
|
||||
ExponentialEquation() {SetCoeff(1, 0);}
|
||||
|
|
@ -152,6 +212,7 @@ public:
|
|||
EvalExpr();
|
||||
double Eval(String line);
|
||||
String EvalStr(String line, int numDigits = 3);
|
||||
void SetCaseSensitivity(bool val = true) {noCase = !val;}
|
||||
|
||||
VectorMap<String, double> constants;
|
||||
VectorMap<String, double> variables;
|
||||
|
|
@ -164,6 +225,7 @@ private:
|
|||
String TermStr(CParser& p, int numDigits);
|
||||
String MulStr(CParser& p, int numDigits);
|
||||
String ExpStr(CParser& p, int numDigits);
|
||||
bool noCase;
|
||||
|
||||
VectorMap<String, double (*)(double)> functions;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public:
|
|||
typeMap().Remove(i);
|
||||
}
|
||||
static String TypeName(int i) {return typeMap()[i];}
|
||||
static int TypeIndex(const String& name) {return classMap().Find(name);}
|
||||
static int TypeIndex(const String& name) {return typeMap().Find(name);}
|
||||
static int GetCount() {return classMap().GetCount();}
|
||||
static MarkPlot* Create(int i) {return classMap()[i]();}
|
||||
static Vector<String> GetTypes() {return clone(typeMap()).PickValues();}
|
||||
|
|
|
|||
|
|
@ -633,11 +633,10 @@ ScatterDraw &ScatterDraw::_InsertSeries(int index, DataSource *data) {
|
|||
|
||||
int64 ScatterDraw::GetCount(int index) {
|
||||
ASSERT(IsValid(index));
|
||||
if (series[index].PointsData()->IsParam())
|
||||
if (series[index].PointsData()->IsParam() || series[index].PointsData()->IsExplicit())
|
||||
return Null;
|
||||
else if (IsNull(series[index].PointsData()->GetCount()))
|
||||
return Null;
|
||||
return series[index].PointsData()->GetCount();
|
||||
else
|
||||
return series[index].PointsData()->GetCount();
|
||||
}
|
||||
|
||||
void ScatterDraw::GetValues(int index, int64 idata, double &x, double &y) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public:
|
|||
typeMap().Remove(i);
|
||||
}
|
||||
static String TypeName(int i) {return typeMap()[i];}
|
||||
static int TypeIndex(const String& name) {return classMap().Find(name);}
|
||||
static int TypeIndex(const String& name) {return typeMap().Find(name);}
|
||||
static int GetCount() {return classMap().GetCount();}
|
||||
static SeriesPlot* Create(int i) {return classMap()[i]();}
|
||||
static Vector<String> GetTypes() {return clone(typeMap()).PickValues();}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
|
|
@ -22,4 +22,4 @@ topic "2.2 VectorY";
|
|||
values beginning from [%-*@3 x0] and with [%-*@3 deltaX] between
|
||||
X axis values.&]
|
||||
[s3;%% &]
|
||||
[s0;%% ]]
|
||||
[s3;%% ]]
|
||||
|
|
@ -2,5 +2,5 @@ TITLE("2.2 VectorY")
|
|||
COMPRESSED
|
||||
120,156,133,82,109,107,219,48,16,254,43,7,107,66,50,218,68,58,73,177,99,151,146,209,176,13,246,97,31,10,163,65,40,182,106,43,157,153,107,23,91,105,59,74,255,251,228,151,188,141,177,250,131,124,156,238,121,238,158,71,39,225,236,140,156,147,15,228,157,47,88,154,141,222,230,86,201,140,115,63,212,40,194,95,223,190,207,67,7,167,14,206,60,202,124,193,40,199,153,59,40,163,40,144,113,234,227,156,251,140,249,36,168,109,181,77,108,102,205,131,146,57,250,126,136,14,137,14,137,158,64,234,113,159,251,148,121,62,58,2,36,4,137,135,130,114,230,163,8,82,83,39,74,18,87,206,92,249,124,198,230,132,18,226,81,74,24,122,132,9,78,41,67,71,129,30,82,34,2,83,164,74,126,157,133,13,128,55,194,196,204,141,63,115,108,156,19,199,222,192,56,163,140,32,19,116,46,102,193,157,185,207,138,191,101,53,211,137,119,117,121,36,72,202,212,116,170,94,163,55,144,240,250,74,27,187,22,12,100,77,194,193,0,228,199,197,8,113,62,230,240,195,36,182,172,86,
|
||||
74,189,189,13,149,172,105,184,24,145,9,153,160,16,99,2,93,38,40,202,202,108,2,144,135,43,112,228,143,185,182,70,69,151,199,233,36,215,117,173,34,71,207,97,165,174,122,124,223,35,14,226,160,45,56,165,218,99,246,179,68,65,116,92,240,184,189,203,179,164,101,101,176,212,86,223,148,219,42,49,170,97,199,70,77,19,116,178,16,62,129,146,107,91,62,102,137,107,55,141,167,55,137,182,214,84,203,74,63,199,211,186,74,226,233,129,33,62,51,69,124,177,173,215,120,68,235,240,216,205,4,119,186,54,41,148,5,232,126,52,40,55,240,164,243,173,169,39,109,119,22,54,189,119,246,126,30,81,244,199,95,218,115,65,15,86,195,117,89,116,155,230,24,150,198,234,44,223,217,205,91,130,90,156,120,180,11,71,93,16,95,174,226,171,120,24,159,167,165,51,194,236,255,227,0,142,60,27,201,104,221,197,235,62,167,46,119,207,16,197,195,214,187,223,141,74,117,126,226,126,71,214,155,251,66,254,119,155,154,220,234,91,53,222,251,126,93,25,183,2,245,222,158,213,63,28,
|
||||
147,131,139,67,107,120,206,236,79,184,5,253,146,213,189,145,208,110,122,145,21,247,176,169,202,135,93,189,155,4,116,145,118,128,62,215,247,119,8,251,108,76,113,202,51,233,222,227,120,27,148,250,3,203,0,57,164,
|
||||
147,131,139,67,107,120,206,236,79,184,5,253,146,213,189,145,208,110,122,145,21,247,176,169,202,135,93,189,155,4,116,145,118,128,62,215,247,119,8,251,108,76,113,202,51,233,222,163,223,134,54,80,234,15,203,21,57,167,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue