Class: Gsplat::Strategy::MCMC

Inherits:
Base
  • Object
show all
Defined in:
lib/gsplat/strategy/mcmc.rb

Overview

3D Gaussian Splatting as Markov Chain Monte Carlo strategy.

Constant Summary collapse

DEFAULTS =

Upstream-compatible relocation and noise defaults.

{
  cap_max: 1_000_000,
  noise_lr: 5e5,
  refine_start_iter: 500,
  refine_stop_iter: 25_000,
  refine_every: 100,
  min_opacity: 0.005,
  verbose: false
}.freeze

Constants inherited from Base

Base::REQUIRED_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#check_sanity, #step_pre_backward

Constructor Details

#initialize(**options) ⇒ MCMC

Returns a new instance of MCMC.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
# File 'lib/gsplat/strategy/mcmc.rb', line 21

def initialize(**options)
  super()
  unknown = options.keys - DEFAULTS.keys
  raise ArgumentError, "unknown options: #{unknown.join(', ')}" unless unknown.empty?

  DEFAULTS.merge(options).each { |name, value| instance_variable_set(:"@#{name}", value) }
  validate_options!
end

Instance Attribute Details

#cap_maxObject (readonly)

Returns the value of attribute cap_max.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def cap_max
  @cap_max
end

#min_opacityObject (readonly)

Returns the value of attribute min_opacity.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def min_opacity
  @min_opacity
end

#noise_lrObject (readonly)

Returns the value of attribute noise_lr.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def noise_lr
  @noise_lr
end

#refine_everyObject (readonly)

Returns the value of attribute refine_every.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def refine_every
  @refine_every
end

#refine_start_iterObject (readonly)

Returns the value of attribute refine_start_iter.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def refine_start_iter
  @refine_start_iter
end

#refine_stop_iterObject (readonly)

Returns the value of attribute refine_stop_iter.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def refine_stop_iter
  @refine_stop_iter
end

#verboseObject (readonly)

Returns the value of attribute verbose.



18
19
20
# File 'lib/gsplat/strategy/mcmc.rb', line 18

def verbose
  @verbose
end

Instance Method Details

#initialize_state(scene_scale: 1.0) ⇒ Hash

Creates strategy state including the relocation binomial table.

Parameters:

  • scene_scale (Numeric) (defaults to: 1.0)

Returns:

  • (Hash)


34
35
36
# File 'lib/gsplat/strategy/mcmc.rb', line 34

def initialize_state(scene_scale: 1.0)
  super.merge(binoms: Gsplat::Ops::Relocation.binomial_table(n_max: 51))
end

#step_post_backward(params:, optimizers:, state:, step:, info:, **options) ⇒ Object

rubocop:disable Metrics/ParameterLists

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gsplat/strategy/mcmc.rb', line 39

def step_post_backward(params:, optimizers:, state:, step:, info:, **options)
  raise ArgumentError, "info must be a Hash" unless info.is_a?(Hash)

  learning_rate = options.fetch(:lr)
  check_sanity(params, optimizers)
  if should_refine?(step)
    relocated = relocate_dead!(params, optimizers, state)
    added = add_new!(params, optimizers, state)
    log_step(step, relocated, added) if verbose
  end
  Ops.inject_position_noise!(params, scaler: learning_rate * noise_lr)
  state
end