Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
c2fec153
Commit
c2fec153
authored
Nov 27, 2015
by
Ultima
Browse files
Improved _cast_to_d2o when flatted d2o is inserted.
Made the steepest descent work.
parent
9aa680c4
Changes
4
Hide whitespace changes
Inline
Side-by-side
demos/demo_wf2.py
View file @
c2fec153
...
...
@@ -32,6 +32,23 @@
"""
from
__future__
import
division
#from pycallgraph import PyCallGraph
#from pycallgraph import Config
#from pycallgraph import GlobbingFilter
#from pycallgraph.output import GraphvizOutput
#
#config = Config()
#config.trace_filter = GlobbingFilter(exclude=[
# 'pycallgraph.*',
# #'*.secret_function',
#])
#
#graphviz = GraphvizOutput(output_file='steepest_profiling.png')
#
#
from
nifty
import
*
# version 0.8.0
...
...
@@ -43,10 +60,10 @@ k_space = x_space.get_codomain() # get conjugate
# some power spectrum
power
=
(
lambda
k
:
42
/
(
k
+
1
)
**
3
)
S
=
power_operator
(
k_space
,
spec
=
power
)
# define signal covariance
s
=
S
.
get_random_field
(
domain
=
x_space
)
# generate signal
S
=
power_operator
(
k_space
,
codomain
=
x_space
,
spec
=
power
)
# define signal covariance
s
=
S
.
get_random_field
(
domain
=
x_space
,
codomain
=
k_space
)
# generate signal
R
=
response_operator
(
x_space
,
sigma
=
0.0
,
mask
=
1.0
,
assign
=
None
)
# define response
R
=
response_operator
(
x_space
,
codomain
=
k_space
,
sigma
=
0.0
,
mask
=
1.0
,
assign
=
None
)
# define response
d_space
=
R
.
target
# get data space
# some noise variance; e.g., signal-to-noise ratio of 1
...
...
@@ -70,11 +87,13 @@ def eggs(x):
return
H
,
g
m
=
field
(
x_space
,
target
=
k_space
)
# reconstruct map
m
=
field
(
x_space
,
codomain
=
k_space
)
# reconstruct map
#with PyCallGraph(output=graphviz, config=config):
m
,
convergence
=
steepest_descent
(
eggs
=
eggs
,
note
=
True
)(
m
,
tol
=
1E-3
,
clevel
=
3
)
s
.
plot
(
title
=
"signal"
)
# plot signal
d_
=
field
(
x_space
,
val
=
d
.
val
,
target
=
k_space
)
d_
.
plot
(
title
=
"data"
,
vmin
=
s
.
min
(),
vmax
=
s
.
max
())
# plot data
m
.
plot
(
title
=
"reconstructed map"
,
vmin
=
s
.
min
(),
vmax
=
s
.
max
())
# plot map
#
s.plot(title="signal") # plot signal
#
d_ = field(x_space, val=d.val, target=k_space)
#
d_.plot(title="data", vmin=s.min(), vmax=s.max()) # plot data
#
m.plot(title="reconstructed map", vmin=s.min(), vmax=s.max()) # plot map
nifty_core.py
View file @
c2fec153
...
...
@@ -1167,13 +1167,17 @@ class point_space(space):
if
np
.
any
(
np
.
array
(
x
.
shape
)
!=
np
.
array
(
self
.
get_shape
())):
# Check if at least the number of degrees of freedom is equal
if
x
.
get_dim
()
==
self
.
get_dim
():
# If the number of dof is equal or 1, use np.reshape...
about
.
warnings
.
cflush
(
"WARNING: Trying to reshape the data. This "
+
"operation is expensive as it consolidates the "
+
"full data!
\n
"
)
temp
=
x
.
get_full_data
()
temp
=
np
.
reshape
(
temp
,
self
.
get_shape
())
try
:
temp
=
x
.
copy_empty
(
global_shape
=
self
.
get_shape
())
temp
.
set_local_data
(
x
.
get_local_data
(),
copy
=
False
)
except
:
# If the number of dof is equal or 1, use np.reshape...
about
.
warnings
.
cflush
(
"WARNING: Trying to reshape the data. This "
+
"operation is expensive as it consolidates the "
+
"full data!
\n
"
)
temp
=
x
.
get_full_data
()
temp
=
np
.
reshape
(
temp
,
self
.
get_shape
())
# ... and cast again
return
self
.
_cast_to_d2o
(
temp
,
dtype
=
dtype
,
...
...
nifty_mpi_data.py
View file @
c2fec153
...
...
@@ -773,7 +773,7 @@ class distributed_data_object(object):
"""
self
.
hermitian
=
hermitian
if
copy
is
True
:
self
.
data
[:]
=
data
self
.
data
[:]
=
data
.
reshape
(
self
.
local_shape
)
else
:
self
.
data
=
np
.
array
(
data
,
dtype
=
self
.
dtype
,
...
...
operators/nifty_minimization.py
View file @
c2fec153
...
...
@@ -581,7 +581,8 @@ class steepest_descent(object):
self
.
note
.
cprint
(
"
\n
iteration : %08u alpha < 1.0E-13
\n
... dead."
%
ii
)
break
else
:
delta
=
np
.
absolute
(
g
.
val
).
max
()
*
(
alpha
/
norm
)
delta
=
abs
(
g
).
max
()
*
(
alpha
/
norm
)
#delta = np.absolute(g.val).max()*(alpha/norm)
self
.
note
.
cflush
(
"
\n
iteration : %08u alpha = %3.1E delta = %3.1E"
%
(
ii
,
alpha
,
delta
))
## update
self
.
x
=
x_
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment