Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Eisgenerator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klemm, Carl Philipp
Eisgenerator
Commits
e445b1dd
Commit
e445b1dd
authored
3 years ago
by
Carl Philipp Klemm
Browse files
Options
Downloads
Patches
Plain Diff
add the ability to add random noise to output spectra
parent
b6e7112b
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
basicmath.cpp
+16
-0
16 additions, 0 deletions
basicmath.cpp
eisgenerator/basicmath.h
+1
-0
1 addition, 0 deletions
eisgenerator/basicmath.h
main.cpp
+7
-2
7 additions, 2 deletions
main.cpp
options.h
+5
-0
5 additions, 0 deletions
options.h
with
29 additions
and
2 deletions
basicmath.cpp
+
16
−
0
View file @
e445b1dd
#include
"basicmath.h"
#include
<algorithm>
#include
<random>
#include
"eistype.h"
...
...
@@ -115,3 +116,18 @@ std::vector<eis::DataPoint> eis::rescale(const std::vector<eis::DataPoint>& data
}
return
output
;
}
void
eis
::
noise
(
std
::
vector
<
eis
::
DataPoint
>&
data
,
double
amplitude
,
bool
relative
)
{
std
::
random_device
rd
;
std
::
default_random_engine
rande
(
rd
());
for
(
eis
::
DataPoint
&
point
:
data
)
{
double
realNoise
=
(
static_cast
<
double
>
(
rande
()
>>
1
)
/
(
rande
.
max
()
>>
1
))
*
amplitude
;
point
.
im
.
real
(
relative
?
point
.
im
.
real
()
+
realNoise
/
point
.
im
.
real
()
:
point
.
im
.
real
()
+
realNoise
);
double
imgNoise
=
(
static_cast
<
double
>
(
rande
()
>>
1
)
/
(
rande
.
max
()
>>
1
))
*
amplitude
;
point
.
im
.
imag
(
relative
?
point
.
im
.
imag
()
+
imgNoise
/
point
.
im
.
imag
()
:
point
.
im
.
imag
()
+
imgNoise
);
}
}
This diff is collapsed.
Click to expand it.
eisgenerator/basicmath.h
+
1
−
0
View file @
e445b1dd
...
...
@@ -12,4 +12,5 @@ namespace eis
fvalue
median
(
std
::
vector
<
fvalue
>
data
);
std
::
complex
<
fvalue
>
median
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
);
std
::
vector
<
eis
::
DataPoint
>
rescale
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
size_t
outputSize
);
void
noise
(
std
::
vector
<
eis
::
DataPoint
>&
data
,
double
amplitude
,
bool
relative
);
}
This diff is collapsed.
Click to expand it.
main.cpp
+
7
−
2
View file @
e445b1dd
...
...
@@ -3,6 +3,7 @@
#include
<chrono>
#include
<cmath>
#include
"basicmath.h"
#include
"model.h"
#include
"log.h"
#include
"options.h"
...
...
@@ -36,7 +37,8 @@ static void paramSweepCb(std::vector<eis::DataPoint>& data, const std::vector<fv
std
::
cout
<<
'.'
<<
std
::
flush
;
}
static
void
runSweep
(
const
std
::
string
&
modelString
,
eis
::
Range
omega
,
bool
normalize
=
false
,
bool
reduce
=
false
,
bool
hertz
=
false
,
bool
invert
=
false
)
static
void
runSweep
(
const
std
::
string
&
modelString
,
eis
::
Range
omega
,
bool
normalize
=
false
,
bool
reduce
=
false
,
bool
hertz
=
false
,
bool
invert
=
false
,
double
noise
=
0
)
{
std
::
vector
<
eis
::
DataPoint
>
results
;
...
...
@@ -64,6 +66,9 @@ static void runSweep(const std::string& modelString, eis::Range omega, bool norm
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
"results:"
;
}
if
(
noise
>
0
)
eis
::
noise
(
results
,
noise
,
false
);
std
::
cout
<<
(
hertz
?
"freqency"
:
"omega"
)
<<
",real,im
\n
"
;
for
(
const
eis
::
DataPoint
&
res
:
results
)
...
...
@@ -107,7 +112,7 @@ int main(int argc, char** argv)
switch
(
config
.
mode
)
{
case
MODE_SWEEP
:
runSweep
(
config
.
modelStr
,
config
.
omegaRange
,
config
.
normalize
,
config
.
reduce
,
config
.
hertz
,
config
.
invert
);
runSweep
(
config
.
modelStr
,
config
.
omegaRange
,
config
.
normalize
,
config
.
reduce
,
config
.
hertz
,
config
.
invert
,
config
.
noise
);
break
;
case
MODE_PARAM_SWEEP
:
runParamSweep
();
...
...
This diff is collapsed.
Click to expand it.
options.h
+
5
−
0
View file @
e445b1dd
...
...
@@ -24,6 +24,7 @@ static struct argp_option options[] =
{
"reduce"
,
'r'
,
0
,
0
,
"reduce values to
\"
interesting
\"
range"
},
{
"hz"
,
'h'
,
0
,
0
,
"freqency values as temporal frequency instead of angular frequency"
},
{
"invert"
,
'i'
,
0
,
0
,
"inverts the imaginary axis"
},
{
"noise"
,
'x'
,
"[AMPLITUDE]"
,
0
,
"add noise to output"
},
{
0
}
};
...
...
@@ -42,6 +43,7 @@ struct Config
bool
reduce
=
false
;
bool
hertz
=
false
;
bool
invert
=
false
;
double
noise
=
0
;
Config
()
:
omegaRange
(
1
,
1001
,
1
,
true
)
{}
...
...
@@ -123,6 +125,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
}
break
;
}
case
'x'
:
config
->
noise
=
std
::
stod
(
std
::
string
(
arg
));
break
;
default
:
return
ARGP_ERR_UNKNOWN
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment