Commit c2fec153 authored by Ultima's avatar Ultima
Browse files

Improved _cast_to_d2o when flatted d2o is inserted.

Made the steepest descent work.
parent 9aa680c4
......@@ -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
......@@ -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,
......
......@@ -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,
......
......@@ -581,7 +581,8 @@ class steepest_descent(object):
self.note.cprint("\niteration : %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("\niteration : %08u alpha = %3.1E delta = %3.1E"%(ii,alpha,delta))
## update
self.x = x_
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment