Skip to content

vectorize the peak fitting #10

@rmflight

Description

@rmflight

I don't think we can vectorize getting coefficients of $intensity = a + m/z + m/z^2$, however, I think we could vectorize getting the center and intensity, because the number of coefficients is the same, and the only bit we need otherwise is the mean of the m/z's, I think

model_peak_center_intensity = function(x, coefficients){
  mn_x = mean(x)
  # this is all on the coefficients
  peak_center = ((-1 * coefficients[2]) / (2 * coefficients[3]))
  # this is just center from above, and then coefficients
  center_int = coefficients[1] + coefficients[2] * peak_center +
    (coefficients[3] * (peak_center ^ 2))
  c(ObservedMZ = peak_center + mn_x, Height = center_int)
}

So looking at this, if we passed in a vector of means, and a matrix of coefficients, we should be able to generate a whole lot of peak centers and heights all in one go. This would be good, because one of the big penalties we currently take is writing data-frame, and right now we do it row by row (using purrr mostly, so it's trying to do pre-allocation, but it's still not going to be as good as a whole lot at once I think).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions