Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alta
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alta
alta
Commits
e6f2c0b7
Commit
e6f2c0b7
authored
Mar 20, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Iteration to optimize the solution in the DCA code
parent
2385eb6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
67 deletions
+30
-67
sources/plugins/rational_fitter_dca/rational_fitter.cpp
sources/plugins/rational_fitter_dca/rational_fitter.cpp
+30
-67
No files found.
sources/plugins/rational_fitter_dca/rational_fitter.cpp
View file @
e6f2c0b7
...
...
@@ -132,7 +132,7 @@ bool rational_fitter_dca::fit_data(const data* d, int np, int nq, rational_funct
// algorithm.
double
delta
=
0.0
;
bootstrap
(
d
,
np
,
nq
,
r
,
delta
);
#if
n
def DEBUG
#ifdef DEBUG
std
::
cout
<<
"<<DEBUG>> delta value after boostrap: "
<<
delta
<<
std
::
endl
;
std
::
cout
<<
"<<DEBUG>> r: "
<<
*
r
<<
std
::
endl
;
#endif
...
...
@@ -179,13 +179,15 @@ bool rational_fitter_dca::fit_data(const data* d, int np, int nq, rational_funct
engPutVariable
(
ep
,
"u"
,
u
);
engPutVariable
(
ep
,
"l"
,
l
);
double
delta_k
=
delta
;
double
delta_k
;
// Loop until you get a converge solution \delta > \delta_k
// \todo add the correct looping condition
while
(
true
)
do
{
// delta_{k+1} = delta_{k}
delta_k
=
delta
;
// The function to minimize is \delta which is the last element of
// the result vector
for
(
int
j
=
0
;
j
<
nY
*
(
N
-
1
);
++
j
)
...
...
@@ -283,85 +285,46 @@ bool rational_fitter_dca::fit_data(const data* d, int np, int nq, rational_funct
char
*
output
=
new
char
[
BUFFER_SIZE
+
1
];
output
[
BUFFER_SIZE
]
=
'\0'
;
engOutputBuffer
(
ep
,
output
,
BUFFER_SIZE
)
;
#ifndef DEBUG
engEvalString
(
ep
,
"display(f)"
);
std
::
cout
<<
output
<<
std
::
endl
;
engEvalString
(
ep
,
"display(A)"
);
std
::
cout
<<
output
<<
std
::
endl
;
engEvalString
(
ep
,
"display(b)"
);
std
::
cout
<<
output
<<
std
::
endl
;
engEvalString
(
ep
,
"display(u)"
);
std
::
cout
<<
output
<<
std
::
endl
;
engEvalString
(
ep
,
"display(l)"
);
std
::
cout
<<
output
<<
std
::
endl
;
#endif
engEvalString
(
ep
,
"[x, fval, flag] = linprog(f,A,b,[],[], l, u);"
);
#if
n
def DEBUG
#ifdef DEBUG
std
::
cout
<<
output
<<
std
::
endl
;
#endif
x
=
engGetVariable
(
ep
,
"x"
)
;
flag
=
engGetVariable
(
ep
,
"flag"
)
;
// \todo remove when correct looping condition ready
break
;
}
mxDestroyArray
(
f
);
mxDestroyArray
(
A
);
mxDestroyArray
(
b
);
if
(
x
!=
NULL
)
{
if
(
flag
!=
NULL
)
// Update the rational function
double
*
val
=
(
double
*
)
mxGetData
(
x
)
;
std
::
vector
<
double
>
a
,
b
;
for
(
int
i
=
0
;
i
<
(
np
+
nq
)
*
nY
;
++
i
)
{
if
(
mxGetScalar
(
flag
)
!=
1
)
if
(
i
<
np
*
nY
)
{
mxDestroyArray
(
x
);
mxDestroyArray
(
flag
);
#ifdef DEBUG
std
::
cerr
<<
"<<ERROR>> flag is not equal to 1"
<<
std
::
endl
;
#endif
return
false
;
a
.
push_back
(
val
[
i
])
;
}
double
total
=
0.0
;
double
*
val
=
(
double
*
)
mxGetData
(
x
)
;
std
::
vector
<
double
>
a
,
b
;
for
(
int
i
=
0
;
i
<
N
;
++
i
)
else
{
total
+=
val
[
i
]
*
val
[
i
]
;
if
(
i
<
np
)
{
a
.
push_back
(
val
[
i
])
;
}
else
{
b
.
push_back
(
val
[
i
])
;
}
b
.
push_back
(
val
[
i
])
;
}
r
->
update
(
a
,
b
)
;
mxDestroyArray
(
x
);
mxDestroyArray
(
flag
);
return
total
>
0.0
;
}
else
{
#ifdef DEBUG
std
::
cerr
<<
"<<ERROR>> unable to gather result flag"
<<
std
::
endl
;
#endif
return
false
;
}
}
else
{
r
->
update
(
a
,
b
)
;
#ifdef DEBUG
std
::
c
err
<<
"<<ERROR>> unable to gather result x"
<<
std
::
endl
;
std
::
c
out
<<
"<<DEBUG>> current rational function: "
<<
*
r
<<
std
::
endl
;
#endif
return
false
;
}
// Compute the new delta_k, the distance to the data points
delta
=
distance
(
r
,
d
);
}
while
(
delta
<=
delta_k
);
mxDestroyArray
(
f
);
mxDestroyArray
(
A
);
mxDestroyArray
(
b
);
mxDestroyArray
(
u
);
mxDestroyArray
(
l
);
return
true
;
}
Q_EXPORT_PLUGIN2
(
rational_fitter_dca
,
rational_fitter_dca
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment