package gdsc.smlm.function.gaussian;
/*-----------------------------------------------------------------------------
* GDSC SMLM Software
*
* Copyright (C) 2013 Alex Herbert
* Genome Damage and Stability Centre
* University of Sussex, UK
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*---------------------------------------------------------------------------*/
/**
* Evaluates an 2-dimensional Gaussian function for a configured number of peaks.
* <p>
* The single parameter x in the {@link #eval(int, double[])} function is assumed to be a linear index into
* 2-dimensional
* data. The dimensions of the data must be specified to allow unpacking to coordinates.
* <p>
* Data should be packed in descending dimension order, e.g. Y,X : Index for [x,y] = MaxX*y + x.
*/
public class NBFreeCircularGaussian2DFunction extends FreeCircularGaussian2DFunction
{
/**
* Constructor
*
* @param npeaks
* The number of peaks
* @param maxx
* The maximum x value of the 2-dimensional data (used to unpack a linear index into coordinates)
* @param maxy
* The maximum y value of the 2-dimensional data (used to unpack a linear index into coordinates)
*/
public NBFreeCircularGaussian2DFunction(int npeaks, int maxx, int maxy)
{
super(npeaks, maxx, maxy);
}
/*
* (non-Javadoc)
*
* @see gdsc.smlm.function.gaussian.Gaussian2DFunction#copy()
*/
@Override
public Gaussian2DFunction copy()
{
return new NBFreeCircularGaussian2DFunction(npeaks, maxx, maxy);
}
/*
* (non-Javadoc)
*
* @see gdsc.smlm.fitting.function.gaussian.FreeCircularGaussian2DFunction#eval(int, double[])
*/
public double eval(final int x, final double[] dyda)
{
// Track the position of the parameters
int apos = 0;
int dydapos = 0;
// First parameter is the background level
double y_fit = a[BACKGROUND];
// Unpack the predictor into the dimensions
final int x1 = x / maxx;
final int x0 = x % maxx;
for (int j = 0; j < npeaks; j++)
{
y_fit += gaussian(x0, x1, dyda, apos, dydapos, peakFactors[j]);
apos += 6;
dydapos += PARAMETERS_PER_PEAK;
}
return y_fit;
}
@Override
public boolean evaluatesBackground()
{
return false;
}
}