optimize

Function optimize 

Source
pub fn optimize<F: Float + FromPrimitive, U: PrimInt>(
    log_likelihood: &[Vec<F>],
    counts: &[U],
    prior: &[F],
    opts: Option<OptimizerOpts>,
) -> Result<(Vec<f32>, Vec<f32>), Box<dyn Error>>
Expand description

Run optimizer on 2D f32 log-likelihoods and integer weights.

Wrapper around optimize_flat that flattens the input and computes the log counts.

This function uses extra memory to handle generic floating point and integer types. optimize_flat or optimize_tensor(optimize_tensor<B: Backend>) should be preferred if memory usage is a concern.

§Inputs

  • log_likelihood: 2D vector with n_cols x n_rows log-likelihood matrix.
  • counts: n_rows vector of integer weights for log_likelihood rows.
  • prior: n_cols vector of prior counts for the Dirichlet model.
  • opts: OptimizerOpts.

§Outputs:

  • thetas: n_cols vector of inferred mixing proportions.
  • gamma_Z: flattened n_cols x n_rows column-major matrix containing inferred probabilities that the row i was generated from cluster j.

§Floating point width

Values will be converted to and returned as 32-bit floats regardless of input width.

Computation is performed in 32-bit space by default. If you want to perform computation in 64-bit space, specify a 64-bit device via opts.

If you want to supply log likelihoods using non-32-bit floating point numbers, call optimize_tensor(optimize_tensor<B: Backend>) with the appropriate tensor data.