Commit aefdad7f authored by Alexandre Bône's avatar Alexandre Bône

Random initialization of the momenta for the longitudinal atlas.

parent bdec4e23
Pipeline #56354468 passed with stages
in 5 minutes and 12 seconds
......@@ -304,7 +304,8 @@ class LongitudinalAtlas(AbstractStatisticalModel):
self.__initialize_control_points_prior()
# Momenta.
self.set_momenta(initialize_momenta(initial_momenta, self.number_of_control_points, self.dimension))
self.set_momenta(
initialize_momenta(initial_momenta, self.number_of_control_points, self.dimension, random=True))
self.__initialize_momenta_prior()
# Modulation matrix.
......
......@@ -31,15 +31,19 @@ def initialize_control_points(initial_control_points, template, spacing, deforma
return control_points
def initialize_momenta(initial_momenta, number_of_control_points, dimension, number_of_subjects=0):
def initialize_momenta(initial_momenta, number_of_control_points, dimension, number_of_subjects=0, random=False):
if initial_momenta is not None:
momenta = read_3D_array(initial_momenta)
logger.info('>> Reading initial momenta from file: %s.' % initial_momenta)
else:
if number_of_subjects == 0:
momenta = np.zeros((number_of_control_points, dimension))
logger.info('>> Momenta initialized to zero.')
if random:
momenta = np.random.randn(number_of_control_points, dimension) / math.sqrt(number_of_control_points * dimension)
logger.info('>> Momenta randomly initialized.')
else:
momenta = np.zeros((number_of_control_points, dimension))
logger.info('>> Momenta initialized to zero.')
else:
momenta = np.zeros((number_of_subjects, number_of_control_points, dimension))
logger.info('>> Momenta initialized to zero, for %d subjects.' % number_of_subjects)
......
......@@ -335,8 +335,9 @@ class API(unittest.TestCase):
model_options={
'deformation_kernel_type': 'torch',
'deformation_kernel_width': 1.0,
'number_of_processes': 2,
'number_of_processes': 1,
'dtype': self.dtype
# 'initial_modulation_matrix':
})
logger.info('>>>>> estimate_longitudinal_atlas took : ' + str(time.perf_counter() - start) + ' seconds')
......
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